[Spec tests] Add tests for receivers prioritization

This commit is contained in:
anastasiia.spaseeva
2020-02-13 17:57:39 +03:00
committed by Victor Petukhov
parent 3b35374186
commit 157e33d08b
7 changed files with 339 additions and 0 deletions
@@ -0,0 +1,43 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-268
* PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 2
* NUMBER: 1
* DESCRIPTION: implicit this receiver has higher priority than any companion object receiver
*/
class Case1() : Case1Base() {
companion object foo{
var isCompanionObjectReceiverCalled = false
operator fun invoke() {}
fun foo() {
this.isCompanionObjectReceiverCalled = true
}
}
fun case() {
foo() // resolved (1)
}
}
open class Case1Base {
var isImplicitReceiverCalled = false
fun foo() {
this.isImplicitReceiverCalled = true
}
}
fun box(): String {
val test = Case1()
test.case()
if (test.isImplicitReceiverCalled && !Case1.isCompanionObjectReceiverCalled)
return "OK"
return "NOK"
}
@@ -0,0 +1,43 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-268
* PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 2
* NUMBER: 2
* DESCRIPTION: implicit this receiver has higher priority than any companion object receiver
*/
class Case1() : Case1Base() {
var isImplicitReceiverCalled = false
fun foo() {
this.isImplicitReceiverCalled = true
} // (1)
fun case() {
foo() // resolved (1)
}
}
open class Case1Base {
companion object foo{
var isCompanionObjectReceiverCalled = false
operator fun invoke() {}
fun foo() {
this.isCompanionObjectReceiverCalled = true
}
}
}
fun box(): String {
val test = Case1()
test.case()
if (test.isImplicitReceiverCalled && !Case1Base.isCompanionObjectReceiverCalled)
return "OK"
return "NOK"
}
@@ -0,0 +1,33 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-268
* PLACE:overload-resolution, receivers -> paragraph 5 -> sentence 3
* NUMBER: 1
* DESCRIPTION: Current class companion object receiver has higher priority than any of the superclass companion objects;
*/
class Case() : CaseBase() {
companion object foo{
var isCaseCompanionCalled = false
fun foo(){isCaseCompanionCalled = true}
}
}
open class CaseBase {
companion object foo {
var isCaseBaseReceiverCalled = false
fun foo() { this.isCaseBaseReceiverCalled = true }
// operator fun invoke() {}
}
}
fun box(): String {
Case.foo.foo()
if (!CaseBase.isCaseBaseReceiverCalled && Case.isCaseCompanionCalled)
return "OK"
return "NOK"
}
@@ -0,0 +1,36 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-268
* PLACE:overload-resolution, receivers -> paragraph 5 -> sentence 3
* NUMBER: 2
* DESCRIPTION: Current class companion object receiver has higher priority than any of the superclass companion objects;
*/
class Case() : CaseBase() {
companion object foo{
var isCaseCompanionCalled = false
fun foo(){isCaseCompanionCalled = true}
}
fun test(): String{
foo.foo()
if (!isCaseBaseReceiverCalled && isCaseCompanionCalled)
return "OK"
return "NOK"
}
}
open class CaseBase {
companion object foo {
var isCaseBaseReceiverCalled = false
fun foo() { this.isCaseBaseReceiverCalled = true }
}
}
fun box(): String {
return Case().test()
}
@@ -0,0 +1,71 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-268
* PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 4
* RELEVANT PLACES: overload-resolution, receivers -> paragraph 5 -> sentence 3
* NUMBER: 1
* DESCRIPTION: Superclass companion object receivers are prioritized according to the inheritance order
*/
fun box(): String {
val case0 =CaseBase0().case0()
val case1 =CaseBase1().case1()
val case2 =CaseBase2().case2()
if (case0 && case1 && case2)
return "OK"
return "NOK"
}
class CaseBase2() : CaseBase1() {
companion object foo {
var isCaseCompanionCalled = false
fun foo() {
isCaseCompanionCalled = true
}
}
fun case2(): Boolean {
foo.foo()
val res = !isCaseBase0ReceiverCalled && !isCaseBaseReceiverCalled && isCaseCompanionCalled
isCaseCompanionCalled = false
return res
}
}
open class CaseBase1 : CaseBase0() {
companion object foo {
var isCaseBaseReceiverCalled = false
fun foo() {
this.isCaseBaseReceiverCalled = true
}
}
fun case1(): Boolean {
foo.foo()
val res = !isCaseBase0ReceiverCalled && CaseBase1.isCaseBaseReceiverCalled && !CaseBase2.isCaseCompanionCalled
isCaseBaseReceiverCalled = false
return res
}
}
open class CaseBase0 {
companion object foo {
var isCaseBase0ReceiverCalled = false
fun foo() {
this.isCaseBase0ReceiverCalled = true
}
}
fun case0(): Boolean {
foo.foo()
val res = isCaseBase0ReceiverCalled && !CaseBase1.isCaseBaseReceiverCalled && !CaseBase2.isCaseCompanionCalled
isCaseBase0ReceiverCalled = false
return res
}
}
@@ -0,0 +1,49 @@
{
"5": {
"pos": {
"2": [
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "implicit this receiver has higher priority than any companion object receiver",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "implicit this receiver has higher priority than any companion object receiver",
"unexpectedBehaviour": false
}
],
"3": [
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "Current class companion object receiver has higher priority than any of the superclass companion objects;",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "Superclass companion object receivers are prioritized according to the inheritance order",
"path": "compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "Current class companion object receiver has higher priority than any of the superclass companion objects;",
"unexpectedBehaviour": false
}
],
"4": [
{
"specVersion": "0.1-268",
"casesNumber": 0,
"description": "Superclass companion object receivers are prioritized according to the inheritance order",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -3388,6 +3388,70 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Receivers extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInReceivers() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/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.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/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/overload-resolution/receivers/p-5/pos/2.1.kt");
}
@TestMetadata("2.2.kt")
public void test2_2() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.2.kt");
}
@TestMetadata("3.1.kt")
public void test3_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.1.kt");
}
@TestMetadata("3.2.kt")
public void test3_2() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.2.kt");
}
@TestMetadata("4.1.kt")
public void test4_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/statements")