[Spec tests] Add tests for containment-checking-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-20 18:20:19 +03:00
parent 4a94ffa5dd
commit 479fa0e7b8
11 changed files with 501 additions and 0 deletions
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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
@@ -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)
}
@@ -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
}
]
}
}
}
@@ -0,0 +1,57 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_PARAMETER -UNUSED_VARIABLE
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, type-checking-and-containment-checking-expressions, containment-checking-expression -> paragraph 5 -> sentence 2
* NUMBER: 1
* DESCRIPTION: Containment-checking expressions always have type kotlin.Boolean.
* HELPERS: checkType
*/
class A(val a: Set<Any>) {
operator fun contains(other: Any?): Boolean = run { this.a.contains(other) }
fun throwException(b: Boolean): A { if (b) throw Exception() else return this }
}
class C() {
var isEvaluated: Boolean = false
fun foo(): C {
this.isEvaluated = true
return this
}
}
// TESTCASE NUMBER: 1
fun case1() {
val b = A(mutableSetOf(1, C(), 3, false, 2, "azaza"))
val c = C()
val a = (c in b.throwException(true))
a checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 2
fun case2() {
val b = A(mutableSetOf(1, C(), 3, false, 2, "azaza"))
val a = (null in b)
a checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 3
fun case3() {
val b = A(mutableSetOf(1, C(), 3, false, 2, "azaza"))
val x = ""
val a = (C() in b)
a checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 4
fun case4(nothing: Nothing) {
val b = A(mutableSetOf(1, C(), 3, false, 2, "azaza"))
val a = (nothing in b)
a checkType { check<Boolean>() }
}
@@ -0,0 +1,14 @@
{
"5": {
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 4,
"description": "Containment-checking expressions always have type kotlin.Boolean.",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -2173,6 +2173,50 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Containment_checking_expression extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInContainment_checking_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_5 extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_5() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("2.1.kt")
public void test2_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5/pos/2.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/type-checking-and-containment-checking-expressions/type-checking-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1714,6 +1714,122 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Containment_checking_expression extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInContainment_checking_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_2 extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_2() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2/pos/1.1.kt");
}
@TestMetadata("1.2.kt")
public void test1_2() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2/pos/1.2.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_4 extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_4() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4/pos/1.1.kt");
}
@TestMetadata("1.2.kt")
public void test1_2() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4/pos/1.2.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_5 extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_5() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5/neg")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Neg extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5/neg/1.1.kt");
}
public void testAllFilesPresentInNeg() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/containment-checking-expression/p-5/neg"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/type-checking-and-containment-checking-expressions/type-checking-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)