1
2import unittest
3
4import antlr3
5
6
7class TestDFA(unittest.TestCase):
8    """Test case for the DFA class."""
9
10    def setUp(self):
11        """Setup test fixure.
12
13        We need a Recognizer in order to instanciate a DFA.
14
15        """
16
17        class TRecognizer(antlr3.BaseRecognizer):
18            api_version = 'HEAD'
19
20        self.recog = TRecognizer()
21
22
23    def testInit(self):
24        """DFA.__init__()
25
26        Just a smoke test.
27
28        """
29
30        dfa = antlr3.DFA(
31            self.recog, 1,
32            eot=[],
33            eof=[],
34            min=[],
35            max=[],
36            accept=[],
37            special=[],
38            transition=[]
39            )
40
41
42    def testUnpack(self):
43        """DFA.unpack()"""
44
45        self.failUnlessEqual(
46            antlr3.DFA.unpack(
47            u"\1\3\1\4\2\uffff\1\5\22\uffff\1\2\31\uffff\1\6\6\uffff"
48            u"\32\6\4\uffff\1\6\1\uffff\32\6"
49            ),
50            [ 3, 4, -1, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
51              -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
52              -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
53              6, -1, -1, -1, -1, -1, -1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
54              6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -1, -1, -1, -1, 6, -1,
55              6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
56              6, 6, 6, 6, 6
57              ]
58            )
59
60
61
62if __name__ == "__main__":
63    unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
64