From 0430d0cdc074dc5650c9da747a71c37809d59f58 Mon Sep 17 00:00:00 2001 From: Andrey Dernov Date: Thu, 7 Jul 2016 09:32:18 +0300 Subject: [PATCH] Test for IDEA-158139 --- .../template/LiveTemplateTest.groovy | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) 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 93b27b312e19..3bd363b46d41 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy @@ -18,6 +18,7 @@ package com.intellij.codeInsight.template import com.intellij.JavaTestUtil import com.intellij.codeInsight.CodeInsightSettings import com.intellij.codeInsight.completion.CompletionType +import com.intellij.codeInsight.daemon.impl.quickfix.EmptyExpression import com.intellij.codeInsight.lookup.Lookup import com.intellij.codeInsight.lookup.LookupManager import com.intellij.codeInsight.template.impl.* @@ -276,6 +277,94 @@ class Foo { assert !state } + public void "test not to go to next tab after insert if element is a psi package"() { + myFixture.configureByText 'a.java', ''' + +''' + final TemplateManager manager = TemplateManager.getInstance(getProject()); + final Template template = manager.createTemplate("imp", "user", 'import $MODIFIER$ java.$NAME$;'); + template.addVariable('NAME', new MacroCallNode(new CompleteMacro(true)), new EmptyNode(), true) + template.addVariable('MODIFIER', new EmptyExpression(), true) + startTemplate(template); + myFixture.type('uti\n') + myFixture.checkResult ''' +import java.util.; +''' + assert !state.finished + } + + public void "test not to go to next tab after insert if element has call arguments"() { + myFixture.configureByText 'a.java', ''' +import java.util.*; +public class Main { + List getStringList(int i){ + List ints = null; + + return new ArrayList<>(i); + } +} +''' + final TemplateManager manager = TemplateManager.getInstance(getProject()); + final Template template = manager.createTemplate("for", "user", 'for ($ELEMENT_TYPE$ $VAR$ : $ITERABLE_TYPE$) {\n' + + '$END$;\n' + + '}'); + template.addVariable('ITERABLE_TYPE', new MacroCallNode(new CompleteSmartMacro()), new EmptyNode(), true) + template.addVariable('VAR', new TextExpression("item"), true) + template.addVariable('ELEMENT_TYPE', new TextExpression("String"), true); + template.setToReformat(true) + startTemplate(template); + myFixture.type('get\n') + myFixture.checkResult """ +import java.util.*; +public class Main { + List getStringList(int i){ + List ints = null; + for (String item : getStringList()) { + ; + } + return new ArrayList<>(i); + } +} +""" + assert !state.finished + } + + public void "test go to next tab after insert if element does not have call arguments"() { + myFixture.configureByText 'a.java', ''' +import java.util.*; +public class Main { + List getStringList(int i){ + List ints = null; + + return new ArrayList<>(i); + } +} +''' + final TemplateManager manager = TemplateManager.getInstance(getProject()); + final Template template = manager.createTemplate("for", "user", 'for ($ELEMENT_TYPE$ $VAR$ : $ITERABLE_TYPE$) {\n' + + '$END$;\n' + + '}'); + template.addVariable('ITERABLE_TYPE', new MacroCallNode(new CompleteSmartMacro()), new EmptyNode(), true) + template.addVariable('VAR', new TextExpression("item"), true) + template.addVariable('ELEMENT_TYPE', new TextExpression("String"), true); + template.setToReformat(true) + startTemplate(template); + myFixture.type('in\n') + myFixture.checkResult """ +import java.util.*; +public class Main { + List getStringList(int i){ + List ints = null; + for (String item : ints) { + ; + } + return new ArrayList<>(i); + } +} +""" + assert !state.finished + } + public void "test non-imported classes in className macro"() { myFixture.addClass('package bar; public class Bar {}') myFixture.configureByText 'a.java', ''' @@ -1086,7 +1175,7 @@ class Foo {{ class Foo {{ for (int a = 0; a < array.length; a++) { = array[a]; - + } }} """