From 97d650e902e34d667d9faddc5786d6eb6392966f Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 3 Jun 2015 17:37:07 +0200 Subject: [PATCH] a test for IDEA-139349 Go to action has strange order for "Rebas" input --- .../intellij/navigation/GotoActionTest.groovy | 44 +++++++++++++++++++ .../ide/util/gotoByName/GotoActionModel.java | 7 ++- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy diff --git a/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy new file mode 100644 index 000000000000..9e56995d0edd --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.navigation +import com.intellij.ide.util.gotoByName.GotoActionModel +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +/** + * @author peter + */ +class GotoActionTest extends LightCodeInsightFixtureTestCase { + + public void "test shorter actions first despite ellipsis"() { + def pattern = 'Rebas' + def fork = 'Rebase my GitHub fork' + def rebase = 'Rebase...' + def items = [new GotoActionModel.MatchedValue(createAction(fork), pattern), new GotoActionModel.MatchedValue(createAction(rebase), pattern)].sort() + assert [rebase, fork] == items.collect { it.valueText } + } + + private static GotoActionModel.ActionWrapper createAction(String text) { + def action = new AnAction(text) { + @Override + void actionPerformed(AnActionEvent e) { + } + } + return new GotoActionModel.ActionWrapper(action, "", GotoActionModel.MatchMode.NAME, DataContext.EMPTY_CONTEXT) + } + +} diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index 0d5630e4cc42..1a4bfa19b67f 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -16,6 +16,7 @@ package com.intellij.ide.util.gotoByName; +import com.google.common.annotations.VisibleForTesting; import com.intellij.ide.IdeBundle; import com.intellij.ide.actions.ApplyIntentionAction; import com.intellij.ide.actions.ShowSettingsUtilImpl; @@ -153,7 +154,8 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C } @Nullable - private String getValueText() { + @VisibleForTesting + public String getValueText() { if (value instanceof OptionDescription) return ((OptionDescription)value).getHit(); if (!(value instanceof ActionWrapper)) return null; return ((ActionWrapper)value).getAction().getTemplatePresentation().getText(); @@ -447,7 +449,8 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C return objects; } - protected enum MatchMode { + @VisibleForTesting + public enum MatchMode { NONE, INTENTION, NAME, DESCRIPTION, GROUP, NON_MENU }