From e5a9a58d65bb7ff111dfb3fda003ce66bc0c9d9b Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Mon, 23 Dec 2019 15:57:09 +0300 Subject: [PATCH] [Spec tests] Add tests for prefix-expressions, unary-minus-expression and unary-minus-expression --- .../unary-minus-expression/p-2/pos/1.1.kt | 30 +++++++ .../unary-minus-expression/testsMap.json | 27 ++++++ .../unary-plus-expression/p-2/pos/1.1.kt | 30 +++++++ .../unary-plus-expression/testsMap.json | 27 ++++++ .../unary-minus-expression/p-3/pos/1.1.kt | 33 +++++++ .../unary-minus-expression/testsMap.json | 14 +++ .../unary-plus-expression/p-3/pos/1.1.kt | 33 +++++++ .../unary-plus-expression/testsMap.json | 14 +++ .../DiagnosticsTestSpecGenerated.java | 88 +++++++++++++++++++ .../BlackBoxCodegenTestSpecGenerated.java | 88 +++++++++++++++++++ 10 files changed, 384 insertions(+) create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/pos/1.1.kt new file mode 100644 index 00000000000..eb50a271030 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/pos/1.1.kt @@ -0,0 +1,30 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, prefix-expressions, unary-minus-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, prefix-expressions, unary-minus-expression -> paragraph 1 -> sentence 2 + * expressions, prefix-expressions, unary-minus-expression -> paragraph 1 -> sentence 1 + * expressions, prefix-expressions, unary-minus-expression -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: exactly the same as A.unaryMinus() where unaryMinus is a valid operator function available in the current scope. + */ + +class A(var a: Int) { + var isCalled = false + operator fun unaryMinus(): A { + isCalled = true + return A(a) + } +} + +fun box(): String { + val a = A(-1) + val a1 = -a + if (!a1.isCalled && a.isCalled) { + return "OK" + } + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json new file mode 100644 index 00000000000..0cc1c98b456 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json @@ -0,0 +1,27 @@ +{ + "2": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "exactly the same as A.unaryMinus() where unaryMinus is a valid operator function available in the current scope.", + "unexpectedBehaviour": false + } + ] + } + }, + "1": { + "pos": { + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "exactly the same as A.unaryMinus() where unaryMinus is a valid operator function available in the current scope.", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/pos/1.1.kt new file mode 100644 index 00000000000..8d61d21f707 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/pos/1.1.kt @@ -0,0 +1,30 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, prefix-expressions, unary-plus-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, prefix-expressions, unary-plus-expression -> paragraph 1 -> sentence 1 + * expressions, prefix-expressions, unary-plus-expression -> paragraph 1 -> sentence 2 + * expressions, prefix-expressions, unary-plus-expression -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: +A is exactly the same as A.unaryPlus() where unaryMinus is a valid operator function available in the current scope. + */ + +class A(var a: Int) { + var isCalled = false + operator fun unaryPlus(): A { + isCalled = true + return A(a) + } +} + +fun box(): String { + val a = A(-1) + val a1 = +a + if (!a1.isCalled && a.isCalled) { + return "OK" + } + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json new file mode 100644 index 00000000000..96d9beafeee --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json @@ -0,0 +1,27 @@ +{ + "2": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "+A is exactly the same as A.unaryPlus() where unaryMinus is a valid operator function available in the current scope.", + "unexpectedBehaviour": false + } + ] + } + }, + "1": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "+A is exactly the same as A.unaryPlus() where unaryMinus is a valid operator function available in the current scope.", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos/1.1.kt new file mode 100644 index 00000000000..eb188cd16ea --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos/1.1.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, prefix-expressions, unary-minus-expression -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: No additional restrictions apply for unary minus + * HELPERS: checkType + */ + + +// TESTCASE NUMBER: 1 +class Case1(var a: Int) { + operator fun unaryMinus(): Nothing? { TODO() } +} + +fun case1() { + val a = -Case1(1) +} + +// TESTCASE NUMBER: 2 +class Case2(var a: Int) { + operator fun unaryMinus(): Any? { TODO() } +} + +fun case2() { + val a = -Case2(1) +} + diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json new file mode 100644 index 00000000000..5152cde8563 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/testsMap.json @@ -0,0 +1,14 @@ +{ + "3": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 2, + "description": "No additional restrictions apply for unary minus", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos/1.1.kt new file mode 100644 index 00000000000..f59d4c726a5 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos/1.1.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, prefix-expressions, unary-plus-expression -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: No additional restrictions apply for unary plus + * HELPERS: checkType + */ + + +// TESTCASE NUMBER: 1 +class Case1(var a: Int) { + operator fun unaryPlus(): Nothing? { TODO() } +} + +fun case1() { + val a = +Case1(1) +} + +// TESTCASE NUMBER: 2 +class Case2(var a: Int) { + operator fun unaryPlus(): Any? { TODO() } +} + +fun case2() { + val a = +Case2(1) +} + diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json new file mode 100644 index 00000000000..b80f5f3d845 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/testsMap.json @@ -0,0 +1,14 @@ +{ + "3": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 2, + "description": "No additional restrictions apply for unary plus", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java index ab6ac178575..7af7e9dda77 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java @@ -2153,6 +2153,94 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unary_minus_expression extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnary_minus_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_3 extends AbstractDiagnosticsTestSpec { + 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/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractDiagnosticsTestSpec { + 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/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-minus-expression/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unary_plus_expression extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnary_plus_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_3 extends AbstractDiagnosticsTestSpec { + 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/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractDiagnosticsTestSpec { + 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/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions/unary-plus-expression/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } } @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression") 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 fdb61d67d7c..8ad8cb7b303 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 @@ -1796,6 +1796,94 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unary_minus_expression extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnary_minus_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_2 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_2() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/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/prefix-expressions/unary-minus-expression/p-2/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-minus-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unary_plus_expression extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnary_plus_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_2 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_2() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/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/prefix-expressions/unary-plus-expression/p-2/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/prefix-expressions/unary-plus-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } } @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression")