[Spec tests] Add tests for logical-conjunction-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-19 17:42:43 +03:00
parent 6da8ccb9eb
commit 15b561195f
10 changed files with 439 additions and 6 deletions
@@ -0,0 +1,39 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false.
*/
fun box(): String {
val aval = A()
val x = aval.a(true) &&
aval.b(true) &&
aval.c(false) &&
aval.d(false)
if (aval.a && aval.b && aval.c && !aval.d && !x)
return "OK"
return "NOK"
}
class A (var a: Boolean = false,
var b: Boolean = false,
var c: Boolean = false,
var d: Boolean = false){
fun a(a: Boolean): Boolean { this.a = true; return a }
fun b(a: Boolean): Boolean { this.b = true; return a }
fun c(a: Boolean): Boolean { this.c = true; return a }
fun d(a: Boolean): Boolean { this.d = true; return a }
}
@@ -0,0 +1,25 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1
* NUMBER: 2
* DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false.
*/
fun box(): String {
val x: Boolean
try {
x = true && true && false && throw MyException()
} catch (e: MyException) {
return "NOK"
}
if (x)
return "NOK"
return "OK"
}
class MyException : Exception() {}
@@ -0,0 +1,24 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 1 -> sentence 1
* NUMBER: 3
* DESCRIPTION: operator && does not evaluate the right hand side argument unless the left hand side argument evaluated to false.
*/
fun box(): String {
val x: Boolean = false
try {
x = (throw MyException()) && true
} catch (e: MyException) {
if (!x)
return "OK"
}
return "NOK"
}
class MyException : Exception() {}
@@ -0,0 +1,49 @@
{
"1": {
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"unexpectedBehaviour": false
}
],
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "operator \u0026\u0026 does not evaluate the right hand side argument unless the left hand side argument evaluated to false.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,81 @@
// !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, logical-conjunction-expression -> paragraph 2 -> sentence 1
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 2 -> sentence 2
* NUMBER: 1
* DESCRIPTION: Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean
* HELPERS: checkType
*/
// MODULE: libModule
// FILE: libModule/JavaClass.java
package libModule;
public class JavaClass {
public static Object VALUE = false;
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
import checkSubtype
import checkType
import check
// TESTCASE NUMBER: 0
fun foo() = run { false && <!TYPE_MISMATCH!>JavaClass.VALUE<!> && throw Exception() }
// TESTCASE NUMBER: 1
fun case1() {
val a: Boolean? = false
checkSubtype<Boolean?>(a)
val x4 = <!TYPE_MISMATCH!>a<!> && true
x4 checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 2
fun case2() {
val a: Any = false
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>a<!>
val x4 = <!TYPE_MISMATCH!>a<!> && true
x4 checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 3
fun case3() {
val a1 = false
val a2 = JavaClass.VALUE
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Any..kotlin.Any?)")!>a2<!>
val x3 = a1 && <!TYPE_MISMATCH!>a2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean")!>x3<!>
x3 checkType { check<Boolean>() }
}
// TESTCASE NUMBER: 4
fun case4() {
var x = false &&<!SYNTAX!><!> ;
}
// TESTCASE NUMBER: 5
fun case5() {
var y = false &&<!SYNTAX!><!>
}
// TESTCASE NUMBER: 5
fun case5() {
var x =<!SYNTAX!><!> <!SYNTAX!>&&<!>
}
// TESTCASE NUMBER: 6
fun case6() {
var x =<!SYNTAX!><!> <!SYNTAX!>&& false && true<!>
}
@@ -0,0 +1,57 @@
// !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, logical-conjunction-expression -> paragraph 2 -> sentence 1
* RELEVANT PLACES: expressions, logical-conjunction-expression -> paragraph 2 -> sentence 2
* NUMBER: 1
* DESCRIPTION: Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean
* HELPERS: checkType
*/
// MODULE: libModule
// FILE: libModule/JavaClass.java
package libModule;
public class JavaClass {
public static boolean VALUE;
public static Object VALUE_OBJ = true;
public Boolean getValue ()
{ return new Boolean ("true"); }
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
import checkSubtype
import checkType
import check
fun foo() = run { false && JavaClass.VALUE && throw Exception() }
// TESTCASE NUMBER: 1
fun case1() {
val a1 = false
val a2 = JavaClass.VALUE
val a3 = foo()
val a4 = JavaClass().getValue()
val a5 = JavaClass.VALUE_OBJ
checkSubtype<Boolean>(a1)
checkSubtype<Boolean>(a2)
checkSubtype<Boolean>(a3)
checkSubtype<Boolean>(a4)
val x3 = a1 && a2 && a3 && a4 && a5 as Boolean
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean")!>x3<!>
x3 checkType { check<Boolean>()}
}
@@ -0,0 +1,42 @@
{
"2": {
"neg": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 7,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean",
"unexpectedBehaviour": false
}
],
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 7,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean",
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/neg/1.1.kt",
"unexpectedBehaviour": false
}
]
},
"pos": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 1,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean",
"unexpectedBehaviour": false
}
],
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 1,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean",
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/pos/1.1.kt",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -4,16 +4,16 @@
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 6,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error.",
"casesNumber": 7,
"description": "Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error.",
"unexpectedBehaviour": false
}
],
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 6,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error.",
"casesNumber": 7,
"description": "Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean, otherwise it is a type error.",
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/neg/1.1.kt",
"unexpectedBehaviour": false
}
@@ -24,7 +24,7 @@
{
"specVersion": "0.1-218",
"casesNumber": 1,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean",
"description": "Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean",
"unexpectedBehaviour": false
}
],
@@ -32,7 +32,7 @@
{
"specVersion": "0.1-218",
"casesNumber": 1,
"description": "Both operands of a logical conjunction expression must have a type which is a subtype of kotlin.Boolean",
"description": "Both operands of a logical disjunction expression must have a type which is a subtype of kotlin.Boolean",
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression/p-2/pos/1.1.kt",
"unexpectedBehaviour": false
}
@@ -1604,6 +1604,68 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Logical_conjunction_expression extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInLogical_conjunction_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_2 extends AbstractDiagnosticsTestSpec {
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/diagnostics/linked/expressions/logical-conjunction-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/neg")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Neg extends AbstractDiagnosticsTestSpec {
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/diagnostics/linked/expressions/logical-conjunction-expression/p-2/neg/1.1.kt");
}
public void testAllFilesPresentInNeg() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/neg"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/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("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/pos/1.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-conjunction-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/logical-disjunction-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1051,6 +1051,60 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Logical_conjunction_expression extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInLogical_conjunction_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_1 extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_1() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/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("2.1.kt")
public void test2_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.1.kt");
}
@TestMetadata("2.2.kt")
public void test2_2() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.2.kt");
}
@TestMetadata("2.3.kt")
public void test2_3() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos/2.3.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-conjunction-expression/p-1/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/logical-disjunction-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)