now we read tests files from directories

This commit is contained in:
Sergey Ignatov
2011-11-04 20:16:37 +04:00
parent f8adc88299
commit 433405c4e1
470 changed files with 883 additions and 2124 deletions
@@ -1,89 +1,123 @@
package org.jetbrains.jet.j2k;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.psi.PsiJavaFile;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.j2k.TestCaseBuilder.getTestDataPathBase;
/**
* @author abreslav
* @author ignatov
*/
public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
private boolean checkInfos = false;
private final String dataPath;
private final String name;
public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
private String myDataPath;
private String myName;
protected JetTestCaseBase() {
this("", "");
public JavaToKotlinConverterTest(String dataPath, String name) {
myDataPath = dataPath;
myName = name;
}
private JetTestCaseBase(String dataPath, String name) {
this.dataPath = dataPath;
this.name = name;
private static String readFileAsString(String filePath)
throws java.io.IOException {
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
reader.close();
return fileData.toString();
}
public final JetTestCaseBase setCheckInfos(boolean checkInfos) {
this.checkInfos = checkInfos;
return this;
@Override
protected void runTest() throws Throwable {
String javaPath = getTestDataPath() + File.separator + getTestFilePath();
String kotlinPath = javaPath.replace(".jav", ".kt");
String expected = readFileAsString(kotlinPath);
String actual = "";
if (javaPath.contains("/expression_mult/")) actual = expressionToKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/expression/")) actual = expressionToKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/statement/")) actual = statementToSingleLineKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/statement_mult/")) actual = statementToKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/method/")) actual = methodToSingleLineKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/method_mult/")) actual = methodToKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/class/")) actual = classToSingleLineKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/class_mult/")) actual = classToKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/file/")) actual = fileToSingleLineKotlin(readFileAsString(javaPath));
else if (javaPath.contains("/file_mult/")) actual = fileToKotlin(readFileAsString(javaPath));
assert !actual.equals("");
Assert.assertEquals(expected, actual);
}
@NotNull
protected String getTestFilePath() {
return myDataPath + File.separator + myName + ".jav";
}
@Override
protected String getTestDataPath() {
return "testData";
}
private static Sdk jdkFromIdeaHome() {
return new JavaSdkImpl().createJdk("JDK", "jre", true);
}
@Override
protected String getTestDataPath() {
return getTestDataPathBase();
}
private static String getTestDataPathBase() {
return getHomeDirectory() + "/compiler/testData";
}
private static String getHomeDirectory() {
return new File(PathManager.getResourceRoot(JetTestCaseBase.class, "/org/jetbrains/jet/JetTestCaseBase.class")).getParentFile().getParentFile().getParent();
}
@Override
protected Sdk getProjectJDK() {
return jdkFromIdeaHome();
}
// @Override
// public String getName() {
// return "test" + name;
// }
// @Override
// protected void runTest() throws Throwable {
// doTest(getTestFilePath(), true, checkInfos);
// }
@NotNull
protected String getTestFilePath() {
return dataPath + File.separator + name + ".jet";
@Override
public String getName() {
return "test_" + myName;
}
protected String getDataPath() {
return dataPath;
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestCaseBuilder.suiteForDirectory(getTestDataPathBase(), "", true, new TestCaseBuilder.NamedTestFactory() {
@NotNull
@Override
public Test createTest(@NotNull String dataPath, @NotNull String name) {
return new JavaToKotlinConverterTest(dataPath, name);
}
}));
return suite;
}
void configureFromText(String text) throws IOException {
configureFromFileText("test.java", text);
}
protected String fileToKotlin(String text) throws IOException {
configureFromText(text);
return prettify(Converter.fileToFile((PsiJavaFile) myFile).toKotlin());
}
protected String fileToSingleLineKotlin(String text) throws IOException {
return toSingleLine(fileToKotlin(text));
}
@NotNull
protected String classToKotlin(String text) throws IOException {
configureFromText(text);
@@ -100,15 +134,6 @@ public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
return toSingleLine(classToKotlin(text));
}
protected String fileToKotlin(String text) throws IOException {
configureFromText(text);
return prettify(Converter.fileToFile((PsiJavaFile) myFile).toKotlin());
}
protected String fileToSingleLineKotlin(String text) throws IOException {
return toSingleLine(fileToKotlin(text));
}
protected String methodToKotlin(String text) throws IOException {
String result = classToKotlin("final class C {" + text + "}")
.replaceAll("class C \\{", "");
@@ -141,47 +166,6 @@ public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
return toSingleLine(expressionToKotlin(code));
}
public interface NamedTestFactory {
@NotNull
Test createTest(@NotNull String dataPath, @NotNull String name);
}
@NotNull
private static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull NamedTestFactory factory) {
TestSuite suite = new TestSuite(dataPath);
final String extension = ".jet";
FilenameFilter extensionFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(extension);
}
};
File dir = new File(baseDataDir + dataPath);
FileFilter dirFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
};
if (recursive) {
File[] files = dir.listFiles(dirFilter);
assert files != null : dir;
List<File> subdirs = Arrays.asList(files);
Collections.sort(subdirs);
for (File subdir : subdirs) {
suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, factory));
}
}
List<File> files = Arrays.asList(dir.listFiles(extensionFilter));
Collections.sort(files);
for (File file : files) {
String fileName = file.getName();
assert fileName != null;
suite.addTest(factory.createTest(dataPath, fileName.substring(0, fileName.length() - extension.length())));
}
return suite;
}
@NotNull
private static String prettify(String code) {
if (code == null)
@@ -0,0 +1,91 @@
package org.jetbrains.jet.j2k;
import com.intellij.openapi.application.PathManager;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author ignatov
*/
public abstract class TestCaseBuilder {
private static FilenameFilter emptyFilter = new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return true;
}
};
public static String getTestDataPathBase() {
return "testData";
}
public static String getHomeDirectory() {
return new File(PathManager.getResourceRoot(TestCaseBuilder.class, "/org/jetbrains/jet/TestCaseBuilder.class")).getParentFile().getParentFile().getParent();
}
public interface NamedTestFactory {
@NotNull Test createTest(@NotNull String dataPath, @NotNull String name);
}
@NotNull
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull NamedTestFactory factory) {
return suiteForDirectory(baseDataDir, dataPath, recursive, emptyFilter, factory);
}
@NotNull
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, final FilenameFilter filter, @NotNull NamedTestFactory factory) {
TestSuite suite = new TestSuite(dataPath);
final String extensionJava = ".jav";
final FilenameFilter extensionFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(extensionJava);
}
};
FilenameFilter resultFilter;
if (filter != emptyFilter) {
resultFilter = new FilenameFilter() {
@Override
public boolean accept(File file, String s) {
return extensionFilter.accept(file, s) && filter.accept(file, s);
}
};
}
else {
resultFilter = extensionFilter;
}
File dir = new File(baseDataDir + dataPath);
FileFilter dirFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
};
if (recursive) {
File[] files = dir.listFiles(dirFilter);
assert files != null : dir;
List<File> subdirs = Arrays.asList(files);
Collections.sort(subdirs);
for (File subdir : subdirs) {
suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory));
}
}
List<File> files = Arrays.asList(dir.listFiles(resultFilter));
Collections.sort(files);
for (File file : files) {
String fileName = file.getName();
assert fileName != null;
suite.addTest(factory.createTest(dataPath, fileName.substring(0, fileName.length() - extensionJava.length())));
}
return suite;
}
}
@@ -1,21 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ArrayAccessExpressionTest extends JetTestCaseBase {
public void testIntIndex() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("myArray[10]"), "myArray[10]");
}
public void testVariableIndex() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("myArray[i]"), "myArray[i]");
}
public void testExpressionIndex() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("myArray[myLibrary.calculateIndex(100)]"), "myArray[myLibrary.calculateIndex(100)]");
}
}
@@ -1,45 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ArrayInitializerExpressionTest extends JetTestCaseBase {
public void testOneDim() throws Exception {
Assert.assertEquals(
expressionToSingleLineKotlin("{1, 2, 3};"),
"array(1, 2, 3)"
);
}
public void testOneDimWithVariables() throws Exception {
Assert.assertEquals(
expressionToSingleLineKotlin("{a, b, c};"),
"array(a, b, c)"
);
}
public void testNewInt() throws Exception {
Assert.assertEquals(
expressionToSingleLineKotlin("new int[] {1, 2, 3};"),
"array(1, 2, 3)"
);
}
public void testTwoDim() throws Exception {
Assert.assertEquals(
expressionToSingleLineKotlin("{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };"),
"array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))"
);
}
// TODO
// public void testTwoDimNewInt() throws Exception {
// Assert.assertEquals(
// statementToSingleLineKotlin("int[][] myArray = new int[5][];"),
// "array(1, 2, 3)"
// );
// }
}
@@ -1,65 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ArrayTypeTest extends JetTestCaseBase {
public void testNewStringArray() throws Exception {
Assert.assertEquals(
statementToKotlin("String[] a = new String[]{\"abc\"}"),
"var a : Array<String?>? = array(\"abc\")"
);
}
public void testNewIntArray() throws Exception {
Assert.assertEquals(
statementToKotlin("int[] a = new int[]{1, 2, 3}"),
"var a : IntArray? = array(1, 2, 3)"
);
}
public void testDoubleArray() throws Exception {
Assert.assertEquals(
statementToKotlin("double[] a = new double[]{1, 2, 3}"),
"var a : DoubleArray? = array(1, 2, 3)"
);
}
public void testLongArray() throws Exception {
Assert.assertEquals(
statementToKotlin("long[] a = new long[]{1, 2, 3}"),
"var a : LongArray? = array(1, 2, 3)"
);
}
public void testMethodArrayArgs() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("void fromArrayToCollection(Foo[] a) {}"),
"fun fromArrayToCollection(a : Array<Foo?>?) : Unit { }"
);
}
public void testArrayInitializationStatement() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("int [][] d2 = new int[][]{};"),
"var d2 : Array<IntArray?>? = array()" // more precisely: "var d2 : Array<IntArray?>? = array<IntArray?>()"
);
}
public void testArrayInitializationStatementWithDimension() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("int [][] d2 = new int[5][];"),
"var d2 : Array<IntArray?>? = Array<IntArray?>?(5, {null})" // another variant: "var d2 : Array<IntArray?>? = array(5, {null, null, null, null, null})"
);
}
// public void testArrayInitializationStatementWithThreeDimension() throws Exception {
// Assert.assertEquals(
// statementToSingleLineKotlin("int[][][] d3= new int[5][5][5];"),
// "var d3 : Array<Array<IntArray?>?>? = Array<Array<IntArray?>?>?()"
// );
// }
}
@@ -1,30 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class AssertStatementTest extends JetTestCaseBase {
public void testOnlyCondition() throws Exception {
Assert.assertEquals(
statementToKotlin("assert boolMethod();"),
"assert {boolMethod()}"
);
}
public void testOnlyConditionWithBraces() throws Exception {
Assert.assertEquals(
statementToKotlin("assert(boolMethod());"),
"assert {(boolMethod())}"
);
}
public void testWithStringDetail() throws Exception {
Assert.assertEquals(
statementToKotlin("assert true : \"string details\";"),
"assert(\"string details\") {true}"
);
}
}
@@ -1,61 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class AssignmentExpressionTest extends JetTestCaseBase {
public void testSimpleAssignment() throws Exception {
Assert.assertEquals(statementToSingleLineKotlin("i = 1;"), "i = 1");
}
public void testShiftRight() throws Exception {
Assert.assertEquals(expressionToKotlin("x >>= 2"), "x = (x shr 2)");
}
public void testShiftLeft() throws Exception {
Assert.assertEquals(expressionToKotlin("x <<= 2"), "x = (x shl 2)");
}
public void testUnsignedRightShift() throws Exception {
Assert.assertEquals(expressionToKotlin("x >>>= 2"), "x = x.cyclicShiftRight(2)");
}
public void testXor() throws Exception {
Assert.assertEquals(expressionToKotlin("x ^= 2"), "x = (x xor 2)");
}
public void testAnd() throws Exception {
Assert.assertEquals(expressionToKotlin("x &= 2"), "x = (x and 2)");
}
public void testOr() throws Exception {
Assert.assertEquals(expressionToKotlin("x |= 2"), "x = (x or 2)");
}
public void testMultiplyAssign() throws Exception {
Assert.assertEquals(expressionToKotlin("x *= 2"), "x *= 2");
}
public void testDivideAssign() throws Exception {
Assert.assertEquals(expressionToKotlin("x /= 2"), "x /= 2");
}
public void testPlusAssign() throws Exception {
Assert.assertEquals(expressionToKotlin("x += 2"), "x += 2");
}
public void testMinusAssign() throws Exception {
Assert.assertEquals(expressionToKotlin("x -= 2"), "x -= 2");
}
public void testReminder() throws Exception {
Assert.assertEquals(expressionToKotlin("x %= 2"), "x %= 2");
}
public void testAssignment() throws Exception {
Assert.assertEquals(expressionToKotlin("x = 2"), "x = 2");
}
}
@@ -1,81 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class BinaryExpressionTest extends JetTestCaseBase {
public void testMultiply() throws Exception {
Assert.assertEquals(expressionToKotlin("1 * 2"), "(1 * 2)");
}
public void testDivide() throws Exception {
Assert.assertEquals(expressionToKotlin("1 / 2"), "(1 / 2)");
}
public void testRemainder() throws Exception {
Assert.assertEquals(expressionToKotlin("1 % 2"), "(1 % 2)");
}
public void testPlus() throws Exception {
Assert.assertEquals(expressionToKotlin("1 + 2"), "(1 + 2)");
}
public void testMinus() throws Exception {
Assert.assertEquals(expressionToKotlin("1 - 2"), "(1 - 2)");
}
public void testLessThan() throws Exception {
Assert.assertEquals(expressionToKotlin("1 < 2"), "(1 < 2)");
}
public void testGreaterThan() throws Exception {
Assert.assertEquals(expressionToKotlin("1 > 2"), "(1 > 2)");
}
public void testLessThanEqual() throws Exception {
Assert.assertEquals(expressionToKotlin("1 <= 2"), "(1 <= 2)");
}
public void testGreaterThanEqual() throws Exception {
Assert.assertEquals(expressionToKotlin("1 >= 2"), "(1 >= 2)");
}
public void testConditionalAnd() throws Exception {
Assert.assertEquals(expressionToKotlin("true && false"), "(true && false)");
}
public void testConditionalOr() throws Exception {
Assert.assertEquals(expressionToKotlin("true || false"), "(true || false)");
}
public void testShiftRight() throws Exception {
Assert.assertEquals(expressionToKotlin("x >> 2"), "(x shr 2)");
}
public void testShiftLeft() throws Exception {
Assert.assertEquals(expressionToKotlin("x << 2"), "(x shl 2)");
}
public void testUnsignedRightShift() throws Exception {
Assert.assertEquals(expressionToKotlin("x >>> 2"), "x.cyclicShiftRight(2)");
}
public void testXor() throws Exception {
Assert.assertEquals(expressionToKotlin("x ^ 2"), "(x xor 2)");
}
public void testAnd() throws Exception {
Assert.assertEquals(expressionToKotlin("x & 2"), "(x and 2)");
}
public void testOr() throws Exception {
Assert.assertEquals(expressionToKotlin("x | 2"), "(x or 2)");
}
// public void testNot() throws Exception { // TODO: move to prefix
// Assert.assertEquals(expressionToKotlin("~x"), "inv(x)");
// }
}
@@ -1,52 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class BoxedTypeTest extends JetTestCaseBase {
public void testObject() throws Exception {
Assert.assertEquals(statementToKotlin("Object i = 10;"), "var i : Any? = 10");
}
public void testBoolean() throws Exception {
Assert.assertEquals(statementToKotlin("Boolean i = 10;"), "var i : Boolean? = 10");
}
public void testByte() throws Exception {
Assert.assertEquals(statementToKotlin("Byte i = 10;"), "var i : Byte? = 10");
}
public void testCharacter() throws Exception {
Assert.assertEquals(statementToKotlin("Character i = 10;"), "var i : Char? = 10");
}
public void testDouble() throws Exception {
Assert.assertEquals(statementToKotlin("Double i = 10;"), "var i : Double? = 10");
}
public void testFloat() throws Exception {
Assert.assertEquals(statementToKotlin("Float i = 10;"), "var i : Float? = 10");
}
public void testInteger() throws Exception {
Assert.assertEquals(statementToKotlin("Integer i = 10;"), "var i : Int? = 10");
}
public void testLong() throws Exception {
Assert.assertEquals(statementToKotlin("Long i = 10;"), "var i : Long? = 10");
}
public void testShort() throws Exception {
Assert.assertEquals(statementToKotlin("Short i = 10;"), "var i : Short? = 10");
}
// public void testNewInteger() throws Exception {
// Assert.assertEquals(
// statementToKotlin("Integer i = new Integer(10);"),
// "var i : Int? = Integer(10).toInt()"
// );
// }
}
@@ -1,23 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class BreakStatementTest extends JetTestCaseBase {
public void testBreakWithoutLabel() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("break;"),
"break"
);
}
public void testBreakWithLabel() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("break label;"),
"break@label"
);
}
}
@@ -1,152 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ClassTest extends JetTestCaseBase {
public void testEmptyClass() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class A {}"),
"class A { }"
);
}
public void testInnerEmptyClass() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class A { inner final class B {} }"),
"class A { class B { } }"
);
}
public void testClassWithFields() throws Exception {
Assert.assertEquals(classToKotlin(
"final class T {" +
"String a = \"abc\";" +
"int b = 10;" +
"}"),
"class T {\n" +
"var a : String? = \"abc\"\n" +
"var b : Int = 10\n" +
"}");
}
public void testClassWithMultiplyFields() throws Exception {
Assert.assertEquals(classToKotlin(
"final class T {" +
"String a, b, c = \"abc\";" +
"}"),
"class T {\n" +
"var a : String?\n" +
"var b : String?\n" +
"var c : String? = \"abc\"\n" +
"}");
}
public void testClassWithEmptyMethods() throws Exception {
Assert.assertEquals(classToKotlin(
"final class T {" +
"void main() {}" +
"int i() {}" +
"String s() {}" +
"}"
),
"class T {\n" +
"fun main() : Unit {\n" +
"}\n" +
"fun i() : Int {\n" +
"}\n" +
"fun s() : String? {\n" +
"}\n" +
"}");
}
public void testGenericClass() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class Entry<K, V> {}"),
"class Entry<K, V> { }"
);
}
public void testSimpleInheritance() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class A extends Base {}"),
"class A : Base { }"
);
}
public void testExtendsOneClassAndImplementsOneInterface() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class A extends Base implements I {}"),
"class A : Base, I { }"
);
}
public void testExtendsOneClassAndImplementsSeveralInterfaces() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class A extends Base implements I0, I1, I2 {}"),
"class A : Base, I0, I1, I2 { }"
);
}
public void testClass() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("class Test {}"), "open class Test { }");
}
public void testFinalClass() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("final class Test {}"), "class Test { }");
}
public void testPublicClass() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("public class Test {}"), "public open class Test { }");
}
public void testProtectedClass() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("protected class Test {}"), "protected open class Test { }");
}
public void testPivateClass() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("private class Test {}"), "private open class Test { }");
}
public void testInternalClass() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("class Test {}"), "open class Test { }");
}
public void testOneStaticMethod() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class S { static boolean staticF() { return true; } }"),
"class S { class object { fun staticF() : Boolean { return true } } }"
);
}
public void testTwoStaticMethod() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class S { static boolean sB() { return true; } static int sI() { return 1; } }"),
"class S { class object { fun sB() : Boolean { return true } fun sI() : Int { return 1 } } }"
);
}
public void testOneStaticMethodOneNonStatic() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class S { boolean sB() { return true; } static int sI() { return 1; } }"),
"class S { class object { fun sI() : Int { return 1 } } fun sB() : Boolean { return true } }"
);
}
public void testOneStaticFieldOneNonStatic() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class S { boolean sB() { return true; } static int myI = 10; }"),
"class S { class object { var myI : Int = 10 } fun sB() : Boolean { return true } }"
);
}
public void testInnerStaticClass() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class S { static class Inner {} }"),
"class S { class object { open class Inner { } } }"
);
}
}
@@ -1,19 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ConditionalExpressionTest extends JetTestCaseBase {
public void testSimpleConditionalExpression() throws Exception {
Assert.assertEquals(
expressionToKotlin("a.isEmpty() ? 0 : 1"),
"(if (a.isEmpty())\n" +
"0\n" +
"else\n" +
"1)"
);
}
}
@@ -1,23 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ContinueStatementTest extends JetTestCaseBase {
public void testContinueWithoutLabel() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("continue;"),
"continue"
);
}
public void testContinueWithLabel() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("continue label;"),
"continue@label"
);
}
}
@@ -1,55 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class DeclarationStatementTest extends JetTestCaseBase {
public void testSingleStringDeclaration() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("String s;"),
"var s : String?"
);
}
public void testSingleIntDeclaration() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("int s;"),
"var s : Int"
);
}
public void testMultiplyIntDeclaration() throws Exception {
Assert.assertEquals(
statementToKotlin("int k, l, m;"),
"var k : Int\n" +
"var l : Int\n" +
"var m : Int"
);
}
public void testSingleFinalStringDeclaration() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("final String s;"),
"val s : String?"
);
}
public void testSingleFinalIntDeclaration() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("final int s;"),
"val s : Int"
);
}
public void testMultiplyFinalIntDeclaration() throws Exception {
Assert.assertEquals(
statementToKotlin("final int k, l, m;"),
"val k : Int\n" +
"val l : Int\n" +
"val m : Int"
);
}
}
@@ -1,45 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import org.jetbrains.jet.j2k.JetTestCaseBase;
import org.junit.Assert;
/**
* @author ignatov
*/
public class DoWhileStatementTest extends JetTestCaseBase {
public void testWhileWithEmptyBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("do {} while (true)"),
"do\n" +
"{\n" +
"}\n" +
"while (true)"
);
}
public void testWhileWithBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("do {int i = 1; i = i + 1;} while (a > b)"),
"do\n" +
"{\n" +
"var i : Int = 1\n" +
"i = (i + 1)\n" +
"}\n" +
"while ((a > b))"
);
}
public void testWhileWithReturn() throws Exception {
Assert.assertEquals(
statementToKotlin("do return 1; while (true)"),
"do\nreturn 1\nwhile (true)"
);
}
public void testWhileWithExpression() throws Exception {
Assert.assertEquals(
statementToKotlin("do i = i + 1; while (true)"),
"do\ni = (i + 1)\nwhile (true)"
);
}
}
@@ -1,159 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class EnumTest extends JetTestCaseBase {
public void testEmptyEnum() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("enum A {}"),
"enum A { }"
);
}
public void testTypeSafeEnum() throws Exception {
Assert.assertEquals(
classToKotlin("enum Coin { PENNY, NICKEL, DIME, QUARTER; }"),
"enum Coin {\n" +
"PENNY\n" +
"NICKEL\n" +
"DIME\n" +
"QUARTER\n" +
"}"
);
}
public void testOverrideToString() throws Exception {
Assert.assertEquals(
classToKotlin(
"enum Color {" +
" WHITE, BLACK, RED, YELLOW, BLUE;" +
"@Override String toString() {" +
" return \"COLOR\";" +
"}" +
"}"),
"enum Color {\n" +
"WHITE\n" +
"BLACK\n" +
"RED\n" +
"YELLOW\n" +
"BLUE\n" +
"override fun toString() : String? {\n" +
"return \"COLOR\"\n" +
"}\n" +
"}"
);
}
public void testFieldsWithPrimaryPrivateConstructor() throws Exception {
Assert.assertEquals(
classToKotlin(
"enum Color {\n" +
" WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);\n" +
"\n" +
" private int code;\n" +
"\n" +
" private Color(int c) {\n" +
" code = c;\n" +
" }\n" +
"\n" +
" public int getCode() {\n" +
" return code;\n" +
" }"),
"enum Color {\n" +
"WHITE(21)\n" +
"BLACK(22)\n" +
"RED(23)\n" +
"YELLOW(24)\n" +
"BLUE(25)\n" +
"private var code : Int\n" +
"private (c : Int) {\n" +
"code = c\n" +
"}\n" +
"public fun getCode() : Int {\n" +
"return code\n" +
"}\n" +
"}"
);
}
public void testEnumImplementsOneInterface() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("enum A implements I {}"),
"enum A : I { }"
);
}
public void testEnumWithNameField() throws Exception {
Assert.assertEquals(
classToKotlin("enum E { I; private String name; }"),
"enum E {\nI\nprivate var name : String?\n}"
);
}
public void testEnumImplementsSeveralInterfaces() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("enum A implements I0, I1, I2 {}"),
"enum A : I0, I1, I2 { }"
);
}
public void testPublicEnum() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("public enum Test {}"), "public enum Test { }");
}
public void testProtectedEnum() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("protected enum Test {}"), "protected enum Test { }");
}
public void testPrivateEnum() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("private enum Test {}"), "private enum Test { }");
}
public void testInternalEnum() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("enum Test {}"), "enum Test { }");
}
// public void testTwoConstructors() throws Exception {
// Assert.assertEquals(
// classToKotlin(
// "enum MultEnum {\n" +
// " GREMLIN(\"UTILITY\"),\n" +
// " MORT(30);\n" +
// " \n" +
// " MultEnum(String s) {\n" +
// " }\n" +
// " \n" +
// " MultEnum(int dmg) {\n" +
// " }"),
// "" // TODO: will fail
// );
// }
public void testRunnableImplementation() throws Exception {
Assert.assertEquals(
classToKotlin(
"enum Color implements Runnable {\n" +
" WHITE, BLACK, RED, YELLOW, BLUE;\n" +
"\n" +
" public void run() {\n" +
" System.out.println(\"name()=\" + name() +\n" +
" \", toString()=\" + toString());\n" +
" }\n" +
"}"),
"enum Color : Runnable {\n" +
"WHITE\n" +
"BLACK\n" +
"RED\n" +
"YELLOW\n" +
"BLUE\n" +
"override public fun run() : Unit {\n" +
"System.out.println((\"name()=\" + name() + \", toString()=\" + toString()))\n" +
"}\n" +
"}"
);
}
}
@@ -1,46 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class FieldTest extends JetTestCaseBase {
public void testVarWithoutInit() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("Foo f;"),
"var f : Foo?"
);
}
public void testVarWithInit() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("Foo f = new Foo(1, 2);"),
"var f : Foo? = Foo(1, 2)"
);
}
public void testValWithInit() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("final Foo f = new Foo(1, 2);"),
"val f : Foo? = Foo(1, 2)"
);
}
public void testPrivateField() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("private Foo f;"), "private var f : Foo?");
}
public void testProtectedField() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("protected Foo f;"), "protected var f : Foo?");
}
public void testPublicField() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("public Foo f;"), "public var f : Foo?");
}
public void testInternalField() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("Foo f;"), "var f : Foo?");
}
}
@@ -1,68 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class FileTest extends JetTestCaseBase {
public void testPackageWithImports() throws Exception {
Assert.assertEquals(
fileToKotlin(
"package test;" +
"import ast;" +
"import ast2;"),
"namespace test {" + "\n" +
"import ast" + "\n" +
"import ast2" + "\n" +
"}"
);
}
public void testPackageWithMixedImports() throws Exception {
Assert.assertEquals(
fileToKotlin(
"package test;" +
"import static ast;" +
"import ast2;"),
"namespace test {" + "\n" +
"import ast" + "\n" +
"import ast2" + "\n" +
"}"
);
}
public void testPackageWithStaticImports() throws Exception {
Assert.assertEquals(
fileToKotlin(
"package test;" +
"import static ast;" +
"import static ast2;"),
"namespace test {" + "\n" +
"import ast" + "\n" +
"import ast2" + "\n" +
"}"
);
}
public void testPackageWithClass() throws Exception {
Assert.assertEquals(
toSingleLine(fileToKotlin("package test; final class C {}")),
"namespace test { class C { } }"
);
}
public void testPackageWithOpenClass() throws Exception {
Assert.assertEquals(
toSingleLine(fileToKotlin("package test; class C {}")),
"namespace test { open class C { } }"
);
}
public void testPackageWithClasses() throws Exception {
Assert.assertEquals(
toSingleLine(fileToKotlin("final class A {} final class B {}")),
"namespace { class A { } class B { } }");
}
}
-115
View File
@@ -1,115 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ForTest extends JetTestCaseBase {
public void testCommonCaseForTest() throws Exception {
Assert.assertEquals(
statementToKotlin("for (init(); condition(); update()) body();"),
"{\n" +
"init()\n" +
"while (condition())\n" +
"{\n" +
"body()\n" +
"{\n" +
"update()\n" +
"}\n" +
"}\n" +
"}"
);
}
public void testForWithEmptyBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("for (int i = 0; i < 0; j++, i++) {}"),
"{\n" +
"var i : Int = 0\n" +
"while ((i < 0))\n" +
"{\n" +
"{\n" +
"}\n" +
"{\n" +
"(j++)\n" +
"(i++)\n" +
"}\n" +
"}\n" +
"}"
);
}
public void testForWithBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("for (int i = 0; i < 0; i++) {int i = 1; i++;}"),
"{\n" +
"var i : Int = 0\n" +
"while ((i < 0))\n" +
"{\n" +
"{\n" +
"var i : Int = 1\n" +
"(i++)\n" +
"}\n" +
"{\n" +
"(i++)\n" +
"}\n" +
"}\n" +
"}"
);
}
public void testForWithBlockAndDoubleUpdate() throws Exception {
Assert.assertEquals(
statementToKotlin("for (int i = 0; i < 0; j++, i++) {int i = 1; i++;}"),
"{\n" +
"var i : Int = 0\n" +
"while ((i < 0))\n" +
"{\n" +
"{\n" +
"var i : Int = 1\n" +
"(i++)\n" +
"}\n" +
"{\n" +
"(j++)\n" +
"(i++)\n" +
"}\n" +
"}\n" +
"}"
);
}
public void testForWithReturn() throws Exception {
Assert.assertEquals(
statementToKotlin("for (int i = 0; i < 0; j++, i++) return i;"),
"{\n" +
"var i : Int = 0\n" +
"while ((i < 0))\n" +
"{\n" +
"return i\n" +
"{\n" +
"(j++)\n" +
"(i++)\n" +
"}\n" +
"}\n" +
"}"
);
}
public void testForWithExpression() throws Exception {
Assert.assertEquals(
statementToKotlin("for (int i = 0; i < 0; i++) t++;"),
"{\n" +
"var i : Int = 0\n" +
"while ((i < 0))\n" +
"{\n" +
"(t++)\n" +
"{\n" +
"(i++)\n" +
"}\n" +
"}\n" +
"}"
);
}
}
@@ -1,41 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ForeachStatementTest extends JetTestCaseBase {
public void testEnhancedForWithEmptyBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("for (Node n : list) {}"),
"for (n : Node? in list)\n{\n" + "}"
);
}
public void testEnhancedForWithBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("for (Node n : list) {int i = 1; i++;}"),
"for (n : Node? in list)\n" +
"{\n" +
"var i : Int = 1\n" +
"(i++)\n" +
"}"
);
}
public void testEnhancedForWithReturn() throws Exception {
Assert.assertEquals(
statementToKotlin("for (Node n : list) return n;"),
"for (n : Node? in list)\nreturn n"
);
}
public void testEnhancedForWithExpression() throws Exception {
Assert.assertEquals(
statementToKotlin("for (Node n : list) i++;"),
"for (n : Node? in list)\n(i++)"
);
}
}
@@ -1,87 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class FunctionTest extends JetTestCaseBase {
public void testEmptyVoidMethod() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("void main() {}"),
"fun main() : Unit { }"
);
}
public void testMethodClassType() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("String main() {}"),
"fun main() : String? { }"
);
}
public void testMethodPrimitiveType() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("int main() {}"),
"fun main() : Int { }"
);
}
public void testMethodPrimitiveType2() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("boolean main() {}"),
"fun main() : Boolean { }"
);
}
public void testMethodWithReturnStatement() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("boolean isTrue() { return true; }"),
"fun isTrue() : Boolean { return true }"
);
}
public void testClassGenericParam() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("T getT() {}"),
"fun getT() : T? { }"
);
}
public void testOwnGenericParam() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("<U> void putU(U u) {}"),
"fun putU<U>(u : U?) : Unit { }"
);
}
public void testOwnSeveralGenericParams() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("<U, V, W> void putUVW(U u, V v, W w) {}"),
"fun putUVW<U, V, W>(u : U?, v : V?, w : W?) : Unit { }"
);
}
public void testInternal() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("void test() {}"), "fun test() : Unit { }");
}
public void testPrivate() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("private void test() {}"), "private fun test() : Unit { }");
}
public void testProtected() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("protected void test() {}"), "protected fun test() : Unit { }");
}
public void testPublic() throws Exception {
Assert.assertEquals(methodToSingleLineKotlin("public void test() {}"), "public fun test() : Unit { }");
}
public void testOverride() throws Exception {
Assert.assertEquals(fileToSingleLineKotlin("class A {void a() {}} final class B extends A {void a() {}}"),
"namespace { open class A { fun a() : Unit { } } class B : A { override fun a() : Unit { } } }");
}
}
@@ -1,11 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.TestCase;
/**
* @author ignatov
*/
public class IdentifierImplTest extends TestCase {
public void testEmpty() throws Exception { // TODO: remove
}
}
@@ -1,57 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class IfStatementTest extends JetTestCaseBase {
public void testIfStatementWithOneLineBlocks() throws Exception {
Assert.assertEquals(
statementToKotlin("if (true) return 1; else return 0;"),
"if (true)\n" +
"return 1\n" +
"else\n" +
"return 0"
);
}
public void testIfStatementWithMultilineBlocks() throws Exception {
Assert.assertEquals(
statementToKotlin("if (1 > 0) {int n = 1; return n;} else {return 0;}"),
"if ((1 > 0))\n" +
"{\n" +
"var n : Int = 1\n" +
"return n\n" +
"}\n" +
"else\n" +
"{\n" +
"return 0\n" +
"}"
);
}
public void testIfStatementWithoutElse() throws Exception {
Assert.assertEquals(
statementToKotlin("if (1 > 0) {int n = 1; return n;}"),
"if ((1 > 0))\n" +
"{\n" +
"var n : Int = 1\n" +
"return n\n" +
"}"
);
}
public void testIfStatementWithEmptyBlocks() throws Exception {
Assert.assertEquals(
statementToKotlin("if (1 > 0) {} else {}"),
"if ((1 > 0))\n" +
"{\n" +
"}\n" +
"else\n" +
"{\n" +
"}"
);
}
}
@@ -1,16 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class InProjectionTypeTest extends JetTestCaseBase {
public void testMethodParams() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("void popAll(Collection<? super E> dst) {}"),
"fun popAll(dst : Collection<in E?>?) : Unit { }"
);
}
}
@@ -1,23 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class IsOperatorTest extends JetTestCaseBase {
public void testSimpleReference() throws Exception {
Assert.assertEquals(
expressionToKotlin("a instanceof String"),
"(a is String?)"
);
}
public void testComplicatedExpression() throws Exception {
Assert.assertEquals(
expressionToKotlin("c.getType().getName() instanceof String"),
"(c.getType().getName() is String?)"
);
}
}
@@ -1,58 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class LabelStatementTest extends JetTestCaseBase {
public void testComplicatedExampleFromJavaTutorial() throws Exception {
Assert.assertEquals(
statementToKotlin(
" test:" +
" for (int i = 0; i <= max; i++) {" +
" int n = substring.length();" +
" int j = i;" +
" int k = 0;" +
" while (n-- != 0) {" +
" if (searchMe.charAt(j++) != substring.charAt(k++)) {" +
" continue test;" +
" }" +
" } " +
" foundIt = true;" +
" break test;" +
" }" +
" System.out.println(foundIt ? \"Found it\" : \"Didn't find it\");" +
" }" +
"}"),
"@test {\n" +
"var i : Int = 0\n" +
"while ((i <= max))\n" +
"{\n" +
"{\n" +
"var n : Int = substring.length()\n" +
"var j : Int = i\n" +
"var k : Int = 0\n" +
"while (((n--) != 0))\n" +
"{\n" +
"if ((searchMe.charAt((j++)) != substring.charAt((k++))))\n" +
"{\n" +
"continue@test\n" +
"}\n" +
"}\n" +
"foundIt = true\n" +
"break@test\n" +
"}\n" +
"{\n" +
"(i++)\n" +
"}\n" +
"}\n" +
"}\n" +
"System.out.println((if (foundIt)\n" +
"\"Found it\"\n" +
"else\n" +
"\"Didn't find it\"))"
);
}
}
@@ -1,16 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class LocalVariableTest extends JetTestCaseBase {
public void testObject() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("int i;"),
"var i : Int"
);
}
}
@@ -1,27 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class MethodCallExpressionTest extends JetTestCaseBase {
public void testSimpleCall() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("method(param1, param2);"), "method(param1, param2)"
);
}
public void testEmptyCall() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("methodCall();"), "methodCall()"
);
}
public void testCallWithKeywords() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("when(open, trait);"), "`when`(`open`, `trait`)"
);
}
}
@@ -1,25 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class NewClassExpressionTest extends JetTestCaseBase {
public void testClassWithoutBody() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("new Foo();"), "Foo()");
}
public void testClassWithoutBody2() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("new myApp.Foo();"), "myApp.Foo()");
}
public void testClassWithParam() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("new Foo(param);"), "Foo(param)");
}
public void testClassWithParams() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("new Foo(param1, param2);"), "Foo(param1, param2)");
}
}
@@ -1,16 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class OutProjectionTypeTest extends JetTestCaseBase {
public void testMethodParams() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("void pushAll(Collection<? extends E> src) {}"),
"fun pushAll(src : Collection<out E?>?) : Unit { }"
);
}
}
@@ -1,17 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ParenthesizedExpressionTest extends JetTestCaseBase {
public void testParenthesized() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("(1 + 2)"), "((1 + 2))");
}
public void testParenthesized2() throws Exception {
Assert.assertEquals(expressionToSingleLineKotlin("(o.toString() + \"abc\")"), "((o.toString() + \"abc\"))");
}
}
@@ -1,29 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class PolyadicExpressionTest extends JetTestCaseBase {
public void testMultiply() throws Exception {
Assert.assertEquals(expressionToKotlin("1 * 2 * 3"), "(1 * 2 * 3)");
}
public void testDivide() throws Exception {
Assert.assertEquals(expressionToKotlin("1 / 2 / 3"), "(1 / 2 / 3)");
}
public void testRemainder() throws Exception {
Assert.assertEquals(expressionToKotlin("1 % 2 % 3"), "(1 % 2 % 3)");
}
public void testPlus() throws Exception {
Assert.assertEquals(expressionToKotlin("1 + 2 + 3"), "(1 + 2 + 3)");
}
public void testMinus() throws Exception {
Assert.assertEquals(expressionToKotlin("1 - 2 - 3"), "(1 - 2 - 3)");
}
}
@@ -1,17 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class PostfixOperatorTest extends JetTestCaseBase {
public void testIncrement() throws Exception {
Assert.assertEquals(statementToKotlin("i++;"), "(i++)");
}
public void testDecrement() throws Exception {
Assert.assertEquals(statementToKotlin("i--;"), "(i--)");
}
}
@@ -1,17 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class PrefixOperatorTest extends JetTestCaseBase {
public void testIncrement() throws Exception {
Assert.assertEquals(statementToKotlin("++i;"), "(++i)");
}
public void testDecrement() throws Exception {
Assert.assertEquals(statementToKotlin("--i;"), "(--i)");
}
}
@@ -1,37 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ReturnStatementTest extends JetTestCaseBase {
public void testReturnLiteral() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("return true;"),
"return true"
);
}
public void testReturnString() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("return \"str\";"),
"return \"str\""
);
}
public void testReturnNumber() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("return 1;"),
"return 1"
);
}
public void testReturnChar() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("return 'c';"),
"return 'c'"
);
}
}
@@ -1,16 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class StarProjectionTypeTest extends JetTestCaseBase {
public void testMethodParams() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("void wtf(Collection<?> w) {}"),
"fun wtf(w : Collection<*>?) : Unit { }"
);
}
}
@@ -1,16 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class SynchronizedStatementTest extends JetTestCaseBase {
public void testSingleLineExample() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("synchronized (s) { doSomething(s); }"),
"synchronized (s) { doSomething(s) }"
);
}
}
@@ -1,14 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ThrowStatementTest extends JetTestCaseBase {
public void testSimpleThrowStatement() throws Exception {
Assert.assertEquals(
statementToSingleLineKotlin("throw exception;"), "throw exception");
}
}
@@ -1,95 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class TraitTest extends JetTestCaseBase {
public void testEmptyInterface() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("interface A {}"),
"trait A { }"
);
}
public void testInterfaceWithMethodDeclaration() throws Exception {
Assert.assertEquals(classToKotlin(
"interface INode {" +
"Tag getTag();" +
"String toKotlin();" +
"}"
),
"trait INode {\n" +
"public fun getTag() : Tag? \n" +
"public fun toKotlin() : String? \n" +
"}");
}
public void testInterfaceWithFields() throws Exception {
Assert.assertEquals(classToKotlin(
"interface INode {" +
"String IN = \"in\";" +
"String AT = \"@\";" +
"String COMMA_WITH_SPACE = COMMA + SPACE;" +
"}"
),
"trait INode {\n" +
"class object {\n" +
"public val IN : String? = \"in\"\n" +
"public val AT : String? = \"@\"\n" +
"public val COMMA_WITH_SPACE : String? = (COMMA + SPACE)\n" +
"}\n" +
"}"
);
}
public void testExtendsOneInterface() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("interface A extends I {}"),
"trait A : I { }"
);
}
public void testExtendsOneClassAndImplementsSeveralInterfaces() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("interface A extends I0, I1, I2 {}"),
"trait A : I0, I1, I2 { }"
);
}
public void testPublicInterface() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("public interface Test {}"), "public trait Test { }");
}
public void testProtectedInterface() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("protected interface Test {}"), "protected trait Test { }");
}
public void testPrivateInterface() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("private interface Test {}"), "private trait Test { }");
}
public void testInternalInterface() throws Exception {
Assert.assertEquals(classToSingleLineKotlin("interface Test {}"), "trait Test { }");
}
public void testInterfaceWithStaticFields() throws Exception {
Assert.assertEquals(classToKotlin(
"public interface INode {" +
" public static final String IN = \"in\";" +
" public static final String AT = \"@\";" +
" public static final String COMMA_WITH_SPACE = COMMA + SPACE;" +
"}"
),
"public trait INode {\n" +
"class object {\n" +
"public val IN : String? = \"in\"\n" +
"public val AT : String? = \"@\"\n" +
"public val COMMA_WITH_SPACE : String? = (COMMA + SPACE)\n" +
"}\n" +
"}"
);
}
}
@@ -1,111 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class TryStatementTest extends JetTestCaseBase {
public void testEmptyTryWithTwoCatchesWithoutFinally() throws Exception {
Assert.assertEquals(
statementToKotlin(
"try {" +
"} catch (Exception e) {" +
" println(1);" +
"} catch (IOException e) {" +
" println(0);" +
"}"),
"try\n" +
"{\n" +
"}\n" +
"catch (e : Exception?) {\n" +
"println(1)\n" +
"}\n" +
"catch (e : IOException?) {\n" +
"println(0)\n" +
"}"
);
}
public void testEmptyTryWithTwoCatchesWithEmptyFinally() throws Exception {
Assert.assertEquals(
statementToKotlin(
"try {" +
"} catch (Exception e) {" +
" println(1);" +
"} catch (IOException e) {" +
" println(0);" +
"} finally {}"),
"try\n" +
"{\n" +
"}\n" +
"catch (e : Exception?) {\n" +
"println(1)\n" +
"}\n" +
"catch (e : IOException?) {\n" +
"println(0)\n" +
"}\n" +
"finally\n" +
"{\n" +
"}"
);
}
public void testEmptyTryWithTwoCatchesWithFinally() throws Exception {
Assert.assertEquals(
statementToKotlin(
"try {" +
"} catch (Exception e) {" +
" println(1);" +
"} catch (IOException e) {" +
" println(0);" +
"} finally {" +
" println(3);" +
"}"),
"try\n" +
"{\n" +
"}\n" +
"catch (e : Exception?) {\n" +
"println(1)\n" +
"}\n" +
"catch (e : IOException?) {\n" +
"println(0)\n" +
"}\n" +
"finally\n" +
"{\n" +
"println(3)\n" +
"}"
);
}
public void testCommonCaseForTryStatement() throws Exception {
Assert.assertEquals(
statementToKotlin(
"try {" +
" callMethod(params);" +
"} catch (Exception e) {" +
" println(1);" +
"} catch (IOException e) {" +
" println(0);" +
"} finally {" +
" println(3);" +
"}"),
"try\n" +
"{\n" +
"callMethod(params)\n" +
"}\n" +
"catch (e : Exception?) {\n" +
"println(1)\n" +
"}\n" +
"catch (e : IOException?) {\n" +
"println(0)\n" +
"}\n" +
"finally\n" +
"{\n" +
"println(3)\n" +
"}"
);
}
}
@@ -1,65 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class TypeCastExpressionTest extends JetTestCaseBase {
public void testStringCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(String)t"),
"(t as String?)"
);
}
public void testIntCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(int)t"),
"(t as Int)"
);
}
public void testFooCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(Foo)t"),
"(t as Foo?)"
);
}
public void testPrimitiveType() throws Exception {
Assert.assertEquals(
expressionToKotlin("(int)100.00;"),
"(100.00 as Int)"
);
}
public void testSimpleGenericCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(List<Expression>)list"),
"(list as List<Expression?>?)"
);
}
public void testExtendsWildcardCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(List<? extends String>)list"),
"(list as List<out String?>?)"
);
}
public void testSuperWildcardCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(List<? super String>)list"),
"(list as List<in String?>?)"
);
}
public void testWildcardCast() throws Exception {
Assert.assertEquals(
expressionToKotlin("(List<?>)list"),
"(list as List<*>?)"
);
}
}
@@ -1,91 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class TypeParametersTest extends JetTestCaseBase {
public void testGenericParam() throws Exception {
Assert.assertEquals(
statementToKotlin("List<T> l;"),
"var l : List<T?>?"
);
}
public void testManyGenericParams() throws Exception {
Assert.assertEquals(
statementToKotlin("List<T, K, M> l;"),
"var l : List<T?, K?, M?>?"
);
}
public void testWhere() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin(
"<T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {}"),
"fun max<T : Any?>(coll : Collection<out T?>?) : T? where T : Comparable<in T?>? { }"
);
}
public void testMethodDoubleParametrizationWithTwoBounds() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin(
"<T extends Object & Comparable<? super T>, K extends Node & Collection<? super K>> T max(Collection<? extends T> coll) {}"),
"fun max<T : Any?, K : Node?>(coll : Collection<out T?>?) : T? where T : Comparable<in T?>?, K : Collection<in K?>? { }"
);
}
public void testClassDoubleParametrizationWithTwoBoundsWithExtending() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class CC <T extends INode & Comparable<? super T>, K extends Node & Collection<? super K>> extends A {}"),
"class CC<T : INode?, K : Node?> : A where T : Comparable<in T?>?, K : Collection<in K?>? { }"
);
}
public void testTraitDoubleParametrizationWithTwoBoundsWithExtending() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin(
"interface I <T extends INode & Comparable<? super T>, K extends Node & Collection<? super K>> extends II {}"),
"trait I<T : INode?, K : Node?> : II where T : Comparable<in T?>?, K : Collection<in K?>? { }"
);
}
public void testGenericClass() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class Comparable<T> {}"),
"class Comparable<T> { }"
);
}
public void testComplexExampleWithClassExtending() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin(
"interface CommandHandler<T extends Command> {}"),
"trait CommandHandler<T : Command?> { }"
);
}
public void testClassParametrizationWithTwoBounds() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class C<T extends INode & Comparable<? super T>> {}"),
"class C<T : INode?> where T : Comparable<in T?>? { }"
);
}
public void testClassParametrizationWithTwoBoundsWithExtending() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin("final class C<T extends INode & Comparable<? super T>> extends A {}"),
"class C<T : INode?> : A where T : Comparable<in T?>? { }"
);
}
public void testComplexExampleWithClassMultiplyExtending() throws Exception {
Assert.assertEquals(
classToSingleLineKotlin(
"interface CommandHandler<T extends INode, String> {}"),
"trait CommandHandler<T : INode?, String> { }"
);
}
}
@@ -1,23 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class VarArgTest extends JetTestCaseBase {
public void testEllipsisTypeSingleParams() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("void pushAll(Object... objs) {}"),
"fun pushAll(vararg objs : Any?) : Unit { }"
);
}
public void testEllipsisTypeSeveralParams() throws Exception {
Assert.assertEquals(
methodToSingleLineKotlin("String format(String pattern, Object... arguments);"),
"fun format(pattern : String?, vararg arguments : Any?) : String?"
);
}
}
@@ -1,41 +0,0 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class WhileStatementTest extends JetTestCaseBase {
public void testWhileWithEmptyBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("while (true) {}"),
"while (true)\n{\n}"
);
}
public void testWhileWithBlock() throws Exception {
Assert.assertEquals(
statementToKotlin("while (a > b) {int i = 1; i = i + 1;}"),
"while ((a > b))\n" +
"{\n" +
"var i : Int = 1\n" +
"i = (i + 1)\n" +
"}"
);
}
public void testWhileWithReturn() throws Exception {
Assert.assertEquals(
statementToKotlin("while (true) return 1;"),
"while (true)\nreturn 1"
);
}
public void testWhileWithExpression() throws Exception {
Assert.assertEquals(
statementToKotlin("while (true) i = i + 1;"),
"while (true)\ni = (i + 1)"
);
}
}
@@ -0,0 +1 @@
myArray[myLibrary.calculateIndex(100)]
@@ -0,0 +1 @@
myArray[myLibrary.calculateIndex(100)]
@@ -0,0 +1 @@
myArray[10]
@@ -0,0 +1 @@
myArray[10]
@@ -0,0 +1 @@
myArray[i]
@@ -0,0 +1 @@
myArray[i]
@@ -0,0 +1 @@
new int[] {1, 2, 3};
@@ -0,0 +1 @@
array(1, 2, 3)
@@ -0,0 +1 @@
{1, 2, 3};
@@ -0,0 +1 @@
array(1, 2, 3)
@@ -0,0 +1 @@
{a, b, c};
@@ -0,0 +1 @@
array(a, b, c)
@@ -0,0 +1 @@
{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
@@ -0,0 +1 @@
array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))
@@ -0,0 +1 @@
void fromArrayToCollection(Foo[] a) {}
@@ -0,0 +1 @@
fun fromArrayToCollection(a : Array<Foo?>?) : Unit { }
@@ -0,0 +1 @@
int [][] d2 = new int[][]{};
@@ -0,0 +1 @@
var d2 : Array<IntArray?>? = array()
@@ -0,0 +1 @@
int [][] d2 = new int[5][];
@@ -0,0 +1 @@
var d2 : Array<IntArray?>? = Array<IntArray?>?(5, {null})
@@ -0,0 +1 @@
double[] a = new double[]{1, 2, 3}
@@ -0,0 +1 @@
var a : DoubleArray? = array(1, 2, 3)
@@ -0,0 +1 @@
long[] a = new long[]{1, 2, 3}
@@ -0,0 +1 @@
var a : LongArray? = array(1, 2, 3)
@@ -0,0 +1 @@
int[] a = new int[]{1, 2, 3}
@@ -0,0 +1 @@
var a : IntArray? = array(1, 2, 3)
@@ -0,0 +1 @@
String[] a = new String[]{"abc"}
@@ -0,0 +1 @@
var a : Array<String?>? = array("abc")
@@ -0,0 +1 @@
assert boolMethod();
@@ -0,0 +1 @@
assert {boolMethod()}
@@ -0,0 +1 @@
assert(boolMethod());
@@ -0,0 +1 @@
assert {(boolMethod())}
@@ -0,0 +1 @@
assert true : "string details";
@@ -0,0 +1 @@
assert("string details") {true}
@@ -0,0 +1 @@
x &= 2
@@ -0,0 +1 @@
x = (x and 2)
@@ -0,0 +1 @@
x = 2
@@ -0,0 +1 @@
x = 2
@@ -0,0 +1 @@
x /= 2
@@ -0,0 +1 @@
x /= 2
@@ -0,0 +1 @@
x -= 2
@@ -0,0 +1 @@
x -= 2
@@ -0,0 +1 @@
x *= 2
@@ -0,0 +1 @@
x *= 2
@@ -0,0 +1 @@
x |= 2
@@ -0,0 +1 @@
x = (x or 2)
@@ -0,0 +1 @@
x += 2
@@ -0,0 +1 @@
x += 2
@@ -0,0 +1 @@
x %= 2
@@ -0,0 +1 @@
x %= 2
@@ -0,0 +1 @@
x <<= 2
@@ -0,0 +1 @@
x = (x shl 2)
@@ -0,0 +1 @@
x >>= 2
@@ -0,0 +1 @@
x = (x shr 2)
@@ -0,0 +1 @@
x >>>= 2
@@ -0,0 +1 @@
x = x.cyclicShiftRight(2)

Some files were not shown because too many files have changed in this diff Show More