[Spec tests] Add tests for containment-checking-expression
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 2 -> sentence 1
|
||||
* RELEVANT PLACES: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 2
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 1
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 3 -> sentence 1
|
||||
*
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: A in B is exactly the same as B.contains(A);
|
||||
*/
|
||||
|
||||
class A(val a: Set<Any>) {
|
||||
var isEvaluated: Boolean = false
|
||||
var isChecked = false
|
||||
operator fun contains(other: Any): Boolean = run {
|
||||
isChecked = true
|
||||
this.a.contains(other)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b= A(mutableSetOf(1, 3, false, 2 , "azaza"))
|
||||
|
||||
if (3 in b)
|
||||
if (b.isChecked )
|
||||
return "OK"
|
||||
return "NOK"
|
||||
|
||||
return "NOK"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 2 -> sentence 1
|
||||
* RELEVANT PLACES: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 2
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 1
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 3 -> sentence 1
|
||||
*
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: A in B is exactly the same as B.contains(A);
|
||||
*/
|
||||
|
||||
class A(val a: Set<Any>) {
|
||||
var isEvaluated: Boolean = false
|
||||
var isChecked = false
|
||||
operator fun contains(other: Any): Boolean = run {
|
||||
isChecked = true
|
||||
this.a.contains(other)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b= A(mutableSetOf(1, 3, false, 2 , "azaza"))
|
||||
|
||||
if (true !in b)
|
||||
if (b.isChecked )
|
||||
return "OK"
|
||||
return "NOK"
|
||||
|
||||
return "NOK"
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 4 -> sentence 1
|
||||
* RELEVANT PLACES: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 2
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 1
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 3 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: A in B is exactly the same as B.contains(A);
|
||||
*/
|
||||
|
||||
class A(val a: Set<Any>) {
|
||||
var isEvaluated: Boolean = false
|
||||
var isChecked = false
|
||||
operator fun contains(other: Any): Boolean = run {
|
||||
isChecked = true
|
||||
this.a.contains(other)
|
||||
}
|
||||
|
||||
fun foo(): A {
|
||||
this.isEvaluated = true
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
fun throwException(b: Boolean): Boolean {
|
||||
if (b) throw Exception()
|
||||
else return false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = A(mutableSetOf(1, 3, false, 2, "azaza"))
|
||||
try {
|
||||
val k = (throwException(true) in b.foo())
|
||||
} catch (e: Exception) {
|
||||
if (!b.isChecked && b.isEvaluated)
|
||||
return "OK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 4 -> sentence 1
|
||||
* RELEVANT PLACES: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 2
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 1 -> sentence 1
|
||||
* expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 3 -> sentence 1
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: A in B is exactly the same as B.contains(A);
|
||||
*/
|
||||
|
||||
class A(val a: Set<Any>) {
|
||||
var isEvaluated: Boolean = false
|
||||
var isChecked = false
|
||||
operator fun contains(other: Any): Boolean = run {
|
||||
isChecked = true
|
||||
this.a.contains(other)
|
||||
}
|
||||
|
||||
fun foo(): A {
|
||||
this.isEvaluated = true
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
fun throwException(b: Boolean): Boolean {
|
||||
if (b) throw Exception()
|
||||
else return false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = A(mutableSetOf(1, 3, false, 2, "azaza"))
|
||||
try {
|
||||
val k = (throwException(true) !in b.foo())
|
||||
} catch (e: Exception) {
|
||||
if (!b.isChecked && b.isEvaluated)
|
||||
return "OK"
|
||||
}
|
||||
return "NOK"
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
java.lang.IllegalStateException: INAPPLICABLE_OPERATOR_MODIFIER: 'operator' modifier is inapplicable on this function: must return Boolean (16,5) in /1.1.kt
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* PLACE: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 5 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: The contains function must have a return type kotlin.Boolean, otherwise it is a compile-time error.
|
||||
* EXCEPTION: compiletime
|
||||
*/
|
||||
|
||||
class A(val a: Set<Any>) {
|
||||
var isEvaluated: Boolean = false
|
||||
var isChecked = false
|
||||
operator fun contains(other: Any): Nothing = run {
|
||||
TODO()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun box() {
|
||||
|
||||
val b = A(mutableSetOf(1, 3, false, 2, "azaza"))
|
||||
|
||||
val a = (true in b)
|
||||
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"4": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4/pos/1.2.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2/pos/1.2.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": " A in B is exactly the same as B.contains(A);",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"5": {
|
||||
"neg": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 0,
|
||||
"description": "The contains function must have a return type kotlin.Boolean, otherwise it is a compile-time error.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user