From 3bb5ddb22444a74df69cec8836b4cb405813d63a Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Thu, 19 Dec 2019 18:33:28 +0300 Subject: [PATCH] [Spec tests] Add tests for reference-equality-expressions (paragraph 3) --- .../p-3/pos/1.1.kt | 24 ++++++ .../p-3/pos/2.1.kt | 36 +++++++++ .../testsMap.json | 73 +++++++++++++++++++ .../DiagnosticsTestSpecGenerated.java | 4 +- .../BlackBoxCodegenTestSpecGenerated.java | 40 +++++++++- 5 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/2.1.kt create mode 100644 compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/testsMap.json diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/1.1.kt new file mode 100644 index 00000000000..1f3edce91ea --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/1.1.kt @@ -0,0 +1,24 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: If these values are non-equal by value, they are also non-equal by reference; + */ + +fun box(): String { + val a1 = A(false) + val a2 = A(true) + + if (!a1.equals( a2)) { + if (a1 !== a2) + return "OK" + else throw Exception() + } + return "NOK" +} + +data class A(val a: Boolean) diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/2.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/2.1.kt new file mode 100644 index 00000000000..b87143d3097 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/2.1.kt @@ -0,0 +1,36 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 3 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: Any instance of the null reference null is equal by reference to any other instance of the null reference; + */ + +// FILE: JavaClass.java +public class JavaClass{ + public static Object NULL_VALUE ; +} + +// FILE: KotlinClass.kt +fun box(): String { + + var flag1 = false + if (null === JavaClass.NULL_VALUE) { + if (JavaClass.NULL_VALUE === null) + flag1 = true + } + + var flag2 = false + val x = null + if (null === x) { + if (x === null) + flag2 = true + } + + if (flag1 && flag2) return "OK" + else + return "NOK" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/testsMap.json new file mode 100644 index 00000000000..d06a9e70be6 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/testsMap.json @@ -0,0 +1,73 @@ +{ + "1": { + "pos": { + "2": [ + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "check if two values are equal (\u003d\u003d\u003d) by reference", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "two values are equal (\u003d\u003d\u003d) or non-equal (!\u003d\u003d) by reference", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "check if values are non-equal (!\u003d\u003d) by reference", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "check if two values are non-equal (!\u003d\u003d) by reference", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "check if two values are equal (\u003d\u003d\u003d) by reference", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "todo", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/built-in-types-and-their-semantics/kotlin.unit/p-1/pos/1.1.kt", + "unexpectedBehaviour": false + } + ], + "3": [ + { + "specVersion": "0.1-213", + "casesNumber": 0, + "description": "check equallity by refference via constructor", + "unexpectedBehaviour": false + } + ] + } + }, + "3": { + "pos": { + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "Any instance of the null reference null is equal by reference to any other instance of the null reference;", + "unexpectedBehaviour": false + } + ], + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "If these values are non-equal by value, they are also non-equal by reference;", + "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 00b09cd25d6..0e1416be1a1 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 @@ -25,7 +25,7 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } public void testAllFilesPresentInDiagnostics() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), true, "helpers", "linked/type-inference", "linked/expressions.when-expression", "linked/type-system/type-kinds/type-parameters", "linked/type-system/subtyping", "linked/control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "linked/declarations/classifier-declaration/classifier-initialization", "linked/declarations/function-declaration", "linked/declarations/property-declaration/property-initialization", "linked/annotations", "linked/statements", "linked/inheritance", "linked/expressions.conditional-expression", "linked/expressions/function-literals", "linked/expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "linked/overload-resolution", "linked/control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), true, "helpers", "linked/type-inference", "linked/type-system/type-kinds/type-parameters", "linked/type-system/subtyping", "linked/control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "linked/declarations/classifier-declaration/classifier-initialization", "linked/declarations/function-declaration", "linked/declarations/property-declaration/property-initialization", "linked/annotations", "linked/statements", "linked/inheritance", "linked/expressions/function-literals", "linked/expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "linked/overload-resolution", "linked/control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); } @TestMetadata("compiler/tests-spec/testData/diagnostics/linked") @@ -37,7 +37,7 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } public void testAllFilesPresentInLinked() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked"), Pattern.compile("^(.+)\\.kt$"), true, "type-inference", "expressions.when-expression", "type-system/type-kinds/type-parameters", "type-system/subtyping", "control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "declarations/classifier-declaration/classifier-initialization", "declarations/function-declaration", "declarations/property-declaration/property-initialization", "annotations", "statements", "inheritance", "expressions.conditional-expression", "expressions/function-literals", "expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "overload-resolution", "control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked"), Pattern.compile("^(.+)\\.kt$"), true, "type-inference", "type-system/type-kinds/type-parameters", "type-system/subtyping", "control--and-data-flow-analysis.control-flow-graph.expressions-1.conditional-expressions", "declarations/classifier-declaration/classifier-initialization", "declarations/function-declaration", "declarations/property-declaration/property-initialization", "annotations", "statements", "inheritance", "expressions/function-literals", "expressions/built-in-types-and-their-semantics/kotlin.nothing-1/p-1/neg", "overload-resolution", "control--and-data-flow-analysis/performing-analysis-on-the-control-flow-graph"); } @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis") 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 b0e0c6e7679..c0fa740ab86 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 @@ -25,7 +25,7 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } public void testAllFilesPresentInBox() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), true, "helpers", "templates", "linked/expressions.when-expression", "linked/declarations", "linked/statements", "linked/expressions.conditional-expression", "linked/expressions/equality-expressions/reference-equality-expressions/p-1/neg", "linked/expressions/built-in-types-and-their-semantics/kotlin.unit/p-1/neg", "linked/expressions/prefix-expressions/prefix-increment-expression/p-1/neg"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), true, "helpers", "templates", "linked/declarations", "linked/statements", "linked/expressions/equality-expressions/reference-equality-expressions/p-1/neg", "linked/expressions/built-in-types-and-their-semantics/kotlin.unit/p-1/neg", "linked/expressions/prefix-expressions/prefix-increment-expression/p-1/neg"); } @TestMetadata("compiler/tests-spec/testData/codegen/box/linked") @@ -37,7 +37,7 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } public void testAllFilesPresentInLinked() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked"), Pattern.compile("^(.+)\\.kt$"), true, "expressions.when-expression", "declarations", "statements", "expressions.conditional-expression", "expressions/equality-expressions/reference-equality-expressions/p-1/neg", "expressions/built-in-types-and-their-semantics/kotlin.unit/p-1/neg", "expressions/prefix-expressions/prefix-increment-expression/p-1/neg"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked"), Pattern.compile("^(.+)\\.kt$"), true, "declarations", "statements", "expressions/equality-expressions/reference-equality-expressions/p-1/neg", "expressions/built-in-types-and-their-semantics/kotlin.unit/p-1/neg", "expressions/prefix-expressions/prefix-increment-expression/p-1/neg"); } @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions") @@ -1048,6 +1048,42 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-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/equality-expressions/reference-equality-expressions/p-3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-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/equality-expressions/reference-equality-expressions/p-3/pos/1.1.kt"); + } + + @TestMetadata("2.1.kt") + public void test2_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos/2.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } } }