Home | History | Annotate | Download | only in unit
      1 #!/usr/bin/ruby
      2 # encoding: utf-8
      3 
      4 require 'antlr3'
      5 require 'test/unit'
      6 require 'spec'
      7 
      8 include ANTLR3
      9 
     10 class TestTokenSource < Test::Unit::TestCase
     11   TrivialToken = Struct.new(:type) do
     12     include Token
     13   end
     14   class TestSource
     15     include TokenSource
     16     def initialize
     17       @tokens = (1..4).map { |i| TrivialToken[i] }
     18       @tokens << TrivialToken[EOF]
     19     end
     20     
     21     def next_token
     22       @tokens.shift
     23     end
     24   end
     25   
     26   def test_iterator_interface
     27     src = TestSource.new
     28     tokens = []
     29     src.each do |token|
     30       tokens << token.type
     31     end
     32     tokens.should == [1,2,3,4]
     33   end
     34   
     35 end
     36 
     37 class TestLexer < Test::Unit::TestCase
     38   class TLexer < Lexer
     39     @antlr_version = ANTLR3::ANTLR_VERSION.dup
     40   end
     41   def test_init
     42     stream = StringStream.new('foo')
     43     TLexer.new(stream)
     44   end
     45 end
     46 
     47 __END__
     48 testrecognizers.py                           | LN | STATUS
     49 ---------------------------------------------+----+--------------
     50 class TestBaseRecognizer(unittest.TestCase)  | 07 | [x]
     51     def testGetRuleInvocationStack(self)     | 10 | [x]
     52 class TestTokenSource(unittest.TestCase)     | 20 | [x]
     53     def testIteratorInterface(self)          | 24 | [x]
     54 class TestLexer(unittest.TestCase)           | 54 | [x]
     55     def testInit(self)                       | 56 | [x]