KT-2298 js inter-module communication
This commit is contained in:
@@ -42,7 +42,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
runFunctionOutputTest(EcmaVersion.all(), kotlinFilename, namespaceName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
protected void runFunctionOutputTest(@NotNull EnumSet<EcmaVersion> ecmaVersions, @NotNull String kotlinFilename,
|
||||
protected void runFunctionOutputTest(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String kotlinFilename,
|
||||
@NotNull String namespaceName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult) throws Exception {
|
||||
@@ -50,7 +50,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename, @NotNull EnumSet<EcmaVersion> ecmaVersions) throws Exception {
|
||||
public void checkFooBoxIsTrue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
runFunctionOutputTest(ecmaVersions, filename, "foo", "box", true);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
checkFooBoxIsTrue(getTestName(true) + ".kt", EcmaVersion.all());
|
||||
}
|
||||
|
||||
protected void fooBoxTest(@NotNull EnumSet<EcmaVersion> ecmaVersions) throws Exception {
|
||||
protected void fooBoxTest(@NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
checkFooBoxIsTrue(getTestName(true) + ".kt", ecmaVersions);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoSystemOutputChecker(expectedResult));
|
||||
}
|
||||
|
||||
protected void performTestWithMain(@NotNull EnumSet<EcmaVersion> ecmaVersions,
|
||||
protected void performTestWithMain(@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String testName,
|
||||
@NotNull String testId,
|
||||
@NotNull String... args) throws Exception {
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class TestConfig extends Config {
|
||||
private /*var*/ List<JetFile> jsLibFiles = null;
|
||||
|
||||
public TestConfig(@NotNull Project project, @NotNull EcmaVersion version) {
|
||||
super(project, version);
|
||||
super(project, "main", version);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -39,11 +39,6 @@ class RhinoFunctionManager {
|
||||
this.functionName = functionName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFunctionName() {
|
||||
return functionName;
|
||||
}
|
||||
|
||||
private Script compileScript(int optimizationLevel) {
|
||||
long startNano = System.nanoTime();
|
||||
Context context = Context.enter();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.k2js.test.rhino;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
@@ -59,10 +60,14 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
}
|
||||
|
||||
private String functionCallString() {
|
||||
String result = functionName + "()";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (namespaceName != null) {
|
||||
result = "Kotlin.defs." + namespaceName + "." + result;
|
||||
sb.append("Kotlin.modules.main");
|
||||
if (namespaceName != Namer.getRootNamespaceName()) {
|
||||
sb.append('.').append(namespaceName);
|
||||
}
|
||||
sb.append('.');
|
||||
}
|
||||
return result;
|
||||
return sb.append(functionName).append("()").toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.k2js.test.BasicTest;
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -49,12 +48,7 @@ public final class RhinoUtils {
|
||||
new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
try {
|
||||
return FileUtil.loadFile(new File(BasicTest.JSLINT_LIB));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return fileToString(BasicTest.JSLINT_LIB);
|
||||
}
|
||||
},
|
||||
"JSLINT"
|
||||
@@ -64,15 +58,19 @@ public final class RhinoUtils {
|
||||
|
||||
}
|
||||
|
||||
private static String fileToString(String file) {
|
||||
try {
|
||||
return FileUtil.loadFile(new File(file));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runFileWithRhino(@NotNull String inputFile,
|
||||
@NotNull Context context,
|
||||
@NotNull Scriptable scope) throws Exception {
|
||||
FileReader reader = new FileReader(inputFile);
|
||||
try {
|
||||
context.evaluateReader(scope, reader, inputFile, 1, null);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
context.evaluateString(scope, fileToString(inputFile), inputFile, 1, null);
|
||||
}
|
||||
|
||||
public static void runRhinoTest(@NotNull List<String> fileNames,
|
||||
|
||||
Reference in New Issue
Block a user