From 5e42a2057531d84c854bb69ae9eddf8e45d61baa Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Thu, 19 Dec 2019 19:48:34 +0300 Subject: [PATCH] [Spec tests] Add tests for value-equality-expressions (paragraph 2-3) --- .../value-equality-expressions/p-2/neg/1.1.kt | 41 ++++++++++++ .../value-equality-expressions/p-2/pos/1.1.kt | 41 ++++++++++++ .../value-equality-expressions/testsMap.json | 37 +++++++++++ .../value-equality-expressions/p-3/pos/1.1.kt | 34 ++++++++++ .../value-equality-expressions/testsMap.json | 27 ++++++++ .../DiagnosticsTestSpecGenerated.java | 57 +++++++++++++++++ .../BlackBoxCodegenTestSpecGenerated.java | 62 +++++++++++++++++++ 7 files changed, 299 insertions(+) create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/neg/1.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/p-3/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/neg/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/neg/1.1.kt new file mode 100644 index 00000000000..357724b649d --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/neg/1.1.kt @@ -0,0 +1,41 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: check value-equality-expression + */ + + +//A != B is exactly the same as !((A as? Any)?.equals(B) ?: (B === null)) where equals is the method of kotlin.Any. + +fun box():String{ + val x = A(true) + val y = A(false) + + if (x != y) { + if (x.isEqualsCalled && !y.isEqualsCalled) + return "OK" + } + return "NOK" +} + + +data class A(val a: Boolean) { + var isEqualsCalled = false + + override fun equals(anObject: Any?): Boolean { + isEqualsCalled = true + if (this === anObject) { + return true + } + if (anObject is A) { + if (anObject.a == a) + return true + } + return false + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.1.kt new file mode 100644 index 00000000000..447211755aa --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.1.kt @@ -0,0 +1,41 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, equality-expressions, value-equality-expressions -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: check value-equality-expression + */ + + +//A == B is exactly the same as (A as? Any)?.equals(B) ?: (B === null) where equals is the method of kotlin.Any; +fun box(): String { + val x = A(false) + val y = A(false) + + if (x == y) { + if (x.isEqualsCalled && !y.isEqualsCalled) + return "OK" + } + return "NOK" +} + + +data class A(val a: Boolean) { + var isEqualsCalled = false + + override fun equals(anObject: Any?): Boolean { + isEqualsCalled = true + if (this === anObject) { + return true + } + if (anObject is A) { + if (anObject.a == a) + return true + } + return false + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json new file mode 100644 index 00000000000..6a927a6c929 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json @@ -0,0 +1,37 @@ +{ + "2": { + "neg": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "check value-equality-expression", + "unexpectedBehaviour": false + } + ] + }, + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "check value-equality-expression", + "unexpectedBehaviour": false + } + ] + } + }, + "3": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "check value-equality-expression", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/p-3/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/p-3/pos/1.1.kt new file mode 100644 index 00000000000..d85a40d0abe --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/p-3/pos/1.1.kt @@ -0,0 +1,34 @@ +// !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, equality-expressions, value-equality-expressions -> paragraph 3 -> sentence 1 + * RELEVANT PLACES: expressions, equality-expressions, value-equality-expressions -> paragraph 1 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: Value equality expressions always have type kotlin.Boolean as does the equals method in kotlin.Any + * HELPERS: checkType + */ +data class A(val a: Boolean) + + +// TESTCASE NUMBER: 1 +fun case1() { + val x = A(false) == A(true) + x checkType { check() } +} + +// TESTCASE NUMBER: 2 +fun case2() { + val x = A(false) == A(false) + x checkType { check() } +} + +// TESTCASE NUMBER: 3 +fun case3() { + val x = true == false + x checkType { check() } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json new file mode 100644 index 00000000000..e0dd0bc5fb0 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/testsMap.json @@ -0,0 +1,27 @@ +{ + "3": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 3, + "description": "Value equality expressions always have type kotlin.Boolean as does the equals method in kotlin.Any", + "unexpectedBehaviour": false + } + ] + } + }, + "1": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 3, + "description": "Value equality expressions always have type kotlin.Boolean as does the equals method in kotlin.Any", + "path": "compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-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/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java index 0e1416be1a1..617eee5b5f7 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 @@ -1516,6 +1516,63 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Equality_expressions extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInEquality_expressions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Value_equality_expressions extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInValue_equality_expressions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/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/equality-expressions/value-equality-expressions/p-3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/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/equality-expressions/value-equality-expressions/p-3/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/equality-expressions/value-equality-expressions/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/jump-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 c0fa740ab86..68fb9c8d049 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 @@ -1085,6 +1085,68 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Value_equality_expressions extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInValue_equality_expressions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/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/equality-expressions/value-equality-expressions/p-2"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/neg") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Neg 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/equality-expressions/value-equality-expressions/p-2/neg/1.1.kt"); + } + + public void testAllFilesPresentInNeg() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/neg"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/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/equality-expressions/value-equality-expressions/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/equality-expressions/value-equality-expressions/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } } @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression")