    1   /***
    2    *
    3    * Copyright 2005 Jeremy Rayner
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * 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   **/
    18  package org.codehaus.groovy.antlr.treewalker;
    19
    20  import groovy.util.GroovyTestCase;
    21
    22  import java.io.ByteArrayOutputStream;
    23  import java.io.File;
    24  import java.io.PrintStream;
    25  import java.io.StringReader;
    26  import java.util.Arrays;
    27  import java.util.Iterator;
    28  import java.util.List;
    29
    30  import org.apache.commons.cli.CommandLine;
    31  import org.apache.commons.cli.Options;
    32  import org.apache.commons.cli.PosixParser;
    33  import org.codehaus.groovy.antlr.AntlrASTProcessor;
    34  import org.codehaus.groovy.antlr.SourceBuffer;
    35  import org.codehaus.groovy.antlr.UnicodeEscapingReader;
    36  import org.codehaus.groovy.antlr.java.Java2GroovyConverter;
    37  import org.codehaus.groovy.antlr.java.Java2GroovyMain;
    38  import org.codehaus.groovy.antlr.java.JavaLexer;
    39  import org.codehaus.groovy.antlr.java.JavaRecognizer;
    40  import org.codehaus.groovy.runtime.DefaultGroovyMethods;
    41
    42  import antlr.collections.AST;
    43
    44  public class Java2GroovyTest extends GroovyTestCase {
    45
    46  	public void testSimpleClass() throws Exception {
    47  		assertEquals("private class Foo {int x = 1}", convert("private class Foo{int x=1;}"));
    48  	}
    49
    50  	public void testStringLiteral() throws Exception {
    51          assertEquals("class Foo {String x = \"mooky\"}", convert("public class Foo{String x = \"mooky\";}"));
    52          assertEquals("class C {void m(String s) {File f = new File(\"sl\" + s)}}", convert("public class C{void m(String s) {File f=new File(\"sl\" + s);}}"));
    53  	}
    54
    55  	private String convert(String input) throws Exception {
    56  		return Java2GroovyMain.convert(input);
    57  	}
    58  	private String mindmap(String input) throws Exception {
    59  		return Java2GroovyMain.mindmap(input);
    60  	}
    61  	private String nodePrinter(String input) throws Exception {
    62  		return Java2GroovyMain.nodePrinter(input);
    63  	}
    64  }
    65