PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/antlr-3.4/runtime/Ruby/test/unit/test-dfa.rb

https://bitbucket.org/cyanogenmod/android_external_antlr
Ruby | 52 lines | 44 code | 6 blank | 2 comment | 8 complexity | b9783ccce295e9fb30c12d5927924d67 MD5 | raw file
  1. #!/usr/bin/ruby
  2. # encoding: utf-8
  3. require 'antlr3'
  4. require 'test/unit'
  5. require 'spec'
  6. class DFASubclass < ANTLR3::DFA
  7. EOT = [1, 2].freeze
  8. EOF = [3, 4].freeze
  9. MAX = [5, 6].freeze
  10. MIN = [7, 8].freeze
  11. ACCEPT = [9, 10, 11].freeze
  12. SPECIAL = [12].freeze
  13. TRANSITION = [
  14. [13, 14, 15, 16].freeze,
  15. [].freeze
  16. ].freeze
  17. end
  18. class TestDFA < Test::Unit::TestCase
  19. def test_init
  20. dfa = DFASubclass.new(nil, 1)
  21. dfa.eot.should == DFASubclass::EOT
  22. dfa.eof.should == DFASubclass::EOF
  23. dfa.max.should == DFASubclass::MAX
  24. dfa.min.should == DFASubclass::MIN
  25. dfa.accept.should == DFASubclass::ACCEPT
  26. dfa.special.should == DFASubclass::SPECIAL
  27. dfa.transition.should == DFASubclass::TRANSITION
  28. end
  29. def test_unpack
  30. packed = [
  31. 1, 3, 1, 4, 2, -1, 1, 5, 18, -1, 1, 2,
  32. 25, -1, 1, 6, 6, -1, 26, 6, 4, -1, 1, 6,
  33. 1, -1, 26, 6
  34. ]
  35. unpacked = [
  36. 3, 4, -1, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  37. -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  38. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  39. 6, -1, -1, -1, -1, -1, -1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  40. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -1, -1, -1, -1, 6, -1,
  41. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  42. 6, 6, 6, 6, 6
  43. ]
  44. ANTLR3::DFA.unpack(*packed).should == unpacked
  45. end
  46. end