From 0da488058df2e726368c6b4827aae52dfeb0930a Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 27 May 2021 15:06:30 +0200 Subject: [PATCH] FIR IDE: add tests for completion in sealed when --- .../generators/tests/idea/GenerateTests.kt | 1 + .../basic/common/when/enumInEmptyWhen.kt | 16 ++++ .../basic/common/when/enumInWhen.kt | 15 +++ .../when/enumInWhenWithOtherConditions.kt | 14 +++ .../common/when/enumInWhenWithPackage.kt | 18 ++++ .../common/when/nestedSealedClassInWhen.kt | 18 ++++ .../nestedSealedClassInWhenWithPackage.kt | 20 ++++ .../basic/common/when/nonSealedClassInWhen.kt | 21 +++++ .../basic/common/when/nullableEnumInWhen.kt | 17 ++++ .../common/when/nullableSealedClassInWhen.kt | 18 ++++ .../basic/common/when/sealedClassInWhen.kt | 17 ++++ .../sealedClassInWhenWithOtherConditions.kt | 16 ++++ ...sealedClassWithAbstractInheritorsInWhen.kt | 20 ++++ .../common/when/sealedInterfaceInWhen.kt | 18 ++++ ...hLevelJvmBasicCompletionTestGenerated.java | 91 +++++++++++++++++++ 15 files changed, 320 insertions(+) create mode 100644 idea/idea-fir/testData/completion/basic/common/when/enumInEmptyWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/enumInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithOtherConditions.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithPackage.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhenWithPackage.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/nonSealedClassInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/nullableEnumInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/nullableSealedClassInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhenWithOtherConditions.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/sealedClassWithAbstractInheritorsInWhen.kt create mode 100644 idea/idea-fir/testData/completion/basic/common/when/sealedInterfaceInWhen.kt diff --git a/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt b/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt index 554de3ffeaf..14ebf191700 100644 --- a/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt +++ b/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt @@ -1198,6 +1198,7 @@ fun main(args: Array) { testClass { model("basic/common") model("basic/java") + model("../../idea-fir/testData/completion/basic/common", testClassName = "CommonFir") } testClass { diff --git a/idea/idea-fir/testData/completion/basic/common/when/enumInEmptyWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/enumInEmptyWhen.kt new file mode 100644 index 00000000000..284973853df --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/enumInEmptyWhen.kt @@ -0,0 +1,16 @@ +enum class ENUM { + AAAA, BBBB, CCCC +} + +fun foo(e: ENUM) { + when (e) { + + } +} + +// EXIST: ENUM.AAAA +// EXIST: ENUM.BBBB +// EXIST: ENUM.CCCC +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/enumInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/enumInWhen.kt new file mode 100644 index 00000000000..ae32b8dbdd4 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/enumInWhen.kt @@ -0,0 +1,15 @@ +enum class ENUM { + AAAA, BBBB, CCCC +} + +fun foo(e: ENUM) { + when (e) { + ENUM.AAAA, ENUM.CCCC -> TODO() + + } +} + +// EXIST: ENUM.BBBB +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithOtherConditions.kt b/idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithOtherConditions.kt new file mode 100644 index 00000000000..603133b8e44 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithOtherConditions.kt @@ -0,0 +1,14 @@ +enum class ENUM { + AAAA, BBBB, CCCC +} + +fun foo(e: ENUM) { + when (e) { + ENUM.AAAA, ENUM.CCCC, -> TODO() + + } +} + +// EXIST: ENUM.BBBB +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithPackage.kt b/idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithPackage.kt new file mode 100644 index 00000000000..cfd394f5734 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/enumInWhenWithPackage.kt @@ -0,0 +1,18 @@ +package a.b.c + +enum class ENUM { + AAAA, BBBB, CCCC +} + +fun foo(e: ENUM) { + when (e) { + + } +} + +// EXIST: ENUM.AAAA +// EXIST: ENUM.BBBB +// EXIST: ENUM.CCCC +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhen.kt new file mode 100644 index 00000000000..a14d1f7cf9c --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhen.kt @@ -0,0 +1,18 @@ +sealed class SEALED { + class AAAA: SEALED() + object BBBB: SEALED() + class CCCC: SEALED() +} + +fun foo(e: SEALED) { + when (e) { + + } +} + +// EXIST: is SEALED.AAAA +// EXIST: SEALED.BBBB +// EXIST: is SEALED.CCCC +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhenWithPackage.kt b/idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhenWithPackage.kt new file mode 100644 index 00000000000..9635859bf7e --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhenWithPackage.kt @@ -0,0 +1,20 @@ +package a.b.c + +sealed class SEALED { + class AAAA: SEALED() + object BBBB: SEALED() + class CCCC: SEALED() +} + +fun foo(e: SEALED) { + when (e) { + + } +} + +// EXIST: is SEALED.AAAA +// EXIST: SEALED.BBBB +// EXIST: is SEALED.CCCC +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/nonSealedClassInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/nonSealedClassInWhen.kt new file mode 100644 index 00000000000..f1f573e1f75 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/nonSealedClassInWhen.kt @@ -0,0 +1,21 @@ +abstract class SEALED +class AAAA: SEALED() +object BBBB: SEALED() +class CCCC: SEALED() + +class SomeClass +object SomeObject + +fun foo(e: SEALED) { + when (e) { + + } +} + +// EXIST: is AAAA +// EXIST: BBBB +// EXIST: is CCCC +// EXIST: is SomeClass +// EXIST: SomeObject +// EXIST: { lookupString: "else -> "} +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/nullableEnumInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/nullableEnumInWhen.kt new file mode 100644 index 00000000000..2677b4d720a --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/nullableEnumInWhen.kt @@ -0,0 +1,17 @@ +enum class ENUM { + AAAA, BBBB, CCCC +} + +fun foo(e: ENUM?) { + when (e) { + + } +} + +// EXIST: ENUM.AAAA +// EXIST: ENUM.BBBB +// EXIST: ENUM.CCCC +// EXIST: { lookupString: "else -> "} +// EXIST: null +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/nullableSealedClassInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/nullableSealedClassInWhen.kt new file mode 100644 index 00000000000..9ba28df4f65 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/nullableSealedClassInWhen.kt @@ -0,0 +1,18 @@ +sealed class SEALED +class AAAA: SEALED() +object BBBB: SEALED() +class CCCC: SEALED() + +fun foo(e: SEALED?) { + when (e) { + + } +} + +// EXIST: is AAAA +// EXIST: BBBB +// EXIST: is CCCC +// EXIST: null +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhen.kt new file mode 100644 index 00000000000..e5048afe774 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhen.kt @@ -0,0 +1,17 @@ +sealed class SEALED +class AAAA: SEALED() +object BBBB: SEALED() +class CCCC: SEALED() + +fun foo(e: SEALED) { + when (e) { + + } +} + +// EXIST: is AAAA +// EXIST: BBBB +// EXIST: is CCCC +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhenWithOtherConditions.kt b/idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhenWithOtherConditions.kt new file mode 100644 index 00000000000..d0fbe10592b --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/sealedClassInWhenWithOtherConditions.kt @@ -0,0 +1,16 @@ +sealed class SEALED +class AAAA: SEALED() +object BBBB: SEALED() +class CCCC: SEALED() + +fun foo(e: SEALED) { + when (e) { + is AAAA, CCCC -> TODO() + + } +} + +// EXIST: BBBB +// EXIST: { lookupString: "else -> "} +// NOTHING_ELSE +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/sealedClassWithAbstractInheritorsInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/sealedClassWithAbstractInheritorsInWhen.kt new file mode 100644 index 00000000000..924a378066b --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/sealedClassWithAbstractInheritorsInWhen.kt @@ -0,0 +1,20 @@ +sealed class SEALED +class AAAA: SEALED() +object BBBB: SEALED() +abstract class CCCC: SEALED() + +class SomeClass + + +fun foo(e: SEALED) { + when (e) { + + } +} + +// EXIST: is AAAA +// EXIST: BBBB +// EXIST: is CCCC +// EXIST: { lookupString: "else -> "} +// EXIST: is SomeClass +// FIR_COMPARISON diff --git a/idea/idea-fir/testData/completion/basic/common/when/sealedInterfaceInWhen.kt b/idea/idea-fir/testData/completion/basic/common/when/sealedInterfaceInWhen.kt new file mode 100644 index 00000000000..41ab70f8a89 --- /dev/null +++ b/idea/idea-fir/testData/completion/basic/common/when/sealedInterfaceInWhen.kt @@ -0,0 +1,18 @@ +sealed interface SEALED +class AAAA: SEALED() +object BBBB: SEALED() +class CCCC: SEALED() + +class SomeClass + +fun foo(e: SEALED) { + when (e) { + + } +} + +// EXIST: is AAAA +// EXIST: BBBB +// EXIST: is CCCC +// EXIST: { lookupString: "else -> "} +// FIR_COMPARISON diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/completion/HighLevelJvmBasicCompletionTestGenerated.java b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/completion/HighLevelJvmBasicCompletionTestGenerated.java index ff167aabb0d..6427b207bfb 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/completion/HighLevelJvmBasicCompletionTestGenerated.java +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/completion/HighLevelJvmBasicCompletionTestGenerated.java @@ -3322,4 +3322,95 @@ public class HighLevelJvmBasicCompletionTestGenerated extends AbstractHighLevelJ } } } + + @TestMetadata("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CommonFir extends AbstractHighLevelJvmBasicCompletionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInCommonFir() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class When extends AbstractHighLevelJvmBasicCompletionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInWhen() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("enumInEmptyWhen.kt") + public void testEnumInEmptyWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/enumInEmptyWhen.kt"); + } + + @TestMetadata("enumInWhen.kt") + public void testEnumInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/enumInWhen.kt"); + } + + @TestMetadata("enumInWhenWithOtherConditions.kt") + public void testEnumInWhenWithOtherConditions() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/enumInWhenWithOtherConditions.kt"); + } + + @TestMetadata("enumInWhenWithPackage.kt") + public void testEnumInWhenWithPackage() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/enumInWhenWithPackage.kt"); + } + + @TestMetadata("nestedSealedClassInWhen.kt") + public void testNestedSealedClassInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhen.kt"); + } + + @TestMetadata("nestedSealedClassInWhenWithPackage.kt") + public void testNestedSealedClassInWhenWithPackage() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/nestedSealedClassInWhenWithPackage.kt"); + } + + @TestMetadata("nonSealedClassInWhen.kt") + public void testNonSealedClassInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/nonSealedClassInWhen.kt"); + } + + @TestMetadata("nullableEnumInWhen.kt") + public void testNullableEnumInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/nullableEnumInWhen.kt"); + } + + @TestMetadata("nullableSealedClassInWhen.kt") + public void testNullableSealedClassInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/nullableSealedClassInWhen.kt"); + } + + @TestMetadata("sealedClassInWhen.kt") + public void testSealedClassInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/sealedClassInWhen.kt"); + } + + @TestMetadata("sealedClassInWhenWithOtherConditions.kt") + public void testSealedClassInWhenWithOtherConditions() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/sealedClassInWhenWithOtherConditions.kt"); + } + + @TestMetadata("sealedClassWithAbstractInheritorsInWhen.kt") + public void testSealedClassWithAbstractInheritorsInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/sealedClassWithAbstractInheritorsInWhen.kt"); + } + + @TestMetadata("sealedInterfaceInWhen.kt") + public void testSealedInterfaceInWhen() throws Exception { + runTest("idea/idea-completion/testData/../../idea-fir/testData/completion/basic/common/when/sealedInterfaceInWhen.kt"); + } + } + } }