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