1import unittest 2import textwrap 3import antlr3 4import testbase 5 6class T(testbase.ANTLRTest): 7 def testRewrite(self): 8 self.compileGrammar() 9 10 input = textwrap.dedent( 11 '''\ 12 method foo() { 13 i = 3; 14 k = i; 15 i = k*4; 16 } 17 18 method bar() { 19 j = i*2; 20 } 21 ''') 22 23 cStream = antlr3.StringStream(input) 24 lexer = self.getLexer(cStream) 25 tStream = antlr3.TokenRewriteStream(lexer) 26 parser = self.getParser(tStream) 27 parser.program() 28 29 expectedOutput = textwrap.dedent('''\ 30 public class Wrapper { 31 public void foo() { 32 int k; 33 int i; 34 i = 3; 35 k = i; 36 i = k*4; 37 } 38 39 public void bar() { 40 int j; 41 j = i*2; 42 } 43 } 44 45 ''') 46 47 self.assertEqual(str(tStream), expectedOutput) 48 49 50if __name__ == '__main__': 51 unittest.main() 52 53