Sha256: dcbea3c2a400eda9ece56f764c99ccd2dc613abb276db22e7d97cc67d0afb565

Contents?: true

Size: 1.93 KB

Versions: 23

Compression:

Stored size: 1.93 KB

Contents

require File.expand_path(File.dirname(__FILE__)) + '/../helper'

class ShakeCatcherTest < Test::Unit::TestCase
  C = Tracksperanto::ShakeGrammar::Catcher
  
  def at(at, v)
    C::At.new(at, v)
  end
  
  def test_hould_catch_simple_funcall
    k = Class.new(C) do
      def foofunc(a, b, c)
        "#{a.inspect} #{b.inspect} #{c.inspect}"
      end
    end
    tree = parse("FooFunc(1, 2, 3)", k)
    assert_equal [[:retval, "1 2 3"]], tree
  end
  
  def test_uknown_funcalls
    k = Class.new(C)
    tree = parse("OuterFunc(InnerFunc(15)", k)
    assert_equal [[:unknown_func]], tree
    
    tree = parse("OuterFunc(15);", k)
    assert_equal [[:unknown_func]], tree
  end
  
  def test_nested_funcalls
    k = Class.new(C) do
      def outerfunc(a)
        a * 2
      end
      
      def innerfunc(b)
        b * 10
      end
    end
    
    tree = parse("OuterFunc(InnerFunc(15)", k)
    assert_equal [[:retval, 300]], tree
  end
  
  def test_hermite_funcall_with_array_ats
    k = Class.new(C) do
      def hermite(first_arg, *keyframes)
        keyframes
      end
    end
    
    tree = parse('Hermite(0,[1379.04,-0.02,-0.02]@1,[1379.04,-0.03,-0.03]@2)', k)
    assert_equal [[:retval, [at(1, [1379.04, -0.02, -0.02]), at(2, [1379.04, -0.03, -0.03])]]],  tree
  end
  
  def test_linear_funcall
    k = Class.new(C) do
      def linear(first_arg, *keyframes)
        123
      end
    end
    
    tree = parse('Linear(0,591.702@1,591.452@2,591.202@3,590.733@4,590.202@5,589.421@6,589.249@7)', k)
    assert_equal [[:retval, 123]],  tree
  end
  
  def test_nested_funcalls_with_array_return
    k = Class.new(C) do
      def outerfunc(a)
        a * 2
      end
      
      def innerfunc(b)
        [b, b* 2, b* 3]
      end
    end
    
    tree = parse("OuterFunc(InnerFunc(15)", k)
    assert_equal [[:retval, [15, 30, 45, 15, 30, 45]]], tree
  end
  
  def parse(s, klass)
    s = StringIO.new(s) unless s.respond_to?(:read)
    klass.new(s).stack
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
tracksperanto-2.8.6 test/import/test_shake_catcher.rb
tracksperanto-2.8.5 test/import/test_shake_catcher.rb
tracksperanto-2.8.4 test/import/test_shake_catcher.rb
tracksperanto-2.8.2 test/import/test_shake_catcher.rb
tracksperanto-2.8.1 test/import/test_shake_catcher.rb
tracksperanto-2.8.0 test/import/test_shake_catcher.rb
tracksperanto-2.7.0 test/import/test_shake_catcher.rb
tracksperanto-2.6.3 test/import/test_shake_catcher.rb
tracksperanto-2.6.2 test/import/test_shake_catcher.rb
tracksperanto-2.6.1 test/import/test_shake_catcher.rb
tracksperanto-2.6.0 test/import/test_shake_catcher.rb
tracksperanto-2.5.0 test/import/test_shake_catcher.rb
tracksperanto-2.4.1 test/import/test_shake_catcher.rb
tracksperanto-2.3.3 test/import/test_shake_catcher.rb
tracksperanto-2.3.2 test/import/test_shake_catcher.rb
tracksperanto-2.3.1 test/import/test_shake_catcher.rb
tracksperanto-2.3.0 test/import/test_shake_catcher.rb
tracksperanto-2.2.4 test/import/test_shake_catcher.rb
tracksperanto-2.2.2 test/import/test_shake_catcher.rb
tracksperanto-2.2.0 test/import/test_shake_catcher.rb