[Spec tests] Add tests for value-equality-expressions (paragraph 2-3)
This commit is contained in:
+41
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
+41
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -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<Boolean>() }
|
||||||
|
}
|
||||||
|
|
||||||
|
// TESTCASE NUMBER: 2
|
||||||
|
fun case2() {
|
||||||
|
val x = A(false) == A(false)
|
||||||
|
x checkType { check<Boolean>() }
|
||||||
|
}
|
||||||
|
|
||||||
|
// TESTCASE NUMBER: 3
|
||||||
|
fun case3() {
|
||||||
|
val x = true == false
|
||||||
|
x checkType { check<Boolean>() }
|
||||||
|
}
|
||||||
+27
@@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+57
@@ -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")
|
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/jump-expressions")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Generated
+62
@@ -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")
|
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression")
|
||||||
|
|||||||
Reference in New Issue
Block a user