diff --git a/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java b/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java index bb88309f447..5ab654e34c5 100644 --- a/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java +++ b/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java @@ -400,8 +400,23 @@ public final class ExpressionVisitor extends TranslatorVisitor { @NotNull public JsNode visitBinaryWithTypeRHSExpression(@NotNull JetBinaryExpressionWithTypeRHS expression, @NotNull TranslationContext context) { + // we actually do not care for types in js return Translation.translateExpression(expression.getLeft(), context); } + @Override + @NotNull + public JsNode visitBreakExpression(@NotNull JetBreakExpression expression, + @NotNull TranslationContext context) { + return new JsBreak(); + } + + @Override + @NotNull + public JsNode visitContinueExpression(@NotNull JetContinueExpression expression, + @NotNull TranslationContext context) { + return new JsContinue(); + } + } diff --git a/translator/test/org/jetbrains/k2js/test/AbstractExpressionTest.java b/translator/test/org/jetbrains/k2js/test/AbstractExpressionTest.java new file mode 100644 index 00000000000..bb96c99a92a --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/AbstractExpressionTest.java @@ -0,0 +1,22 @@ +package org.jetbrains.k2js.test; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Talanov Pavel + */ +public abstract class AbstractExpressionTest extends TranslationTest { + + private final String SUITE = "expression/"; + + @Override + protected List generateFilenameList(String inputFile) { + return Arrays.asList(inputFile); + } + + @Override + protected String suiteDirectoryName() { + return SUITE; + } +} diff --git a/translator/test/org/jetbrains/k2js/test/ConditionalTest.java b/translator/test/org/jetbrains/k2js/test/ConditionalTest.java new file mode 100644 index 00000000000..a7124ad6923 --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/ConditionalTest.java @@ -0,0 +1,31 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + */ +public class ConditionalTest extends AbstractExpressionTest { + final private static String MAIN = "conditional/"; + + @Override + protected String mainDirectory() { + return MAIN; + } + + @Test + public void ifElseAsExpression() throws Exception { + testFooBoxIsTrue("ifElseAsExpression.kt"); + } + + @Test + public void ifElse() throws Exception { + testFunctionOutput("if.kt", "foo", "box", 5); + } + + //TODO: test fails due to isStatement issue, include when issue is solved or implement another solution +// @Test +// public void ifElseIf() throws Exception { +// testFunctionOutput("elseif.kt", "foo", "box", 5); +// } +} diff --git a/translator/test/org/jetbrains/k2js/test/ExpressionTest.java b/translator/test/org/jetbrains/k2js/test/ExpressionTest.java deleted file mode 100644 index 2415c9a6ef7..00000000000 --- a/translator/test/org/jetbrains/k2js/test/ExpressionTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.jetbrains.k2js.test; - -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; - -/** - * @author Talanov Pavel - *

- * This class tests basic language features and constructs such as constants, local variables, simple loops, - * conditional clauses etc. - */ -public final class ExpressionTest extends TranslationTest { - - private static final String MAIN = "expression/"; - - protected String mainDirectory() { - return MAIN; - } - - @Override - protected List generateFilenameList(String inputFile) { - return Arrays.asList(inputFile); - } - - @Test - public void currentTest() throws Exception { - testFooBoxIsTrue("test.kt"); - } - - @Test - public void testAssign() throws Exception { - testFunctionOutput("assign.jet", "foo", "f", 2.0); - } - - @Test - public void namespaceProperties() throws Exception { - testFunctionOutput("localProperty.jet", "foo", "box", 50); - } - - @Test - public void comparison() throws Exception { - testFooBoxIsTrue("comparison.kt"); - } - - @Test - public void ifElse() throws Exception { - testFunctionOutput("if.kt", "foo", "box", 5); - } - //TODO: test fails due to isStatement issue, include when issue is solved or implement another solution -// @Test -// public void ifElseIf() throws Exception { -// testFunctionOutput("elseif.kt", "foo", "box", 5); -// } - - @Test - public void whileSimpleTest() throws Exception { - testFooBoxIsTrue("while.kt"); - } - - @Test - public void doWhileSimpleTest() throws Exception { - testFooBoxIsTrue("doWhile.kt"); - } - - @Test - public void doWhileExecutesAtLeastOnce() throws Exception { - testFooBoxIsTrue("doWhile2.kt"); - } - - @Test - public void whileDoesntExecuteEvenOnceIfConditionIsFalse() throws Exception { - testFooBoxIsTrue("while2.kt"); - } - - @Test - public void stringConstant() throws Exception { - testFooBoxIsTrue("stringConstant.kt"); - } - - @Test - public void stringAssignment() throws Exception { - testFooBoxIsTrue("stringAssignment.kt"); - } - - @Test - public void functionUsedBeforeDeclaration() throws Exception { - testFooBoxIsTrue("functionUsedBeforeDeclaration.kt"); - } - - @Test - public void functionWithTwoParametersCall() throws Exception { - testFooBoxIsTrue("functionWithTwoParametersCall.kt"); - } - - @Test - public void prefixIntOperations() throws Exception { - testFooBoxIsTrue("prefixIntOperations.kt"); - } - - @Test - public void postfixIntOperations() throws Exception { - testFooBoxIsTrue("postfixIntOperations.kt"); - } - - @Test - public void notBoolean() throws Exception { - testFooBoxIsTrue("notBoolean.kt"); - } - - @Test - public void positiveAndNegativeNumbers() throws Exception { - testFooBoxIsTrue("positiveAndNegativeNumbers.kt"); - } - - @Test - public void ifElseAsExpression() throws Exception { - testFooBoxIsTrue("ifElseAsExpression.kt"); - } - -} diff --git a/translator/test/org/jetbrains/k2js/test/FunctionTest.java b/translator/test/org/jetbrains/k2js/test/FunctionTest.java new file mode 100644 index 00000000000..ad96579343a --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/FunctionTest.java @@ -0,0 +1,26 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + */ +public class FunctionTest extends AbstractExpressionTest { + + final private static String MAIN = "function/"; + + @Override + protected String mainDirectory() { + return MAIN; + } + + @Test + public void functionUsedBeforeDeclaration() throws Exception { + testFooBoxIsTrue("functionUsedBeforeDeclaration.kt"); + } + + @Test + public void functionWithTwoParametersCall() throws Exception { + testFooBoxIsTrue("functionWithTwoParametersCall.kt"); + } +} diff --git a/translator/test/org/jetbrains/k2js/test/MiscTest.java b/translator/test/org/jetbrains/k2js/test/MiscTest.java new file mode 100644 index 00000000000..da01678566a --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/MiscTest.java @@ -0,0 +1,23 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + *

+ * This class contains tests that do not fall in any particular category + * most probably because that functionality has very little support + */ +public class MiscTest extends AbstractExpressionTest { + final private static String MAIN = "misc/"; + + @Override + protected String mainDirectory() { + return MAIN; + } + + @Test + public void namespaceProperties() throws Exception { + testFunctionOutput("localProperty.jet", "foo", "box", 50); + } +} diff --git a/translator/test/org/jetbrains/k2js/test/OperationTest.java b/translator/test/org/jetbrains/k2js/test/OperationTest.java new file mode 100644 index 00000000000..92be83c7be0 --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/OperationTest.java @@ -0,0 +1,45 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + */ +public class OperationTest extends AbstractExpressionTest { + final private static String MAIN = "operation/"; + + @Override + protected String mainDirectory() { + return MAIN; + } + + @Test + public void prefixIntOperations() throws Exception { + testFooBoxIsTrue("prefixIntOperations.kt"); + } + + @Test + public void postfixIntOperations() throws Exception { + testFooBoxIsTrue("postfixIntOperations.kt"); + } + + @Test + public void notBoolean() throws Exception { + testFooBoxIsTrue("notBoolean.kt"); + } + + @Test + public void positiveAndNegativeNumbers() throws Exception { + testFooBoxIsTrue("positiveAndNegativeNumbers.kt"); + } + + @Test + public void assign() throws Exception { + testFunctionOutput("assign.jet", "foo", "f", 2.0); + } + + @Test + public void comparison() throws Exception { + testFooBoxIsTrue("comparison.kt"); + } +} diff --git a/translator/test/org/jetbrains/k2js/test/StringTest.java b/translator/test/org/jetbrains/k2js/test/StringTest.java new file mode 100644 index 00000000000..fa8a9b09d02 --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/StringTest.java @@ -0,0 +1,26 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + */ +public class StringTest extends AbstractExpressionTest { + + final private static String MAIN = "string/"; + + @Override + protected String mainDirectory() { + return MAIN; + } + + @Test + public void stringConstant() throws Exception { + testFooBoxIsTrue("stringConstant.kt"); + } + + @Test + public void stringAssignment() throws Exception { + testFooBoxIsTrue("stringAssignment.kt"); + } +} diff --git a/translator/test/org/jetbrains/k2js/test/TranslationTest.java b/translator/test/org/jetbrains/k2js/test/TranslationTest.java index 3a6454b59ea..80b4e3eef0c 100644 --- a/translator/test/org/jetbrains/k2js/test/TranslationTest.java +++ b/translator/test/org/jetbrains/k2js/test/TranslationTest.java @@ -1,7 +1,6 @@ package org.jetbrains.k2js.test; import org.jetbrains.k2js.K2JSTranslator; -import org.junit.Before; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; @@ -19,29 +18,34 @@ public abstract class TranslationTest { final private static String OUT = "out/"; final private String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js"; - protected String testFilesDirectory; - protected String testCasesDirectory; - protected String outputDirectory; - - @Before - public void setUpClass() { - testCasesDirectory = CASES; - outputDirectory = OUT; - testFilesDirectory = TEST_FILES + mainDirectory(); - } - protected abstract String mainDirectory(); protected String kotlinLibraryPath() { return KOTLIN_JS_LIB; } - private String getOutputDirectory() { - return testFilesDirectory + outputDirectory; + private String casesDirectoryName() { + return CASES; } - private String getInputDirectory() { - return testFilesDirectory + testCasesDirectory; + private String outDirectoryName() { + return OUT; + } + + private String testFilesPath() { + return TEST_FILES + suiteDirectoryName() + mainDirectory(); + } + + protected String suiteDirectoryName() { + return ""; + } + + private String getOutputPath() { + return testFilesPath() + outDirectoryName(); + } + + private String getInputPath() { + return testFilesPath() + casesDirectoryName(); } protected void testFunctionOutput(String filename, String namespaceName, @@ -62,7 +66,7 @@ public abstract class TranslationTest { //TODO: refactor filename generation logic private String getOutputFilePath(String filename) { - return getOutputDirectory() + convertToDotJsFile(filename); + return getOutputPath() + convertToDotJsFile(filename); } private String convertToDotJsFile(String filename) { @@ -70,7 +74,7 @@ public abstract class TranslationTest { } private String getInputFilePath(String filename) { - return getInputDirectory() + filename; + return getInputPath() + filename; } protected String cases(String filename) { diff --git a/translator/test/org/jetbrains/k2js/test/WhileTest.java b/translator/test/org/jetbrains/k2js/test/WhileTest.java new file mode 100644 index 00000000000..c7b0c03d0a1 --- /dev/null +++ b/translator/test/org/jetbrains/k2js/test/WhileTest.java @@ -0,0 +1,35 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + */ +public final class WhileTest extends AbstractExpressionTest { + + private static final String MAIN = "while/"; + + protected String mainDirectory() { + return MAIN; + } + + @Test + public void whileSimpleTest() throws Exception { + testFooBoxIsTrue("while.kt"); + } + + @Test + public void doWhileSimpleTest() throws Exception { + testFooBoxIsTrue("doWhile.kt"); + } + + @Test + public void doWhileExecutesAtLeastOnce() throws Exception { + testFooBoxIsTrue("doWhile2.kt"); + } + + @Test + public void whileDoesntExecuteEvenOnceIfConditionIsFalse() throws Exception { + testFooBoxIsTrue("while2.kt"); + } +} diff --git a/translator/testFiles/expression/cases/test.kt b/translator/testFiles/expression/cases/test.kt deleted file mode 100644 index 98ee81ba1ea..00000000000 --- a/translator/testFiles/expression/cases/test.kt +++ /dev/null @@ -1,9 +0,0 @@ -namespace foo - -fun box() : Boolean { - val a = 2; - val b = 3; - var c = 4; - return (a < c) -} - diff --git a/translator/testFiles/expression/cases/elseif.kt b/translator/testFiles/expression/conditional/cases/elseif.kt similarity index 100% rename from translator/testFiles/expression/cases/elseif.kt rename to translator/testFiles/expression/conditional/cases/elseif.kt diff --git a/translator/testFiles/expression/cases/if.kt b/translator/testFiles/expression/conditional/cases/if.kt similarity index 100% rename from translator/testFiles/expression/cases/if.kt rename to translator/testFiles/expression/conditional/cases/if.kt diff --git a/translator/testFiles/expression/cases/ifElseAsExpression.kt b/translator/testFiles/expression/conditional/cases/ifElseAsExpression.kt similarity index 100% rename from translator/testFiles/expression/cases/ifElseAsExpression.kt rename to translator/testFiles/expression/conditional/cases/ifElseAsExpression.kt diff --git a/translator/testFiles/expression/cases/functionUsedBeforeDeclaration.kt b/translator/testFiles/expression/function/cases/functionUsedBeforeDeclaration.kt similarity index 100% rename from translator/testFiles/expression/cases/functionUsedBeforeDeclaration.kt rename to translator/testFiles/expression/function/cases/functionUsedBeforeDeclaration.kt diff --git a/translator/testFiles/expression/cases/functionWithTwoParametersCall.kt b/translator/testFiles/expression/function/cases/functionWithTwoParametersCall.kt similarity index 100% rename from translator/testFiles/expression/cases/functionWithTwoParametersCall.kt rename to translator/testFiles/expression/function/cases/functionWithTwoParametersCall.kt diff --git a/translator/testFiles/expression/cases/localProperty.jet b/translator/testFiles/expression/misc/cases/localProperty.jet similarity index 100% rename from translator/testFiles/expression/cases/localProperty.jet rename to translator/testFiles/expression/misc/cases/localProperty.jet diff --git a/translator/testFiles/expression/cases/assign.jet b/translator/testFiles/expression/operation/cases/assign.jet similarity index 100% rename from translator/testFiles/expression/cases/assign.jet rename to translator/testFiles/expression/operation/cases/assign.jet diff --git a/translator/testFiles/expression/cases/comparison.kt b/translator/testFiles/expression/operation/cases/comparison.kt similarity index 100% rename from translator/testFiles/expression/cases/comparison.kt rename to translator/testFiles/expression/operation/cases/comparison.kt diff --git a/translator/testFiles/expression/cases/notBoolean.kt b/translator/testFiles/expression/operation/cases/notBoolean.kt similarity index 100% rename from translator/testFiles/expression/cases/notBoolean.kt rename to translator/testFiles/expression/operation/cases/notBoolean.kt diff --git a/translator/testFiles/expression/cases/positiveAndNegativeNumbers.kt b/translator/testFiles/expression/operation/cases/positiveAndNegativeNumbers.kt similarity index 100% rename from translator/testFiles/expression/cases/positiveAndNegativeNumbers.kt rename to translator/testFiles/expression/operation/cases/positiveAndNegativeNumbers.kt diff --git a/translator/testFiles/expression/cases/postfixIntOperations.kt b/translator/testFiles/expression/operation/cases/postfixIntOperations.kt similarity index 100% rename from translator/testFiles/expression/cases/postfixIntOperations.kt rename to translator/testFiles/expression/operation/cases/postfixIntOperations.kt diff --git a/translator/testFiles/expression/cases/prefixIntOperations.kt b/translator/testFiles/expression/operation/cases/prefixIntOperations.kt similarity index 100% rename from translator/testFiles/expression/cases/prefixIntOperations.kt rename to translator/testFiles/expression/operation/cases/prefixIntOperations.kt diff --git a/translator/testFiles/expression/cases/stringAssignment.kt b/translator/testFiles/expression/string/cases/stringAssignment.kt similarity index 100% rename from translator/testFiles/expression/cases/stringAssignment.kt rename to translator/testFiles/expression/string/cases/stringAssignment.kt diff --git a/translator/testFiles/expression/cases/stringConstant.kt b/translator/testFiles/expression/string/cases/stringConstant.kt similarity index 100% rename from translator/testFiles/expression/cases/stringConstant.kt rename to translator/testFiles/expression/string/cases/stringConstant.kt diff --git a/translator/testFiles/expression/cases/doWhile.kt b/translator/testFiles/expression/while/cases/doWhile.kt similarity index 100% rename from translator/testFiles/expression/cases/doWhile.kt rename to translator/testFiles/expression/while/cases/doWhile.kt diff --git a/translator/testFiles/expression/cases/doWhile2.kt b/translator/testFiles/expression/while/cases/doWhile2.kt similarity index 100% rename from translator/testFiles/expression/cases/doWhile2.kt rename to translator/testFiles/expression/while/cases/doWhile2.kt diff --git a/translator/testFiles/expression/cases/while.kt b/translator/testFiles/expression/while/cases/while.kt similarity index 100% rename from translator/testFiles/expression/cases/while.kt rename to translator/testFiles/expression/while/cases/while.kt diff --git a/translator/testFiles/expression/cases/while2.kt b/translator/testFiles/expression/while/cases/while2.kt similarity index 100% rename from translator/testFiles/expression/cases/while2.kt rename to translator/testFiles/expression/while/cases/while2.kt