From 328daa455a08ee5892deeab701e577ffa98d46e0 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Fri, 14 Mar 2014 12:56:00 +0400 Subject: [PATCH] fix HtmlCompletionTest.testXhtmlCompletionInHtml --- .../template/LiveTemplateTest.groovy | 40 +++++++++++-------- .../template/macro/BaseCompleteMacro.java | 8 +--- .../fixtures/CodeInsightTestUtil.java | 6 ++- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy index cef42e9ea06d..45cd2ebf01a4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy @@ -35,6 +35,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager import com.intellij.psi.codeStyle.CommonCodeStyleSettings import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.util.containers.ContainerUtil +import com.intellij.util.ui.UIUtil import org.jetbrains.annotations.NotNull import static com.intellij.codeInsight.template.Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE @@ -80,6 +81,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { addTemplate(template, testRootDisposable) manager.startTemplate(editor, (char)'\t'); + UIUtil.dispatchAllInvocationEvents() checkResultByText(expected); } @@ -110,6 +112,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { addTemplate(template, testRootDisposable) startTemplate(templateName, templateGroup) + UIUtil.dispatchAllInvocationEvents() if (firstDefaultValue.empty) myFixture.type("TestValue1") myFixture.type("\t") if (secondDefaultValue.empty) myFixture.type("TestValue2") @@ -137,9 +140,8 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("empty", "user", '$VAR$'); template.addVariable("VAR", "", "", false); - final Editor editor = getEditor(); - manager.startTemplate(editor, template); + startTemplate(template); checkResultByText(""); } @@ -150,9 +152,8 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { final Template template = manager.createTemplate("empty", "user", '$VAR$$END$'); template.addVariable("VAR", "bar", "bar", true); template.setToReformat(true); - final Editor editor = getEditor(); - manager.startTemplate(editor, template); + startTemplate(template); myFixture.type("foo"); checkResultByText("foo"); } @@ -168,7 +169,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { ' $END$\n' + 'foo()'); template.setToReformat(true); - manager.startTemplate(getEditor(), template); + startTemplate(template); checkResultByText("class C {\n" + " bar() {\n" + " foo()\n" + @@ -196,7 +197,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { "frame.pack();"); template.setToShortenLongNames(false); template.setToReformat(true); - manager.startTemplate(getEditor(), template); + startTemplate(template); checkResult(); } @@ -210,7 +211,7 @@ class Foo { final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("frm", "user", '$VAR$'); template.addVariable('VAR', new MacroCallNode(new CompleteMacro()), new EmptyNode(), true) - manager.startTemplate(getEditor(), template); + startTemplate(template); myFixture.type('fo\n') myFixture.checkResult ''' class Foo { @@ -231,7 +232,7 @@ class Foo { final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("frm", "user", '$VAR$'); template.addVariable('VAR', new MacroCallNode(new CompleteMacro()), new EmptyNode(), true) - manager.startTemplate(getEditor(), template); + startTemplate(template); myFixture.type('fo\n') myFixture.checkResult ''' class Foo { @@ -253,7 +254,7 @@ class Foo { final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("frm", "user", '$VAR$'); template.addVariable('VAR', new MacroCallNode(new ClassNameCompleteMacro()), new EmptyNode(), true) - manager.startTemplate(getEditor(), template); + startTemplate(template); assert !state.finished assert 'Bar' in myFixture.lookupElementStrings } @@ -278,7 +279,12 @@ class Foo { } def startTemplate(String name, String group) { - TemplateManager.getInstance(getProject()).startTemplate(getEditor(), TemplateSettings.getInstance().getTemplate(name, group)); + startTemplate(TemplateSettings.getInstance().getTemplate(name, group)); + } + + def startTemplate(Template template) { + TemplateManager.getInstance(getProject()).startTemplate(getEditor(), template) + UIUtil.dispatchAllInvocationEvents() } private static T contextType(Class clazz) { @@ -533,7 +539,7 @@ class Foo { template.addVariable("V3", "", "", true); final Editor editor = getEditor(); - writeCommand { manager.startTemplate(editor, template) } + writeCommand { startTemplate(template) } final TemplateState state = getState(); @@ -575,7 +581,7 @@ class Foo { template.addVariable("V1", "", "", true); template.addVariable("V2", "", '"239"', true); - writeCommand { manager.startTemplate(editor, template) } + writeCommand { startTemplate(template) } myFixture.checkResult ' var = 239;' @@ -659,7 +665,7 @@ class Foo { template.addVariable('T', new MacroCallNode(new MethodReturnTypeMacro()), new EmptyNode(), false) template.toReformat = true - manager.startTemplate(getEditor(), template); + startTemplate(template); assert myFixture.editor.document.text.contains('List> result;') } @@ -705,7 +711,7 @@ class Foo { final Template template = manager.createTemplate("xxx", "user", 'foo $ARG$ bar $END$ goo $SELECTION$ after'); template.addVariable("ARG", "", "", true); - manager.startTemplate(editor, template); + startTemplate(template); myFixture.type('arg') state.nextTab() assert !state @@ -731,7 +737,7 @@ class Foo { final Template template = manager.createTemplate("xxx", "user", 'foo.Bar.someMethod($END$)'); template.setValue(USE_STATIC_IMPORT_IF_POSSIBLE, true); - manager.startTemplate(editor, template); + startTemplate(template); myFixture.checkResult """ import static foo.Bar.someMethod; @@ -754,7 +760,7 @@ class Foo { template.addVariable('B', macroCallNode, false) myFixture.configureByText "a.txt", "" - manager.startTemplate(editor, template); + startTemplate(template); myFixture.type('-foo-bar_goo-') state.nextTab() assert !state @@ -779,7 +785,7 @@ class Foo { final Template template = manager.createTemplate("xxx", "user", 'foo.Bar.someMethod($END$)'); template.setValue(USE_STATIC_IMPORT_IF_POSSIBLE, true); - manager.startTemplate(editor, template); + startTemplate(template); myFixture.checkResult """import static foo.Bar.someMethod; class Foo { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java index 717724ce30d2..5aaf314aa369 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -99,11 +99,7 @@ public abstract class BaseCompleteMacro extends Macro { }, "", null); } }; - if (ApplicationManager.getApplication().isUnitTestMode()) { - runnable.run(); - } else { - ApplicationManager.getApplication().invokeLater(runnable); - } + ApplicationManager.getApplication().invokeLater(runnable); } private static void considerNextTab(Editor editor) { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java index d73a4d8aaf51..984324cc51e5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -44,6 +44,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler; import com.intellij.testFramework.TestDataFile; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -72,10 +73,12 @@ public class CodeInsightTestUtil { return null; } + @TestOnly public static void doIntentionTest(CodeInsightTestFixture fixture, @NonNls String file, @NonNls String actionText) { doIntentionTest(fixture, actionText, file + ".xml", file + "_after.xml"); } + @TestOnly public static void doIntentionTest(@NotNull final CodeInsightTestFixture fixture, @NonNls final String action, @NotNull final String before, @NotNull final String after) { fixture.configureByFile(before); @@ -90,6 +93,7 @@ public class CodeInsightTestUtil { fixture.launchAction(intentionAction); } }.execute(); + UIUtil.dispatchAllInvocationEvents(); fixture.checkResultByFile(after, false); }