From 84cf4c5049a3ca76123c9b68519ca26c3a3f1347 Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Mon, 23 Dec 2019 12:41:17 +0300 Subject: [PATCH] [Spec tests] Add tests for elvis-expression --- .../elvis-operator-expression/p-1/pos/2.1.kt | 32 ++++++++++++++ .../elvis-operator-expression/testsMap.json | 23 ++++++++++ .../elvis-operator-expression/p-3/pos/1.1.kt | 43 ++++++++++++++++++ .../elvis-operator-expression/testsMap.json | 14 ++++++ .../DiagnosticsTestSpecGenerated.java | 44 +++++++++++++++++++ .../BlackBoxCodegenTestSpecGenerated.java | 44 +++++++++++++++++++ 6 files changed, 200 insertions(+) create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos/2.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/testsMap.json create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/p-3/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/testsMap.json diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos/2.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos/2.1.kt new file mode 100644 index 00000000000..e5a3e4892b0 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos/2.1.kt @@ -0,0 +1,32 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, elvis-operator-expression -> paragraph 1 -> sentence 2 + * RELEVANT PLACES: expressions, elvis-operator-expression -> paragraph 1 -> sentence 1 + * expressions, elvis-operator-expression -> paragraph 2 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: Check Elvis evaluation + */ + + +fun box(): String { + val x : Boolean? = null ?: getNull() ?: A().b ?: getTrue() ?: false + try { + val y = null ?: throw ExcA() + } catch (e: ExcA) { + + if (x == true) return "OK" + } + + return "NOK" +} +fun getTrue() = true + +fun getNull(): Boolean? = null + +class A(val b: Boolean? = null) + +class ExcA() : Exception() \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/testsMap.json new file mode 100644 index 00000000000..5967c0e923b --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/testsMap.json @@ -0,0 +1,23 @@ +{ + "1": { + "pos": { + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "Check Elvis evaluation", + "unexpectedBehaviour": false + } + ], + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "Check Elvis evaluation", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos/2.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/p-3/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/p-3/pos/1.1.kt new file mode 100644 index 00000000000..be997178bee --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/p-3/pos/1.1.kt @@ -0,0 +1,43 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNREACHABLE_CODE -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, elvis-operator-expression -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: The type of elvis operator expression is the least upper bound of the non-nullable variant of the type of the left-hand side expression and the type of the right-hand side expression. + * HELPERS: checkType + */ + + +// TESTCASE NUMBER: 1 +fun case1() { + val x = null ?: getNull() + x +} + +fun getNull(): Boolean? = null + + +// TESTCASE NUMBER: 2 +fun case2() { + val x = A(mutableSetOf({ false }, { println("") })).b ?: false + x +} + +class A(val b: Set? = null) + +// TESTCASE NUMBER: 3 +fun case3() { + val x = null?: throw Exception() + x +} + +// TESTCASE NUMBER: 4 +fun case4() { + val x = null ?: null + x +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/testsMap.json new file mode 100644 index 00000000000..91b0d869bc0 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression/testsMap.json @@ -0,0 +1,14 @@ +{ + "3": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 4, + "description": "The type of elvis operator expression is the least upper bound of the non-nullable variant of the type of the left-hand side expression and the type of the right-hand side expression.", + "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 bb79caede5c..b84962add91 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 @@ -1591,6 +1591,50 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Elvis_operator_expression extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInElvis_operator_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-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/elvis-operator-expression/p-3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/elvis-operator-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/elvis-operator-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/elvis-operator-expression/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) 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 440045cdede..d0010b731be 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 @@ -1046,6 +1046,50 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Elvis_operator_expression extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInElvis_operator_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_1 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_1() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/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("2.1.kt") + public void test2_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos/2.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/elvis-operator-expression/p-1/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)