Home | History | Annotate | Download | only in tests
      1 import antlr3
      2 import testbase
      3 import unittest
      4 
      5 
      6 class t025lexerRulePropertyRef(testbase.ANTLRTest):
      7     def setUp(self):
      8         self.compileGrammar()
      9         
     10 
     11     def testValid1(self):
     12         stream = antlr3.StringStream('foobar _Ab98 \n A12sdf')
     13         lexer = self.getLexer(stream)
     14 
     15         while True:
     16             token = lexer.nextToken()
     17             if token.type == antlr3.EOF:
     18                 break
     19 
     20         assert len(lexer.properties) == 3, lexer.properties
     21 
     22         text, type, line, pos, index, channel, start, stop = lexer.properties[0]
     23         assert text == 'foobar', lexer.properties[0]
     24         assert type == self.lexerModule.IDENTIFIER, lexer.properties[0]
     25         assert line == 1, lexer.properties[0]
     26         assert pos == 0, lexer.properties[0]
     27         assert index == -1, lexer.properties[0]
     28         assert channel == antlr3.DEFAULT_CHANNEL, lexer.properties[0]
     29         assert start == 0, lexer.properties[0]
     30         assert stop == 5, lexer.properties[0]
     31 
     32         text, type, line, pos, index, channel, start, stop = lexer.properties[1]
     33         assert text == '_Ab98', lexer.properties[1]
     34         assert type == self.lexerModule.IDENTIFIER, lexer.properties[1]
     35         assert line == 1, lexer.properties[1]
     36         assert pos == 7, lexer.properties[1]
     37         assert index == -1, lexer.properties[1]
     38         assert channel == antlr3.DEFAULT_CHANNEL, lexer.properties[1]
     39         assert start == 7, lexer.properties[1]
     40         assert stop == 11, lexer.properties[1]
     41 
     42         text, type, line, pos, index, channel, start, stop = lexer.properties[2]
     43         assert text == 'A12sdf', lexer.properties[2]
     44         assert type == self.lexerModule.IDENTIFIER, lexer.properties[2]
     45         assert line == 2, lexer.properties[2]
     46         assert pos == 1, lexer.properties[2]
     47         assert index == -1, lexer.properties[2]
     48         assert channel == antlr3.DEFAULT_CHANNEL, lexer.properties[2]
     49         assert start == 15, lexer.properties[2]
     50         assert stop == 20, lexer.properties[2]
     51 
     52 
     53 if __name__ == '__main__':
     54     unittest.main()
     55