[Spec tests] Add codegen tests for logical-disjunction-expression (paragraph 1)

This commit is contained in:
anastasiia.spaseeva
2019-12-19 13:49:17 +03:00
parent 1ea5eb6850
commit 31df799103
5 changed files with 195 additions and 3 deletions
@@ -0,0 +1,38 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-disjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-disjunction-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(false) ||
aval.b(false) ||
aval.c(true) ||
aval.d(true)
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,27 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-disjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-disjunction-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 = false || false || true || throw MyException()
} catch (e: MyException) {
return "NOK"
}
if (x)
return "OK"
return "NOK"
}
class MyException : Exception() {}
@@ -0,0 +1,24 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-disjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-disjunction-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 || 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 || 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 || 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 || 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-disjunction-expression/p-1/pos/2.1.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator || 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-disjunction-expression/p-1/pos/2.3.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator || 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-disjunction-expression/p-1/pos/2.2.kt",
"unexpectedBehaviour": false
}
]
}
}
}