[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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user