[Spec tests] Add tests for logical-conjunction-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-19 17:42:43 +03:00
parent 6da8ccb9eb
commit 15b561195f
10 changed files with 439 additions and 6 deletions
@@ -0,0 +1,39 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false.
*/
fun box(): String {
val aval = A()
val x = aval.a(true) &&
aval.b(true) &&
aval.c(false) &&
aval.d(false)
if (aval.a && aval.b && aval.c && !aval.d && !x)
return "OK"
return "NOK"
}
class A (var a: Boolean = false,
var b: Boolean = false,
var c: Boolean = false,
var d: Boolean = false){
fun a(a: Boolean): Boolean { this.a = true; return a }
fun b(a: Boolean): Boolean { this.b = true; return a }
fun c(a: Boolean): Boolean { this.c = true; return a }
fun d(a: Boolean): Boolean { this.d = true; return a }
}
@@ -0,0 +1,25 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1
* NUMBER: 2
* DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false.
*/
fun box(): String {
val x: Boolean
try {
x = true && true && false && throw MyException()
} catch (e: MyException) {
return "NOK"
}
if (x)
return "NOK"
return "OK"
}
class MyException : Exception() {}
@@ -0,0 +1,24 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1
* NUMBER: 3
* DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false.
*/
fun box(): String {
val x: Boolean = false
try {
x = (throw MyException()) && true
} catch (e: MyException) {
if (!x)
return "OK"
}
return "NOK"
}
class MyException : Exception() {}
@@ -0,0 +1,49 @@
{
"1": {
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"unexpectedBehaviour": false
}
],
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt",
"unexpectedBehaviour": false
}
]
}
}
}