[Spec tests] Add tests for not-null-assertion-expression
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-220
|
||||
* PLACE: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.
|
||||
*/
|
||||
|
||||
|
||||
// MODULE: libModule
|
||||
// FILE: libModule/JavaClass.java
|
||||
package libModule;
|
||||
|
||||
public class JavaClass {
|
||||
public static Boolean FALSE;
|
||||
}
|
||||
|
||||
|
||||
// MODULE: mainModule(libModule)
|
||||
// FILE: KotlinClass.kt
|
||||
package mainModule
|
||||
import libModule.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val x = JavaClass.FALSE!!
|
||||
}catch (e: java.lang.NullPointerException){
|
||||
return "OK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-220
|
||||
* PLACE: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 2
|
||||
* RELEVANT PLACES: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.
|
||||
*/
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val x = A(A(A(A())))
|
||||
if ( x.a!!.a!!.a!!.a == null)
|
||||
{
|
||||
try {
|
||||
val t = x.a!!.a!!.a!!.a!!
|
||||
}catch (e: java.lang.NullPointerException){
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
|
||||
class A ( val a: A? = null)
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-220
|
||||
* PLACE: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 3
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: If the evaluation result of e is not equal to null, the result of e!! is the evaluation result of e.
|
||||
*/
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val x: String? = "str"
|
||||
try {
|
||||
val y = x!!
|
||||
}catch (e: java.lang.NullPointerException){
|
||||
return "NOK"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"2": {
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-220",
|
||||
"casesNumber": 0,
|
||||
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-220",
|
||||
"casesNumber": 0,
|
||||
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-220",
|
||||
"casesNumber": 0,
|
||||
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/2.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-220",
|
||||
"casesNumber": 0,
|
||||
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/2.2.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-220",
|
||||
"casesNumber": 0,
|
||||
"description": "If the evaluation result of e is not equal to null, the result of e!! is the evaluation result of e.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user