• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/ruby
2# encoding: utf-8
3
4require 'antlr3'
5require 'test/unit'
6require 'spec'
7
8include ANTLR3
9
10class 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
35end
36
37class 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
45end
46
47__END__
48testrecognizers.py                           | LN | STATUS
49---------------------------------------------+----+--------------
50class TestBaseRecognizer(unittest.TestCase)  | 07 | [x]
51    def testGetRuleInvocationStack(self)     | 10 | [x]
52class TestTokenSource(unittest.TestCase)     | 20 | [x]
53    def testIteratorInterface(self)          | 24 | [x]
54class TestLexer(unittest.TestCase)           | 54 | [x]
55    def testInit(self)                       | 56 | [x]