[Spec tests] Add tests for range-expression
This commit is contained in:
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
/*
|
||||||
|
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
|
||||||
|
*
|
||||||
|
* SPEC VERSION: 0.1-218
|
||||||
|
* PLACE: expressions, range-expression -> paragraph 2 -> sentence 1
|
||||||
|
* RELEVANT PLACES: expressions, range-expression -> paragraph 1 -> sentence 1
|
||||||
|
* expressions, range-expression -> paragraph 1 -> sentence 2
|
||||||
|
* expressions, range-expression -> paragraph 3 -> sentence 1
|
||||||
|
* NUMBER: 1
|
||||||
|
* DESCRIPTION: A..B is exactly the same as A.rangeTo(B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
class A(val a: Int) {
|
||||||
|
var isRangeToCalled = false
|
||||||
|
operator fun rangeTo(o: A): MutableList<Int> {
|
||||||
|
isRangeToCalled = true
|
||||||
|
val x: MutableList<Int> = mutableListOf<Int>()
|
||||||
|
for (i in a..o.a)
|
||||||
|
x.add(i)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a1 = A(0)
|
||||||
|
val a2 = A(5)
|
||||||
|
val x = a1..a2
|
||||||
|
if (a1.isRangeToCalled && x is MutableList<Int>)
|
||||||
|
return "OK"
|
||||||
|
return "NOK"
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"2": {
|
||||||
|
"pos": {
|
||||||
|
"1": [
|
||||||
|
{
|
||||||
|
"specVersion": "0.1-218",
|
||||||
|
"casesNumber": 0,
|
||||||
|
"description": "A..B is exactly the same as A.rangeTo(B)",
|
||||||
|
"unexpectedBehaviour": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"1": {
|
||||||
|
"pos": {
|
||||||
|
"1": [
|
||||||
|
{
|
||||||
|
"specVersion": "0.1-218",
|
||||||
|
"casesNumber": 0,
|
||||||
|
"description": "A..B is exactly the same as A.rangeTo(B)",
|
||||||
|
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos/1.1.kt",
|
||||||
|
"unexpectedBehaviour": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// !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, range-expression -> paragraph 4 -> sentence 1
|
||||||
|
* RELEVANT PLACES: expressions, range-expression -> paragraph 4 -> sentence 2
|
||||||
|
* NUMBER: 1
|
||||||
|
* DESCRIPTION: The return type of range operator is not restricted.
|
||||||
|
* HELPERS: checkType
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// TESTCASE NUMBER: 1
|
||||||
|
class Case1() {
|
||||||
|
operator fun rangeTo(o: Case1): Nothing?{
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun case1() {
|
||||||
|
val x = Case1() .. Case1()
|
||||||
|
<!DEBUG_INFO_CONSTANT, DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?")!>x<!>
|
||||||
|
<!DEBUG_INFO_CONSTANT!>x<!> checkType { check<Nothing?>() }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TESTCASE NUMBER: 2
|
||||||
|
class Case2() {
|
||||||
|
operator fun rangeTo(o: Case2): Any?{
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun case2() {
|
||||||
|
val x = Case2() .. Case2()
|
||||||
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
|
||||||
|
x checkType { check<Any?>() }
|
||||||
|
}
|
||||||
|
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"4": {
|
||||||
|
"pos": {
|
||||||
|
"1": [
|
||||||
|
{
|
||||||
|
"specVersion": "0.1-218",
|
||||||
|
"casesNumber": 2,
|
||||||
|
"description": "The return type of range operator is not restricted.",
|
||||||
|
"unexpectedBehaviour": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"2": [
|
||||||
|
{
|
||||||
|
"specVersion": "0.1-218",
|
||||||
|
"casesNumber": 2,
|
||||||
|
"description": "The return type of range operator is not restricted.",
|
||||||
|
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos/1.1.kt",
|
||||||
|
"unexpectedBehaviour": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+44
@@ -1992,6 +1992,50 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Range_expression extends AbstractDiagnosticsTestSpec {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInRange_expression() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class P_4 extends AbstractDiagnosticsTestSpec {
|
||||||
|
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/diagnostics/linked/expressions/range-expression/p-4"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/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/range-expression/p-4/pos/1.1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInPos() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression")
|
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Generated
+44
@@ -1543,6 +1543,50 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Range_expression extends AbstractBlackBoxCodegenTestSpec {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInRange_expression() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-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/range-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-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/range-expression/p-2/pos/1.1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInPos() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression")
|
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user