diff --git a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java index d0efbc59e82..c59798dbabc 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java @@ -20,9 +20,13 @@ import com.google.common.collect.Lists; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.k2js.config.EcmaVersion; +import org.jetbrains.k2js.facade.MainCallParameters; +import org.jetbrains.k2js.test.utils.TranslationUtils; import java.io.File; import java.util.Collections; +import java.util.EnumSet; import java.util.List; import static org.jetbrains.k2js.test.utils.JsTestUtils.convertFileNameToDotJsFile; @@ -84,6 +88,22 @@ public abstract class BasicTest extends TestWithEnvironment { return Collections.singletonList(KOTLIN_JS_LIB); } + protected void generateJavaScriptFiles(@NotNull String kotlinFilename, + @NotNull MainCallParameters mainCallParameters, + @NotNull EnumSet ecmaVersions) throws Exception { + generateJavaScriptFiles(Collections.singletonList(getInputFilePath(kotlinFilename)), kotlinFilename, mainCallParameters, + ecmaVersions); + } + + protected void generateJavaScriptFiles(@NotNull List files, @NotNull String testName, + @NotNull MainCallParameters mainCallParameters, @NotNull EnumSet ecmaVersions) + throws Exception { + for (EcmaVersion version : ecmaVersions) { + TranslationUtils.translateFiles(getProject(), files, getOutputFilePath(testName, version), mainCallParameters, version); + } + } + + protected static String casesDirectoryName() { return CASES; } @@ -129,8 +149,17 @@ public abstract class BasicTest extends TestWithEnvironment { } @NotNull - protected String getOutputFilePath(@NotNull String filename) { - return getOutputPath() + convertFileNameToDotJsFile(filename); + protected List getOutputFilePaths(@NotNull String filename, @NotNull EnumSet ecmaVersions) { + List result = Lists.newArrayList(); + for (EcmaVersion ecmaVersion : ecmaVersions) { + result.add(getOutputFilePath(filename, ecmaVersion)); + } + return result; + } + + @NotNull + protected String getOutputFilePath(@NotNull String filename, @NotNull EcmaVersion ecmaVersion) { + return getOutputPath() + convertFileNameToDotJsFile(filename, ecmaVersion); } @NotNull diff --git a/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java b/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java index 70b6ba4d6a1..2fd8c67b395 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java @@ -17,14 +17,12 @@ package org.jetbrains.k2js.test; import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.facade.MainCallParameters; -import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker; import java.util.List; -import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest; import static org.jetbrains.k2js.test.utils.JsTestUtils.getAllFilesInDir; -import static org.jetbrains.k2js.test.utils.TranslationUtils.translateFiles; /** * @author Pavel Talanov @@ -37,14 +35,14 @@ public abstract class MultipleFilesTranslationTest extends BasicTest { protected void generateJsFromDir(@NotNull String dirName) throws Exception { List fullFilePaths = getAllFilesInDir(getInputFilePath(dirName)); - translateFiles(getProject(), fullFilePaths, getOutputFilePath(dirName + ".kt"), MainCallParameters.noCall()); + generateJavaScriptFiles(fullFilePaths, dirName, MainCallParameters.noCall(), EcmaVersion.all()); } protected void runMultiFileTest(@NotNull String dirName, @NotNull String namespaceName, @NotNull String functionName, @NotNull Object expectedResult) throws Exception { generateJsFromDir(dirName); - runRhinoTest(withAdditionalFiles(getOutputFilePath(dirName + ".kt")), - new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult)); + //runRhinoTest(withAdditionalFiles(getOutputFilePaths(dirName + ".kt", EcmaVersion.all())), + // new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult)); } public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java b/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java index 599ef455565..4d5a53e00ef 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java @@ -18,10 +18,13 @@ package org.jetbrains.k2js.test; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.facade.MainCallParameters; import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker; import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker; -import org.jetbrains.k2js.test.utils.TranslationUtils; + +import java.util.EnumSet; +import java.util.List; import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest; import static org.jetbrains.k2js.test.utils.JsTestUtils.readFile; @@ -36,15 +39,15 @@ public abstract class SingleFileTranslationTest extends BasicTest { super(main); } - public void runFunctionOutputTest(String filename, String namespaceName, + public void runFunctionOutputTest(String kotlinFilename, String namespaceName, String functionName, Object expectedResult) throws Exception { - generateJsFromFile(filename, MainCallParameters.noCall()); - runRhinoTest(withAdditionalFiles(getOutputFilePath(filename)), - new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult)); - } - - protected void generateJsFromFile(@NotNull String filename, @NotNull MainCallParameters mainCallParameters) throws Exception { - TranslationUtils.translateFile(getProject(), getInputFilePath(filename), getOutputFilePath(filename), mainCallParameters); + EnumSet ecmaVersions = EcmaVersion.all(); + generateJavaScriptFiles(kotlinFilename, MainCallParameters.noCall(), ecmaVersions); + List outputFilePaths = getOutputFilePaths(kotlinFilename, ecmaVersions); + for (String outputFilePath : outputFilePaths) { + runRhinoTest(withAdditionalFiles(outputFilePath), + new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult)); + } } public void checkFooBoxIsTrue(@NotNull String filename) throws Exception { @@ -59,10 +62,14 @@ public abstract class SingleFileTranslationTest extends BasicTest { runFunctionOutputTest(filename, "foo", "box", "OK"); } - protected void checkOutput(@NotNull String filename, @NotNull String expectedResult, @NotNull String... args) throws Exception { - generateJsFromFile(filename, MainCallParameters.mainWithArguments(Lists.newArrayList(args))); - runRhinoTest(withAdditionalFiles(getOutputFilePath(filename)), - new RhinoSystemOutputChecker(expectedResult)); + protected void checkOutput(@NotNull String kotlinFilename, @NotNull String expectedResult, @NotNull String... args) throws Exception { + EnumSet ecmaVersions = EcmaVersion.all(); + generateJavaScriptFiles(kotlinFilename, MainCallParameters.mainWithArguments(Lists.newArrayList(args)), ecmaVersions); + List outputFilePaths = getOutputFilePaths(kotlinFilename, ecmaVersions); + for (String outputFilePath : outputFilePaths) { + runRhinoTest(withAdditionalFiles(outputFilePath), + new RhinoSystemOutputChecker(expectedResult)); + } } protected void performTestWithMain(@NotNull String testName, @NotNull String testId, @NotNull String... args) throws Exception { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/InlineTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/InlineTest.java index 7f808428247..85705c2da0e 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/InlineTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/InlineTest.java @@ -18,6 +18,7 @@ package org.jetbrains.k2js.test.semantics; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.test.SingleFileTranslationTest; import java.io.File; @@ -68,7 +69,7 @@ public final class InlineTest extends SingleFileTranslationTest { private void checkFooBoxIsTrueAndFunctionNameIsNotReferenced(@NotNull String filename, String funName) throws Exception { fooBoxTest(); - String generatedJSFilePath = getOutputFilePath(filename); + String generatedJSFilePath = getOutputFilePath(filename, EcmaVersion.defaultVersion()); String outputFileText = FileUtil.loadFile(new File(generatedJSFilePath)); assertTrue(countOccurrences(outputFileText, funName) == 1); } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java b/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java index 3065d749389..fdbca4eb642 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java @@ -18,6 +18,7 @@ package org.jetbrains.k2js.test.utils; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.EcmaVersion; import java.io.File; import java.io.FileInputStream; @@ -33,8 +34,13 @@ public final class JsTestUtils { private JsTestUtils() { } - public static String convertFileNameToDotJsFile(@NotNull String filename) { - return filename.substring(0, filename.lastIndexOf('.')) + ".js"; + public static String convertFileNameToDotJsFile(@NotNull String filename, EcmaVersion ecmaVersion) { + String postFix = "_" + ecmaVersion.toString() + ".js"; + int index = filename.lastIndexOf('.'); + if (index < 0) { + return filename + postFix; + } + return filename.substring(0, index) + postFix; } @NotNull diff --git a/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java b/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java index 13a2ecfc5fb..8c34792fd46 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.facade.K2JSTranslator; import org.jetbrains.k2js.facade.MainCallParameters; import org.jetbrains.k2js.generate.CodeGenerator; @@ -45,13 +46,13 @@ public final class TranslationUtils { private static /*var*/ K2JSTranslator translator = null; public static void translateFile(@NotNull Project project, @NotNull String inputFile, - @NotNull String outputFile, @NotNull MainCallParameters mainCallParameters) throws Exception { - translateFiles(project, Collections.singletonList(inputFile), outputFile, mainCallParameters); + @NotNull String outputFile, @NotNull MainCallParameters mainCallParameters, @NotNull EcmaVersion version) throws Exception { + translateFiles(project, Collections.singletonList(inputFile), outputFile, mainCallParameters, version); } public static void translateFiles(@NotNull Project project, @NotNull List inputFiles, - @NotNull String outputFile, @NotNull MainCallParameters mainCallParameters) throws Exception { - + @NotNull String outputFile, @NotNull MainCallParameters mainCallParameters, @NotNull EcmaVersion version) throws Exception { + //TODO: ignoring version for the moment List psiFiles = createPsiFileList(inputFiles, project); JsProgram program = getTranslator(project).generateProgram(psiFiles, mainCallParameters); FileWriter writer = new FileWriter(new File(outputFile)); diff --git a/js/js.translator/src/org/jetbrains/k2js/config/EcmaVersion.java b/js/js.translator/src/org/jetbrains/k2js/config/EcmaVersion.java index b17fc2acde7..ffc346459ba 100644 --- a/js/js.translator/src/org/jetbrains/k2js/config/EcmaVersion.java +++ b/js/js.translator/src/org/jetbrains/k2js/config/EcmaVersion.java @@ -20,6 +20,8 @@ import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.EnumSet; + /** * @author Pavel Talanov */ @@ -35,4 +37,9 @@ public enum EcmaVersion { public static EcmaVersion defaultVersion() { return v3; } + + @NotNull + public static EnumSet all() { + return EnumSet.allOf(EcmaVersion.class); + } }