From bb96ca528e77e247d289e3d7994f06cd6e6edc97 Mon Sep 17 00:00:00 2001 From: Ilia Zakoulov Date: Wed, 21 Aug 2024 18:45:26 +0200 Subject: [PATCH] PY-76629: Introduce new argument typeCharIfOnlyOneCompletion for completeBasicAllCarets. There are a few tests that provides `charToTypeAfterCompletion = "\t"` to complete the first variant. It makes tests "ditry" - somewhere in tests you have to check that "\t" is present after completion, somewhere "\t" is not present because it completed the first variant. This argument allows to avoid adding unnecessary `charToTypeAfterCompletion` when there is only one completion variant that is already completed. GitOrigin-RevId: 3ed977930b92cedd04ea73764613a55616c291d4 --- .../testFramework/fixtures/CodeInsightTestFixture.java | 4 ++++ .../testFramework/fixtures/EditorTestFixture.java | 7 +++++-- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index 29c4c21b6eba..69ba4fa83f36 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -771,9 +771,13 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * * @param charToTypeAfterCompletion after completion, this char will be typed if not {@code null}. * It could be used to complete the suggestion with {@code '\t'} for example. + * @param typeCharIfOnlyOneCompletion if charToTypeAfterCompletion should be placed if code is completed by {@link #completeBasic()} * @return list of all completion elements just like in {@link #completeBasic()} * @see #completeBasic() */ + @NotNull + List completeBasicAllCarets(@Nullable Character charToTypeAfterCompletion, boolean typeCharIfOnlyOneCompletion); + @NotNull List completeBasicAllCarets(@Nullable Character charToTypeAfterCompletion); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/EditorTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/EditorTestFixture.java index 5f227790857e..2f9becd6ad16 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/EditorTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/EditorTestFixture.java @@ -228,7 +228,7 @@ public class EditorTestFixture { } @NotNull - public final List completeBasicAllCarets(@Nullable final Character charToTypeAfterCompletion) { + public final List completeBasicAllCarets(@Nullable final Character charToTypeAfterCompletion, boolean typeCharIfOnlyOneCompletion) { final CaretModel caretModel = myEditor.getCaretModel(); final List carets = caretModel.getAllCarets(); @@ -247,7 +247,10 @@ public class EditorTestFixture { caretModel.moveToOffset(originalOffset); final LookupElement[] lookupElements = completeBasic(); if (charToTypeAfterCompletion != null) { - type(charToTypeAfterCompletion); + var alwaysCompleteWithChar = !typeCharIfOnlyOneCompletion; + if (alwaysCompleteWithChar || lookupElements != null && lookupElements.length > 0) { + type(charToTypeAfterCompletion); + } } if (lookupElements != null) { result.addAll(Arrays.asList(lookupElements)); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 04c237f98612..f183807cd63e 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1289,10 +1289,16 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return myEditorTestFixture.completeBasic(); } + @Override + @NotNull + public final List completeBasicAllCarets(@Nullable Character charToTypeAfterCompletion, boolean typeCharIfOnlyOneCompletion) { + return myEditorTestFixture.completeBasicAllCarets(charToTypeAfterCompletion, typeCharIfOnlyOneCompletion); + } + @Override @NotNull public final List completeBasicAllCarets(@Nullable Character charToTypeAfterCompletion) { - return myEditorTestFixture.completeBasicAllCarets(charToTypeAfterCompletion); + return completeBasicAllCarets(charToTypeAfterCompletion, true); } @Override