[Spec tests] Add fixed tests for expressions section, fix linkage for reference-equality-expressions section

This commit is contained in:
anastasiia.spaseeva
2019-12-26 15:11:29 +03:00
parent 9e3ecbd902
commit e0743f2268
42 changed files with 1162 additions and 106 deletions
@@ -0,0 +1,20 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 5
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box() : String{
if (get(null)?: if (get(false)!!) false else get(true)!!)
return "OK"
return "NOK"
}
fun get(b: Boolean?): Boolean? = b
@@ -0,0 +1,19 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 6
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box() : String{
if (get(null)?: if (get(true)!!) false else get(true)!!)
return "NOK"
return "OK"
}
fun get(b: Boolean?): Boolean? = b
@@ -0,0 +1,25 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 7
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box(): String {
val x = if (get(null) ?: if (try {
TODO()
} catch (e: NotImplementedError) {
get(false)!!
}
) false else get(true)!!
) get(true) else false
if (x!!) return "OK"
return "NOK"
}
fun get(b: Boolean?): Boolean? = b
@@ -0,0 +1,31 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 8
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box(): String {
var x = 10
var flag1 = false
if (x == 10.also { x = 11 }) {
flag1 = true
}
var flag2 = false
if (x == if (true) {x = 12; 11} else 11) {
flag2 = true
}
var flag3 = false
if (12.also { x = 13 } == x) {
flag3 = true
}
if (flag1 && flag2 && !flag3)
return "OK"
return "NOK"
}
@@ -6,10 +6,32 @@
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 2 -> sentence 1
* NUMBER: 1
* DESCRIPTION:
* DESCRIPTION: branchless conditional expression, despite being of almost no practical use, is valid in Kotlin
*/
fun box(): String {
if (true) else;
if (true) else; ;
if (true) else ;
if (true)
else;
if (true) else
;
val x = {
if (true) else;
}
if (false) else;
if (false) else; ;
if (false) else ;
if (false)
else;
if (false) else
;
val x1 = {
if (false) else;
}
return "OK"
}
@@ -0,0 +1,36 @@
// !LANGUAGE: +NewInference
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, conditional-expression -> paragraph 6 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error
*/
// FILE: JavaClass.java
public class JavaClass{
public static <T> T id(T x) {
return null;
}
}
// FILE: KotlinClass.kt
import java.lang.IllegalStateException
fun box(): String {
val x = JavaClass.id(null) // Nothing!
return try {
val a = if (x) {
"NOK"
} else "NOK"
a
} catch (e: java.lang.IllegalStateException) {
"OK"
}
}
@@ -0,0 +1,28 @@
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, conditional-expression -> paragraph 6 -> sentence 1
* NUMBER: 2
* DESCRIPTION: The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error
*/
// FILE: JavaClass.java
public class JavaClass{
public Boolean x;
}
// FILE: KotlinClass.kt
import java.lang.IllegalStateException
fun box(): String {
return try {
val a = if (JavaClass().x) { "NOK" } else "NOK"
a
} catch (e: java.lang.IllegalStateException) {
"OK"
}
}
@@ -1,7 +1,49 @@
{
"6": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error",
"unexpectedBehaviour": false
}
]
}
},
"1": {
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
@@ -48,7 +90,7 @@
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "",
"description": "branchless conditional expression, despite being of almost no practical use, is valid in Kotlin",
"unexpectedBehaviour": false
}
]