[Spec tests] Add tests for comparison-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-19 17:13:54 +03:00
parent 5e42a20575
commit 2a1e084f03
12 changed files with 560 additions and 0 deletions
@@ -0,0 +1 @@
java.lang.IllegalStateException: OPERATOR_MODIFIER_REQUIRED: 'operator' modifier is required on 'compareTo' in 'A' (24,17) in /2.1.kt
@@ -0,0 +1,26 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* NUMBER: 1
* DESCRIPTION: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* EXCEPTION: compiletime
*/
class A(val a: Int) {
var isCompared = false
fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
fun box() {
val a3 = A(-1)
val a4 = A(-3)
val x = (a3 > a4)
}
@@ -0,0 +1,32 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, comparison-expressions -> paragraph 1 -> sentence 1
* expressions, comparison-expressions -> paragraph 2 -> sentence 1
* expressions, comparison-expressions -> paragraph 3 -> sentence 1
* expressions, comparison-expressions -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: These operators are overloadable (A < B)
*/
//A < B is exactly the same as integerLess(A.compareTo(B), 0)
fun box(): String {
val a1 = A(-1)
val a2 = A(3)
if (a1 < a2)
if (a1.isCompared && !a2.isCompared)
return "OK"
return "NOK"
}
class A(val a: Int) {
var isCompared = false
operator fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
@@ -0,0 +1,32 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, comparison-expressions -> paragraph 1 -> sentence 1
* expressions, comparison-expressions -> paragraph 2 -> sentence 2
* expressions, comparison-expressions -> paragraph 3 -> sentence 1
* expressions, comparison-expressions -> paragraph 4 -> sentence 1
* NUMBER: 2
* DESCRIPTION: These operators are overloadable (A > B)
*/
//A > B is exactly the same as integerLess(0, A.compareTo(B))
fun box(): String {
val a1 = A(-1)
val a2 = A(-3)
if (a1 > a2)
if (a1.isCompared && !a2.isCompared)
return "OK"
return "NOK"
}
class A(val a: Int) {
var isCompared = false
operator fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
@@ -0,0 +1,36 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, comparison-expressions -> paragraph 1 -> sentence 1
* expressions, comparison-expressions -> paragraph 2 -> sentence 3
* expressions, comparison-expressions -> paragraph 3 -> sentence 1
* expressions, comparison-expressions -> paragraph 4 -> sentence 1
* NUMBER: 3
* DESCRIPTION: These operators are overloadable (A <= B)
*/
//A <= B is exactly the same as !integerLess(A.compareTo(B),0)
fun box(): String {
val a1 = A(1)
val a2 = A(3)
val aa1 = A(0)
val aa2 = A(0)
if (a1 <= a2 && a1.isCompared && !a2.isCompared)
if (aa1 <= aa2 && aa1.isCompared && !aa2.isCompared)
return "OK"
return "NOK"
}
class A(val a: Int) {
var isCompared = false
operator fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
@@ -0,0 +1,36 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, comparison-expressions -> paragraph 1 -> sentence 1
* expressions, comparison-expressions -> paragraph 2 -> sentence 3
* expressions, comparison-expressions -> paragraph 3 -> sentence 1
* expressions, comparison-expressions -> paragraph 4 -> sentence 1
* NUMBER: 4
* DESCRIPTION: These operators are overloadable (A >= B)
*/
// A >= B is exactly the same as !integerLess(0, A.compareTo(B))
fun box(): String {
val a1 = A(10)
val a2 = A(3)
val aa1 = A(0)
val aa2 = A(0)
if (a1 >= a2) if (a1.isCompared && !a2.isCompared)
if (aa1 >= aa2) if (aa1.isCompared && !aa2.isCompared)
return "OK"
return "NOK"
}
class A(val a: Int) {
var isCompared = false
operator fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
@@ -0,0 +1,72 @@
{
"1": {
"neg": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "expressions, comparison-expressions -\u003e paragraph 1 -\u003e sentence 2",
"unexpectedBehaviour": false
}
]
},
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003c B)",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003e\u003d B)",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003c\u003d B)",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003e B)",
"unexpectedBehaviour": false
}
],
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003c B)",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/comparison-expressions/p-1/pos/2.1.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003e\u003d B)",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/comparison-expressions/p-1/pos/2.4.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003c\u003d B)",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/comparison-expressions/p-1/pos/2.3.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "These operators are overloadable (A \u003e B)",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/comparison-expressions/p-1/pos/2.2.kt",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,86 @@
// !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-218
* PLACE: expressions, comparison-expressions -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The compareTo operator function must have return type kotlin.Int
*/
// TESTCASE NUMBER: 1
class Case1(val a: Int) {
var isCompared = false
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun compareTo(other: Case1):Any = run{
TODO()
}
}
fun case1() {
val a3 = Case1(-1)
val a4 = Case1(-3)
val x0 = a3 <!COMPARE_TO_TYPE_MISMATCH!>><!> a4
val x1 = a3 <!COMPARE_TO_TYPE_MISMATCH!><<!> a4
val x2 = a3 <!COMPARE_TO_TYPE_MISMATCH!>>=<!> a4
val x3 = a3 <!COMPARE_TO_TYPE_MISMATCH!><=<!> a4
}
// TESTCASE NUMBER: 2
class Case2(val a: Int) {
var isCompared = false
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun compareTo(other: Case2): Nothing = run {
TODO()
}
}
fun case2() {
val a3 = Case2(-1)
val a4 = Case2(-3)
val x0 = a3 <!COMPARE_TO_TYPE_MISMATCH!>><!> a4
val x1 = a3 <!COMPARE_TO_TYPE_MISMATCH!><<!> a4
val x2 = a3 <!COMPARE_TO_TYPE_MISMATCH!>>=<!> a4
val x3 = a3 <!COMPARE_TO_TYPE_MISMATCH!><=<!> a4
}
// TESTCASE NUMBER: 3
class Case3(val a: Int) {
var isCompared = false
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun compareTo(other: Case3):Long = run{
TODO()
}
}
fun case3() {
val a3 = Case3(-1)
val a4 = Case3(-3)
val x0 = a3 <!COMPARE_TO_TYPE_MISMATCH!>><!> a4
val x1 = a3 <!COMPARE_TO_TYPE_MISMATCH!><<!> a4
val x2 = a3 <!COMPARE_TO_TYPE_MISMATCH!>>=<!> a4
val x3 = a3 <!COMPARE_TO_TYPE_MISMATCH!><=<!> a4
}
// TESTCASE NUMBER: 4
class Case4(val a: Int) {
var isCompared = false
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun compareTo(other: Case4):Int? = run{
TODO()
}
}
fun case4() {
val a3 = Case4(-1)
val a4 = Case4(-3)
val x0 = a3 <!COMPARE_TO_TYPE_MISMATCH!>><!> a4
val x1 = a3 <!COMPARE_TO_TYPE_MISMATCH!><<!> a4
val x2 = a3 <!COMPARE_TO_TYPE_MISMATCH!>>=<!> a4
val x3 = a3 <!COMPARE_TO_TYPE_MISMATCH!><=<!> a4
}
@@ -0,0 +1,61 @@
// !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-218
* PLACE: expressions, comparison-expressions -> paragraph 5 -> sentence 1
* NUMBER: 1
* DESCRIPTION: All comparison expressions always have type kotlin.Boolean.
* HELPERS: checkType
*/
class A(val a: Int) {
var isCompared = false
operator fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
// TESTCASE NUMBER: 1
fun case1() {
val a1 = A(-1)
val a2 = A(-3)
val x = a1 < a2
x checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 2
fun case2() {
val a1 = A(-1)
val a2 = A(-3)
val x = a1 > a2
x checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 3
fun case3() {
val a1 = A(-1)
val a2 = A(-3)
val x = a1 <= a2
x checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 4
fun case4() {
val a1 = A(-1)
val a2 = A(-3)
val x = a1 >= a2
x checkType { check<Boolean>() }
}
@@ -0,0 +1,26 @@
{
"4": {
"neg": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 4,
"description": "The compareTo operator function must have return type kotlin.Int",
"unexpectedBehaviour": false
}
]
}
},
"5": {
"pos": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 4,
"description": "All comparison expressions always have type kotlin.Boolean.",
"unexpectedBehaviour": false
}
]
}
}
}