From 9e3ecbd90264658bf79b5e5ab55b66680d4c6f3e Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Wed, 25 Dec 2019 13:39:48 +0300 Subject: [PATCH] [Spec tests] Add codegen tests for indexing-expression (paragraph 3) --- .../indexing-expressions/p-3/pos/1.1.kt | 27 +++++++ .../indexing-expressions/p-3/pos/1.2.kt | 25 ++++++ .../indexing-expressions/p-3/pos/1.3.kt | 36 +++++++++ .../indexing-expressions/p-3/pos/1.4.kt | 35 ++++++++ .../indexing-expressions/p-3/pos/1.5.kt | 42 ++++++++++ .../indexing-expressions/testsMap.json | 79 +++++++++++++++++++ .../BlackBoxCodegenTestSpecGenerated.java | 64 +++++++++++++++ 7 files changed, 308 insertions(+) create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.2.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.3.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.4.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.5.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/testsMap.json diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.1.kt new file mode 100644 index 00000000000..aef6d5cadf3 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.1.kt @@ -0,0 +1,27 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-220 + * PLACE: expressions, indexing-expressions -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: expressions, indexing-expressions -> paragraph 1 -> sentence 1 + * expressions, indexing-expressions -> paragraph 2 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope + */ + +class A1(val a: Int = 0) { + + operator fun get(x: Int): A1 { + return A1(x) + } +} + +fun box(): String { + val a = A1()[9] + val x = a[1][2][3][4] + if (x.a == 4 && a.a == 9) + return "OK" + return "NOK" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.2.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.2.kt new file mode 100644 index 00000000000..2253d6008c0 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.2.kt @@ -0,0 +1,25 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-220 + * PLACE: expressions, indexing-expressions -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: expressions, indexing-expressions -> paragraph 1 -> sentence 1 + * expressions, indexing-expressions -> paragraph 2 -> sentence 1 + * NUMBER: 2 + * DESCRIPTION: A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope + */ +class A1(val a: Int = 0) { + operator fun get(x: Any): Any { + return x + } +} + +fun box(): String { + val a = A1() + val x = a[a[a[a["qwsax"]]]] + if (x == "qwsax") + return "OK" + return "NOK" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.3.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.3.kt new file mode 100644 index 00000000000..79a9c0ab4b0 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.3.kt @@ -0,0 +1,36 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-220 + * PLACE: expressions, indexing-expressions -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: expressions, indexing-expressions -> paragraph 1 -> sentence 1 + * expressions, indexing-expressions -> paragraph 2 -> sentence 1 + * NUMBER: 3 + * DESCRIPTION: A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope + */ + + +class A1(val a: Int = 0) { + operator fun get(x: Any): Any { + return x + } +} + +class B() { + operator fun get(x: Any, y: Any, z: Any): Any { + return x + } +} + +fun box(): String { + val c = B()[A1(), 'c', false] + val a = A1() + val x = a[a[a[a[B()[A1(100500), 'c', false]]]]] + + x as A1 + if (x.a == 100500) + return "OK" + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.4.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.4.kt new file mode 100644 index 00000000000..8f702475025 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.4.kt @@ -0,0 +1,35 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-220 + * PLACE: expressions, indexing-expressions -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: expressions, indexing-expressions -> paragraph 1 -> sentence 1 + * expressions, indexing-expressions -> paragraph 2 -> sentence 1 + * NUMBER: 4 + * DESCRIPTION: A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope + */ + +class A1(val a: Int = 0) { + operator fun get(x: Any): Any { + return x + } +} + +class B() { + operator fun get(x: Any, y: Any, z: Any): Any { + return x + } +} + +fun box(): String { + val c = B()[A1(5555), 'c', false] + val a = A1(4444) + val x = a[a[a[a[B()[A1(100500)[c], 'c', false]]]]] + + x as A1 + if (x.a == 5555) + return "OK" + return "NOK" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.5.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.5.kt new file mode 100644 index 00000000000..3093af17ba6 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.5.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +NewInference +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-220 + * PLACE: expressions, indexing-expressions -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: expressions, indexing-expressions -> paragraph 1 -> sentence 1 + * expressions, indexing-expressions -> paragraph 2 -> sentence 1 + * NUMBER: 5 + * DESCRIPTION: A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope + */ + + +class A1(val a: Int = 0) { + operator fun get(x: Any): Any { + return x + } +} + +class B() { + operator fun get(x: Any, y: Any, z: Any): Any { + return x + } +} + +class C() { + operator fun get(function: () -> Any): Any { + return function() + } +} + +fun box() : String{ + val a = A1(4444) + val c = a [C()[{ 1 + 900 }]] + val x = a[a[a[a[B()[A1(100500)[ C()[{ 1 + 900 }] ], 'c', false]]]]] + + if (c == 901 && x == 901) + return "OK" + return "NOK" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/testsMap.json new file mode 100644 index 00000000000..33c258428c7 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/testsMap.json @@ -0,0 +1,79 @@ +{ + "3": { + "pos": { + "1": [ + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "unexpectedBehaviour": false + } + ] + } + }, + "1": { + "pos": { + "1": [ + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.2.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.3.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.4.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.5.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-220", + "casesNumber": 0, + "description": "A[I_0,I_1,...,I_N] is exactly the same as A.get(I_0,I_1,...,I_N), where get is a valid operator function available in the current scope", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java index e30f5fd28c7..2ac871c9383 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java @@ -1319,6 +1319,70 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Indexing_expressions extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInIndexing_expressions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_3 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_3() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.1.kt"); + } + + @TestMetadata("1.2.kt") + public void test1_2() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.2.kt"); + } + + @TestMetadata("1.3.kt") + public void test1_3() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.3.kt"); + } + + @TestMetadata("1.4.kt") + public void test1_4() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.4.kt"); + } + + @TestMetadata("1.5.kt") + public void test1_5() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos/1.5.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/indexing-expressions/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)