Skip to content

Commit

Permalink
Merge #7482
Browse files Browse the repository at this point in the history
7482: COMP: fix RsCompletionTestFixtureBase::checkCompletion r=vlad20012 a=Kobzol

While working on #3830, I noticed that the function `RsCompletionTestBase::checkCompletion` does not behave correctly. If no testmark is passed to the function, it basically won't do anything, therefore the test will always succeed.

I changed `checkCompletion` so that it actually does something even without a testmark. It now also throws an error if the passed lookup string is not found.

There were a few tests that used `checkCompletion` without a testmark, so they passed even though they were actually failing. I tried to fix them.

Co-authored-by: Jakub Beránek <berykubik@gmail.com>
  • Loading branch information
bors[bot] and Kobzol committed Jul 23, 2021
2 parents 45bd7e7 + 8ef069b commit 3f0d773
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output=i32> { 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<Output=i32> { unimplemented!() }
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ abstract class RsCompletionTestBase : RsTestBase() {
render: LookupElement.() -> String = { lookupString }
) = completionFixture.checkNotContainsCompletion(code, variant, render)

protected fun checkNotContainsCompletion(
variants: List<String>,
@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) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ abstract class RsCompletionTestFixtureBase<IN>(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,23 +691,15 @@ 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() {
Foo::/*caret*/
}
""")

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*/
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RsVisibilityCompletionTest : RsCompletionTestBase() {
}
""", """
struct S {
pub/*caret*/ a: u32
pub /*caret*/a: u32
}
""")

Expand Down Expand Up @@ -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", """
Expand Down

0 comments on commit 3f0d773

Please sign in to comment.