• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/ruby
2# encoding: utf-8
3
4require 'antlr3'
5require 'test/unit'
6require 'spec'
7
8class DFASubclass < ANTLR3::DFA
9  EOT = [1, 2].freeze
10  EOF = [3, 4].freeze
11  MAX = [5, 6].freeze
12  MIN = [7, 8].freeze
13  ACCEPT = [9, 10, 11].freeze
14  SPECIAL = [12].freeze
15  TRANSITION = [
16    [13, 14, 15, 16].freeze,
17    [].freeze
18  ].freeze
19end
20
21class TestDFA < Test::Unit::TestCase
22  def test_init
23    dfa = DFASubclass.new(nil, 1)
24    dfa.eot.should == DFASubclass::EOT
25    dfa.eof.should == DFASubclass::EOF
26    dfa.max.should == DFASubclass::MAX
27    dfa.min.should == DFASubclass::MIN
28    dfa.accept.should == DFASubclass::ACCEPT
29    dfa.special.should == DFASubclass::SPECIAL
30    dfa.transition.should == DFASubclass::TRANSITION
31  end
32
33  def test_unpack
34    packed = [
35      1, 3, 1, 4, 2, -1, 1, 5, 18, -1, 1, 2,
36      25, -1, 1, 6, 6, -1, 26, 6, 4, -1, 1, 6,
37      1, -1, 26, 6
38    ]
39    unpacked = [
40      3, 4, -1, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41     -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43      6, -1, -1, -1, -1, -1, -1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
44      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -1, -1, -1, -1, 6, -1,
45      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
46      6, 6, 6, 6, 6
47    ]
48
49    ANTLR3::DFA.unpack(*packed).should == unpacked
50  end
51
52end
53