[Spec tests] Add tests for expressions and statements

This commit is contained in:
anastasiia.spaseeva
2020-01-10 17:00:43 +03:00
committed by Victor Petukhov
parent 5f4a94a1b3
commit 5986ffae1e
108 changed files with 4221 additions and 26 deletions
@@ -8,6 +8,7 @@
* SPEC VERSION: 0.1-218
* PLACE: expressions, additive-expression -> paragraph 4 -> sentence 1
* RELEVANT PLACES: expressions, additive-expression -> paragraph 4 -> sentence 2
* overloadable-operators -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The return type of these functions is not restricted.
* HELPERS: checkType
@@ -1,24 +1,4 @@
{
"3": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "Class vs package",
"path": "compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "Bare type",
"path": "compiler/testData/diagnostics/tests/callableReference/bareType.kt",
"unexpectedBehaviour": false
}
]
}
},
"11": {
"pos": {
"3": [
@@ -31,5 +11,18 @@
}
]
}
},
"3": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "Bare type",
"path": "compiler/testData/diagnostics/tests/callableReference/bareType.kt",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,28 @@
{
"9": {
"pos": {
"2": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "Correct info after array like call",
"path": "compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt",
"unexpectedBehaviour": false
}
]
}
},
"8": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "Correct info after array like call",
"path": "compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -7,6 +7,7 @@
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: overloadable-operators -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: <, >, <= and >= operators are overloadable
*/
@@ -7,6 +7,7 @@
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 4 -> sentence 1
* RELEVANT PLACES: overloadable-operators -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The compareTo operator function must have return type kotlin.Int
*/
@@ -7,6 +7,7 @@
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 5 -> sentence 1
* RELEVANT PLACES: overloadable-operators -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: All comparison expressions always have type kotlin.Boolean.
* HELPERS: checkType
@@ -0,0 +1,38 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-222
* PLACE: expressions, jump-expressions, break-expression -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: A break expression is a jump expression allowed only within loop bodies.
*/
// TESTCASE NUMBER: 1
fun case1() {
val inputList = listOf(1, 2, 3)
inputList.forEach {
listOf("1.", "2.", "3.").forEach {
if (true) <!NOT_A_LOOP_LABEL!>break<!LABEL_NAME_CLASH!>@forEach<!><!>
}
}
}
// TESTCASE NUMBER: 2
fun case2() {
val inputList = listOf(1, 2, 3)
inputList.forEach {
listOf("1.", "2.", "3.").forEach {
if (true) <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>
}
}
}
// TESTCASE NUMBER: 3
fun case3() {
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>
}
@@ -0,0 +1,14 @@
{
"1": {
"neg": {
"1": [
{
"specVersion": "0.1-222",
"casesNumber": 3,
"description": "A break expression is a jump expression allowed only within loop bodies.",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,38 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-222
* PLACE: expressions, jump-expressions, continue-expression -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: A continue expression is a jump expression allowed only within loop bodies.
*/
// TESTCASE NUMBER: 1
fun case1() {
val inputList = listOf(1, 2, 3)
inputList.forEach {
listOf("1.", "2.", "3.").forEach {
if (true) <!NOT_A_LOOP_LABEL!>continue<!LABEL_NAME_CLASH!>@forEach<!><!>
}
}
}
// TESTCASE NUMBER: 2
fun case2() {
val inputList = listOf(1, 2, 3)
inputList.forEach {
listOf("1.", "2.", "3.").forEach {
if (true) <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>
}
}
}
// TESTCASE NUMBER: 3
fun case3() {
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>
}
@@ -0,0 +1,14 @@
{
"1": {
"neg": {
"1": [
{
"specVersion": "0.1-222",
"casesNumber": 3,
"description": "A continue expression is a jump expression allowed only within loop bodies.",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,63 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-222
* PLACE: expressions, jump-expressions, return-expressions -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION:
* HELPERS: checkType
*/
// TESTCASE NUMBER: 1
fun case1() {
val x = fooCase1()
x checkType { check<Case1>() }
}
class Case1
fun fooCase1(): Case1 = TODO()
// TESTCASE NUMBER: 2
fun case2() {
val x = fooCase2()
x checkType { check<Case1>() }
}
fun fooCase2(): Case1 {
val x = ""
return Case1()
<!UNREACHABLE_CODE!>val y = ""<!>
}
// TESTCASE NUMBER: 3
fun case3() {
val x = object : Case13 {
override fun fooCase3(): Int {
return 1
<!UNREACHABLE_CODE!>"str"<!>
<!UNREACHABLE_CODE!>3<!>
}
}.fooCase3()
x checkType { check<Int>() }
}
interface Case13 {
fun fooCase3(): Int
}
// TESTCASE NUMBER: 4
fun case4() {
val x = fooCase4()
x checkType { check<kotlin.Unit>() }
}
fun fooCase4() {
return
}
@@ -1,4 +1,16 @@
{
"1": {
"pos": {
"1": [
{
"specVersion": "0.1-222",
"casesNumber": 4,
"description": "",
"unexpectedBehaviour": false
}
]
}
},
"5": {
"neg": {
"2": [
@@ -10,6 +10,7 @@
* DESCRIPTION: Non-exhaustive when using nullable boolean values.
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Boolean?): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
true -> ""