[JS IR BE] hashCode, toString, number conversion support
This commit is contained in:
@@ -545,7 +545,11 @@ abstract class BasicBoxTest(
|
||||
val psiManager = PsiManager.getInstance(project)
|
||||
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||
|
||||
return psiManager.findFile(fileSystem.findFileByPath(fileName)!!) as KtFile
|
||||
val file = fileSystem.findFileByPath(fileName)
|
||||
if (file == null)
|
||||
error("File not found: ${fileName}")
|
||||
|
||||
return psiManager.findFile(file) as KtFile
|
||||
}
|
||||
|
||||
private fun createPsiFiles(fileNames: List<String>): List<KtFile> = fileNames.map(this::createPsiFile)
|
||||
|
||||
@@ -45,6 +45,9 @@ abstract class BasicIrBoxTest(
|
||||
) {
|
||||
val runtime = listOf(
|
||||
"libraries/stdlib/js/src/kotlin/core.kt",
|
||||
"libraries/stdlib/js/irRuntime/core.kt",
|
||||
"libraries/stdlib/js/irRuntime/numberConversion.kt",
|
||||
"libraries/stdlib/js/irRuntime/compareTo.kt",
|
||||
"libraries/stdlib/js/irRuntime/annotations.kt",
|
||||
"libraries/stdlib/js/irRuntime/DefaultConstructorMarker.kt",
|
||||
"libraries/stdlib/js/irRuntime/exceptions.kt",
|
||||
|
||||
+23
@@ -47,6 +47,29 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/box/builtins")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Builtins extends AbstractBoxJsTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuiltins() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/builtins"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("hashCode.kt")
|
||||
public void testHashCode() throws Exception {
|
||||
runTest("js/js.translator/testData/box/builtins/hashCode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toString.kt")
|
||||
public void testToString() throws Exception {
|
||||
runTest("js/js.translator/testData/box/builtins/toString.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/box/callableReference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+23
@@ -47,6 +47,29 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/box/builtins")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Builtins extends AbstractIrBoxJsTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuiltins() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/builtins"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("hashCode.kt")
|
||||
public void testHashCode() throws Exception {
|
||||
runTest("js/js.translator/testData/box/builtins/hashCode.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toString.kt")
|
||||
public void testToString() throws Exception {
|
||||
runTest("js/js.translator/testData/box/builtins/toString.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/box/callableReference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1117
|
||||
package foo
|
||||
|
||||
class A {
|
||||
override fun hashCode() = 42
|
||||
}
|
||||
|
||||
class B
|
||||
|
||||
fun box(): String {
|
||||
if (A().hashCode() != 42) return "Wrong hash 0"
|
||||
|
||||
val o1 = B();
|
||||
if (o1.hashCode() != o1.hashCode()) return "Wrong hash 1"
|
||||
|
||||
val o2 = js("\"\"")
|
||||
if (o2.hashCode() != o2.hashCode()) return "Wrong hash 2"
|
||||
|
||||
val o3 = js("123")
|
||||
if (o3.hashCode() != o3.hashCode()) return "Wrong hash 3"
|
||||
|
||||
val o4 = 123
|
||||
if (o4.hashCode() != o4.hashCode()) return "Wrong hash 4"
|
||||
|
||||
val o5 = "123"
|
||||
if (o5.hashCode() != o5.hashCode()) return "Wrong hash 5"
|
||||
|
||||
val o6 = (123 as Any)
|
||||
if (o6.hashCode() != o6.hashCode()) return "Wrong hash 6"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1117
|
||||
package foo
|
||||
|
||||
class A {
|
||||
override fun toString() = "42"
|
||||
}
|
||||
|
||||
class B
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(A().toString(), "42")
|
||||
assertEquals(B().toString(), "[object Object]")
|
||||
assertEquals(js("\"\"").toString(), "")
|
||||
assertEquals(js("123").toString(), "123")
|
||||
assertEquals(123.toString(), "123")
|
||||
assertEquals("123".toString(), "123")
|
||||
assertEquals((123 as Any).toString(), "123")
|
||||
assertEquals(null.toString(), "null")
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1109
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1126
|
||||
// This test was adapted from compiler/testData/codegen/box/classes
|
||||
package foo
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1114
|
||||
package foo
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1110
|
||||
package foo
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1114
|
||||
package foo
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1109
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1109
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1109
|
||||
/*
|
||||
* Copy of JVM-backend test
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1112
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1110
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1110
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1114
|
||||
// http://youtrack.jetbrains.com/issue/KT-5345
|
||||
// KT-5345 (Javascript) Type mismatch on Int / Float division
|
||||
|
||||
Reference in New Issue
Block a user