From 8ef069b985fe9f8646529c0fa6e94dc4e09f676d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 7 Jul 2021 23:20:59 +0200 Subject: [PATCH] COMP: fix RsCompletionTestFixtureBase::checkCompletion --- .../core/completion/RsAwaitCompletionTest.kt | 20 ++----------------- .../core/completion/RsCompletionTestBase.kt | 10 ++++++++++ .../completion/RsCompletionTestFixtureBase.kt | 8 ++++++-- .../RsKeywordCompletionContributorTest.kt | 12 ++--------- .../completion/RsVisibilityCompletionTest.kt | 4 ++-- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsAwaitCompletionTest.kt b/src/test/kotlin/org/rust/lang/core/completion/RsAwaitCompletionTest.kt index 7c08cc03674..5c039f8f34b 100644 --- a/src/test/kotlin/org/rust/lang/core/completion/RsAwaitCompletionTest.kt +++ b/src/test/kotlin/org/rust/lang/core/completion/RsAwaitCompletionTest.kt @@ -11,14 +11,7 @@ import org.rust.cargo.project.workspace.CargoWorkspace class RsAwaitCompletionTest : RsCompletionTestBase() { @MockEdition(CargoWorkspace.Edition.EDITION_2015) - fun `test postfix await 2015 (anon)`() = checkCompletion("await", """ - #[lang = "core::future::future::Future"] - trait Future { type Output; } - fn foo() -> impl Future { unimplemented!() } - fn main() { - foo()./*caret*/; - } - """, """ + fun `test postfix await 2015 (anon)`() = checkNotContainsCompletion("await", """ #[lang = "core::future::future::Future"] trait Future { type Output; } fn foo() -> impl Future { unimplemented!() } @@ -28,16 +21,7 @@ class RsAwaitCompletionTest : RsCompletionTestBase() { """) @MockEdition(CargoWorkspace.Edition.EDITION_2015) - fun `test postfix await 2015 (adt)`() = checkCompletion("await", """ - #[lang = "core::future::future::Future"] - trait Future { type Output; } - struct S; - impl Future for S { type Output = i32; } - fn foo() -> S { unimplemented!() } - fn main() { - foo()./*caret*/; - } - """, """ + fun `test postfix await 2015 (adt)`() = checkNotContainsCompletion("await", """ #[lang = "core::future::future::Future"] trait Future { type Output; } struct S; diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestBase.kt b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestBase.kt index 544a78dbd34..8eee5b9cd33 100644 --- a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestBase.kt +++ b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestBase.kt @@ -106,6 +106,16 @@ abstract class RsCompletionTestBase : RsTestBase() { render: LookupElement.() -> String = { lookupString } ) = completionFixture.checkNotContainsCompletion(code, variant, render) + protected fun checkNotContainsCompletion( + variants: List, + @Language("Rust") code: String, + render: LookupElement.() -> String = { lookupString } + ) { + for (variant in variants) { + completionFixture.checkNotContainsCompletion(code, variant, render) + } + } + protected open fun checkNoCompletion(@Language("Rust") code: String) = completionFixture.checkNoCompletion(code) protected fun checkNoCompletionByFileTree(@Language("Rust") code: String) = diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestFixtureBase.kt b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestFixtureBase.kt index 228ddc3e39b..8cf23070bc5 100644 --- a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestFixtureBase.kt +++ b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTestFixtureBase.kt @@ -61,12 +61,16 @@ abstract class RsCompletionTestFixtureBase( checkByText(before, after.trimIndent()) { val items = myFixture.completeBasic() ?: return@checkByText // single completion was inserted - val lookupItem = items.find { it.lookupString == lookupString } ?: return@checkByText + val lookupItem = items.find { it.lookupString == lookupString } ?: error("Lookup string $lookupString not found") myFixture.lookup.currentItem = lookupItem myFixture.type(completionChar) } } - testmark?.checkHit(action) + if (testmark != null) { + testmark.checkHit(action) + } else { + action() + } } fun checkNoCompletion(code: IN) { diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsKeywordCompletionContributorTest.kt b/src/test/kotlin/org/rust/lang/core/completion/RsKeywordCompletionContributorTest.kt index ed4ef7e025f..a41557ac8a1 100644 --- a/src/test/kotlin/org/rust/lang/core/completion/RsKeywordCompletionContributorTest.kt +++ b/src/test/kotlin/org/rust/lang/core/completion/RsKeywordCompletionContributorTest.kt @@ -691,13 +691,7 @@ class RsKeywordCompletionContributorTest : RsCompletionTestBase() { } """) - fun `test no if|match after path segment`() = checkCompletion(CONDITION_KEYWORDS, """ - struct Foo; - - fn foo() { - Foo::/*caret*/ - } - """, """ + fun `test no if|match after path segment`() = checkNotContainsCompletion(CONDITION_KEYWORDS, """ struct Foo; fn foo() { @@ -705,9 +699,7 @@ class RsKeywordCompletionContributorTest : RsCompletionTestBase() { } """) - fun `test no if|match out of function`() = checkCompletion(CONDITION_KEYWORDS, """ - const FOO: &str = /*caret*/ - """, """ + fun `test no if|match out of function`() = checkNotContainsCompletion(CONDITION_KEYWORDS, """ const FOO: &str = /*caret*/ """) diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsVisibilityCompletionTest.kt b/src/test/kotlin/org/rust/lang/core/completion/RsVisibilityCompletionTest.kt index 82904d94f0b..dc648d81a56 100644 --- a/src/test/kotlin/org/rust/lang/core/completion/RsVisibilityCompletionTest.kt +++ b/src/test/kotlin/org/rust/lang/core/completion/RsVisibilityCompletionTest.kt @@ -15,7 +15,7 @@ class RsVisibilityCompletionTest : RsCompletionTestBase() { } """, """ struct S { - pub/*caret*/ a: u32 + pub /*caret*/a: u32 } """) @@ -52,7 +52,7 @@ class RsVisibilityCompletionTest : RsCompletionTestBase() { fun `test tuple field decl`() = checkCompletion("pub", """ struct S(/*caret*/u32); """, """ - struct S(pub/*caret*/ u32); + struct S(pub /*caret*/u32); """) fun `test inside struct tuple fields`() = checkContainsCompletion("pub", """