PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/Ruby/test/unit/test-scope.rb

https://bitbucket.org/jwalton/antlr3
Ruby | 45 lines | 35 code | 8 blank | 2 comment | 12 complexity | c012c643e60d0592112cd4edc1c227c6 MD5 | raw file
  1. #!/usr/bin/ruby
  2. # encoding: utf-8
  3. require 'antlr3'
  4. require 'test/unit'
  5. require 'spec'
  6. class TestDFA < Test::Unit::TestCase
  7. def setup
  8. @A = ANTLR3::Scope.new( :a, :b )
  9. @B = ANTLR3::Scope.new( 'count = 3' )
  10. @C = ANTLR3::Scope.new( 'a', 'b = 0', 'c = {}' )
  11. end
  12. def test_members
  13. @A.members.map( &:to_s ).should == %w( a b )
  14. @B.members.map( &:to_s ).should == %w( count )
  15. @C.members.map( &:to_s ).should == %w( a b c )
  16. end
  17. def test_defaults_without_arguments
  18. @A.new.to_a.should == [ nil, nil ]
  19. @B.new.to_a.should == [ 3 ]
  20. @C.new.to_a.should == [ nil, 0, {} ]
  21. end
  22. def test_C_defaults_with_arguments
  23. c = @C.new( Object )
  24. c.a.should == Object
  25. c.b.should == 0
  26. c.c.should == {}
  27. end
  28. def test_B_defaults_with_arguments
  29. b = @B.new( 7000 )
  30. b.count.should == 7000
  31. end
  32. def test_A_defaults_with_arguments
  33. a = @A.new( "apple", :orange )
  34. a.a.should == 'apple'
  35. a.b.should == :orange
  36. end
  37. end