[Spec tests] Add tests for elvis-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-23 12:41:17 +03:00
parent 479fa0e7b8
commit 84cf4c5049
6 changed files with 200 additions and 0 deletions
@@ -0,0 +1,43 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, elvis-operator-expression -> paragraph 3 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of elvis operator expression is the least upper bound of the non-nullable variant of the type of the left-hand side expression and the type of the right-hand side expression.
* HELPERS: checkType
*/
// TESTCASE NUMBER: 1
fun case1() {
val x = null ?: getNull()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean?")!>x<!>
}
fun getNull(): Boolean? = null
// TESTCASE NUMBER: 2
fun case2() {
val x = A(mutableSetOf({ false }, { println("") })).b ?: false
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x<!>
}
class A(val b: Set<Any>? = null)
// TESTCASE NUMBER: 3
fun case3() {
val x = null?: throw Exception()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>x<!>
}
// TESTCASE NUMBER: 4
fun case4() {
val x = null <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>
<!DEBUG_INFO_CONSTANT, DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?")!>x<!>
}
@@ -0,0 +1,14 @@
{
"3": {
"pos": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 4,
"description": "The type of elvis operator expression is the least upper bound of the non-nullable variant of the type of the left-hand side expression and the type of the right-hand side expression.",
"unexpectedBehaviour": false
}
]
}
}
}