• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import antlr3
2import testbase
3import unittest
4
5class t013parser(testbase.ANTLRTest):
6    def setUp(self):
7        self.compileGrammar()
8
9
10    def testValid(self):
11        cStream = antlr3.StringStream('foobar')
12        lexer = self.getLexer(cStream)
13        tStream = antlr3.CommonTokenStream(lexer)
14        parser = self.getParser(tStream)
15        parser.document()
16
17        assert len(parser.reportedErrors) == 0, parser.reportedErrors
18        assert parser.identifiers == ['foobar']
19
20
21    def testMalformedInput1(self):
22        cStream = antlr3.StringStream('')
23        lexer = self.getLexer(cStream)
24        tStream = antlr3.CommonTokenStream(lexer)
25        parser = self.getParser(tStream)
26
27        parser.document()
28
29        # FIXME: currently strings with formatted errors are collected
30        # can't check error locations yet
31        assert len(parser.reportedErrors) == 1, parser.reportedErrors
32
33
34if __name__ == '__main__':
35    unittest.main()
36