diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java index d7334730dd3..ca11b803942 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java @@ -6745,6 +6745,39 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { public void testTmpInsidePrimaryConstructor() throws Exception { runTest("js/js.translator/testData/box/regression/tmpInsidePrimaryConstructor.kt"); } + + @TestMetadata("js/js.translator/testData/box/regression/stdlibTestSnippets") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class StdlibTestSnippets extends AbstractIrBoxJsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInStdlibTestSnippets() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/regression/stdlibTestSnippets"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true); + } + + @TestMetadata("arrayTest_plusInference.kt") + public void testArrayTest_plusInference() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/arrayTest_plusInference.kt"); + } + + @TestMetadata("iterableChunked.kt") + public void testIterableChunked() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/iterableChunked.kt"); + } + + @TestMetadata("json.kt") + public void testJson() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/json.kt"); + } + + @TestMetadata("throwable.kt") + public void testThrowable() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/throwable.kt"); + } + } } @TestMetadata("js/js.translator/testData/box/reified") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index fbcacfa9d56..64edc48d1b1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -6780,6 +6780,39 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { public void testTmpInsidePrimaryConstructor() throws Exception { runTest("js/js.translator/testData/box/regression/tmpInsidePrimaryConstructor.kt"); } + + @TestMetadata("js/js.translator/testData/box/regression/stdlibTestSnippets") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class StdlibTestSnippets extends AbstractBoxJsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInStdlibTestSnippets() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/regression/stdlibTestSnippets"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("arrayTest_plusInference.kt") + public void testArrayTest_plusInference() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/arrayTest_plusInference.kt"); + } + + @TestMetadata("iterableChunked.kt") + public void testIterableChunked() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/iterableChunked.kt"); + } + + @TestMetadata("json.kt") + public void testJson() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/json.kt"); + } + + @TestMetadata("throwable.kt") + public void testThrowable() throws Exception { + runTest("js/js.translator/testData/box/regression/stdlibTestSnippets/throwable.kt"); + } + } } @TestMetadata("js/js.translator/testData/box/reified") diff --git a/js/js.translator/testData/box/regression/stdlibTestSnippets/arrayTest_plusInference.kt b/js/js.translator/testData/box/regression/stdlibTestSnippets/arrayTest_plusInference.kt new file mode 100644 index 00000000000..5d6a91cb08f --- /dev/null +++ b/js/js.translator/testData/box/regression/stdlibTestSnippets/arrayTest_plusInference.kt @@ -0,0 +1,17 @@ +// EXPECTED_REACHABLE_NODES: 1273 +// KJS_WITH_FULL_RUNTIME + +// Copy of stdlib test test.collections.ArraysTest.plusInference + +fun box(): String { + val arrayOfArrays: Array> = arrayOf(arrayOf("s") as Array) + val elementArray = arrayOf("a") as Array + val arrayPlusElement: Array> = arrayOfArrays.plusElement(elementArray) + assertEquals("a", arrayPlusElement[1][0]) + + val arrayOfStringArrays = arrayOf(arrayOf("s")) + val arrayPlusArray = arrayOfStringArrays + arrayOfStringArrays + assertEquals("s", arrayPlusArray[1][0]) + + return "OK" +} diff --git a/js/js.translator/testData/box/regression/stdlibTestSnippets/iterableChunked.kt b/js/js.translator/testData/box/regression/stdlibTestSnippets/iterableChunked.kt new file mode 100644 index 00000000000..87ea4ca2b61 --- /dev/null +++ b/js/js.translator/testData/box/regression/stdlibTestSnippets/iterableChunked.kt @@ -0,0 +1,15 @@ +// EXPECTED_REACHABLE_NODES: 1750 +// KJS_WITH_FULL_RUNTIME + +fun box(): String { + val size = 2 + val a = Array(size) { "$it" } + val data = Iterable { a.iterator() } + + val dataChunked = data.chunked(size).single() + val expectedSingleChunk = data.toList() + if (expectedSingleChunk != dataChunked) + return "Fail" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/regression/stdlibTestSnippets/json.kt b/js/js.translator/testData/box/regression/stdlibTestSnippets/json.kt new file mode 100644 index 00000000000..c91500d8a70 --- /dev/null +++ b/js/js.translator/testData/box/regression/stdlibTestSnippets/json.kt @@ -0,0 +1,13 @@ +// EXPECTED_REACHABLE_NODES: 1274 +// KJS_WITH_FULL_RUNTIME + +import kotlin.js.json + +fun box(): String { + var obj = json(Pair("firstName", "John"), Pair("lastName", "Doe"), Pair("age", 30)) + assertEquals("John", obj["firstName"], "firstName") + assertEquals("Doe", obj["lastName"], "lastName") + assertEquals(30, obj["age"], "age") + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/regression/stdlibTestSnippets/throwable.kt b/js/js.translator/testData/box/regression/stdlibTestSnippets/throwable.kt new file mode 100644 index 00000000000..10ab02fcefc --- /dev/null +++ b/js/js.translator/testData/box/regression/stdlibTestSnippets/throwable.kt @@ -0,0 +1,51 @@ +// EXPECTED_REACHABLE_NODES: 1279 +// Snippet from stdlib test test.exceptions.ExceptionTest + +private val cause = Exception("cause") + +fun assertSame(x: Any?, y: Any?) { + if (x !== y) { + error("Assertion failed") + } +} + +private fun testCreateException( + noarg: () -> T, + fromMessage: (String?) -> T, + fromCause: ((Throwable?) -> T)? = null, + fromMessageCause: ((String?, Throwable?) -> T)? = null +) { + noarg().let { e -> + assertEquals(null, e.message) + assertEquals(null, e.cause) + } + + fromMessage("message").let { e -> + assertEquals("message", e.message) + assertEquals(null, e.cause) + } + + fromMessage(null).let { e -> + assertTrue(e.message == null || e.message == "null") + } + + fromMessageCause?.run { + invoke("message", cause).let { e -> + assertEquals("message", e.message) + assertSame(cause, e.cause) + } + invoke(null, null).let { e -> + assertEquals(null, e.message) + assertEquals(null, e.cause) + } + } + + fromCause?.invoke(cause)?.let { e -> + assertSame(cause, e.cause) + } +} + +fun box(): String { + testCreateException(::Throwable, ::Throwable, ::Throwable, ::Throwable) + return "OK" +}