• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/ruby
2# encoding: utf-8
3require 'antlr3'
4require 'test/unit'
5require 'spec'
6
7include ANTLR3
8
9describe TokenScheme do
10  before do
11    @ts = TokenScheme.new do
12      define_tokens(:A => 4, :B => 5, :T__6 => 6)
13      register_names('A', 'B', "'+'")
14    end
15    @a_class = Class.new do
16      class << self
17        attr_accessor :token_scheme
18      end
19    end
20    @a_class.send(:include, @ts)
21
22    @an_instance = @a_class.new
23  end
24
25  example "token schemes define tokens as constants" do
26    @ts::A.should == 4
27    @ts::B.should == 5
28    @ts::T__6.should == 6
29    @ts::EOF.should == -1
30  end
31
32  example "token schemes track human-friendly token names" do
33    @ts::TOKEN_NAMES.should == {
34      0 => "<invalid>", -1 => "<EOF>", 1 => "<EOR>",
35      2 => "<DOWN>", 3 => "<UP>", 4 => "A",
36      5 => "B", 6 => "'+'"
37    }
38    @ts.token_name(5).should == 'B'
39    @ts.token_name(6).should == "'+'"
40    @ts.token_name(-1).should == '<EOF>'
41    @ts.token_name(7).should == '<UNKNOWN: 7>'
42  end
43
44
45  example 'class-level results of including a token scheme' do
46    #@a_class.token_scheme.should == @ts
47
48    @a_class::A.should == 4
49    @a_class::B.should == 5
50    @a_class::T__6.should == 6
51    @a_class::EOF.should == -1
52
53    @a_class.send(:token_names).should == {
54      0 => "<invalid>", -1 => "<EOF>", 1 => "<EOR>",
55      2 => "<DOWN>", 3 => "<UP>", 4 => "A",
56      5 => "B", 6 => "'+'"
57    }
58  end
59
60  example 'instance-level results of including a token scheme' do
61  end
62end
63