[Spec tests] Add tests for value-equality-expressions (paragraph 2-3)

This commit is contained in:
anastasiia.spaseeva
2019-12-19 19:48:34 +03:00
parent 3bb5ddb224
commit 5e42a20575
7 changed files with 299 additions and 0 deletions
@@ -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
}
}
@@ -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
}
}
@@ -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
}
]
}
}
}