01: /**
02: *
03: * Copyright 2005 Jeremy Rayner
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: **/package org.codehaus.groovy.antlr.treewalker;
18:
19: import groovy.util.GroovyTestCase;
20:
21: import java.io.ByteArrayOutputStream;
22: import java.io.File;
23: import java.io.PrintStream;
24: import java.io.StringReader;
25: import java.util.Arrays;
26: import java.util.Iterator;
27: import java.util.List;
28:
29: import org.apache.commons.cli.CommandLine;
30: import org.apache.commons.cli.Options;
31: import org.apache.commons.cli.PosixParser;
32: import org.codehaus.groovy.antlr.AntlrASTProcessor;
33: import org.codehaus.groovy.antlr.SourceBuffer;
34: import org.codehaus.groovy.antlr.UnicodeEscapingReader;
35: import org.codehaus.groovy.antlr.java.Java2GroovyConverter;
36: import org.codehaus.groovy.antlr.java.Java2GroovyMain;
37: import org.codehaus.groovy.antlr.java.JavaLexer;
38: import org.codehaus.groovy.antlr.java.JavaRecognizer;
39: import org.codehaus.groovy.runtime.DefaultGroovyMethods;
40:
41: import antlr.collections.AST;
42:
43: public class Java2GroovyTest extends GroovyTestCase {
44:
45: public void testSimpleClass() throws Exception {
46: assertEquals("private class Foo {int x = 1}",
47: convert("private class Foo{int x=1;}"));
48: }
49:
50: public void testStringLiteral() throws Exception {
51: assertEquals("class Foo {String x = \"mooky\"}",
52: convert("public class Foo{String x = \"mooky\";}"));
53: assertEquals(
54: "class C {void m(String s) {File f = new File(\"sl\" + s)}}",
55: convert("public class C{void m(String s) {File f=new File(\"sl\" + s);}}"));
56: }
57:
58: private String convert(String input) throws Exception {
59: return Java2GroovyMain.convert(input);
60: }
61:
62: private String mindmap(String input) throws Exception {
63: return Java2GroovyMain.mindmap(input);
64: }
65:
66: private String nodePrinter(String input) throws Exception {
67: return Java2GroovyMain.nodePrinter(input);
68: }
69: }
|