aboutsummaryrefslogtreecommitdiff
path: root/antlr-3.4/runtime/Python/tests/t046rewrite.py
diff options
context:
space:
mode:
Diffstat (limited to 'antlr-3.4/runtime/Python/tests/t046rewrite.py')
-rw-r--r--antlr-3.4/runtime/Python/tests/t046rewrite.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/antlr-3.4/runtime/Python/tests/t046rewrite.py b/antlr-3.4/runtime/Python/tests/t046rewrite.py
new file mode 100644
index 0000000..a61ede4
--- /dev/null
+++ b/antlr-3.4/runtime/Python/tests/t046rewrite.py
@@ -0,0 +1,55 @@
+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()
+