From f6af9462156e2abd89dbe17c8a4c97d9bc09c45e Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sun, 17 Nov 2013 02:36:14 -0800 Subject: [PATCH] Refactoring: extract common method --- .../jet/editor/TypedHandlerTest.java | 98 +++++++++++++------ 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java b/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java index 6eadd418582..acbe340f1e9 100644 --- a/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java +++ b/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java @@ -18,54 +18,77 @@ package org.jetbrains.jet.editor; import com.intellij.testFramework.EditorTestUtil; import com.intellij.testFramework.LightCodeInsightTestCase; +import org.jetbrains.jet.utils.ExceptionUtils; + +import java.io.IOException; public class TypedHandlerTest extends LightCodeInsightTestCase { - public void testTypeStringTemplateStart() throws Exception { - configureFromFileText("a.kt", "val x = \"$\""); - EditorTestUtil.performTypingAction(getEditor(), '{'); - checkResultByText("val x = \"${}\""); + public void testTypeStringTemplateStart() { + doCharTypeTest( + '{', + + "val x = \"$\"", + + "val x = \"${}\"" + ); } - public void testAutoIndentRightOpenBrace() throws Exception { - configureFromFileText("a.kt", - "fun test() {\n" + - "\n" + - "}"); - EditorTestUtil.performTypingAction(getEditor(), '{'); - checkResultByText( + public void testAutoIndentRightOpenBrace() { + doCharTypeTest( + '{', + + "fun test() {\n" + + "\n" + + "}", + "fun test() {\n" + " {}\n" + - "}"); + "}" + ); } - public void testAutoIndentLeftOpenBrace() throws Exception { - configureFromFileText("a.kt", - "fun test() {\n" + - " \n" + - "}"); - EditorTestUtil.performTypingAction(getEditor(), '{'); - checkResultByText( + public void testAutoIndentLeftOpenBrace() { + doCharTypeTest( + '{', + + "fun test() {\n" + + " \n" + + "}", + "fun test() {\n" + " {}\n" + - "}"); + "}" + ); } - public void testTypeStringTemplateStartWithCloseBraceAfter() throws Exception { - configureFromFileText("a.kt", "fun foo() { \"$\" }"); - EditorTestUtil.performTypingAction(getEditor(), '{'); - checkResultByText("fun foo() { \"${}\" }"); + public void testTypeStringTemplateStartWithCloseBraceAfter() { + doCharTypeTest( + '{', + + "fun foo() { \"$\" }", + + "fun foo() { \"${}\" }" + ); } - public void testTypeStringTemplateStartBeforeString() throws Exception { - configureFromFileText("a.kt", "fun foo() { \"$something\" }"); - EditorTestUtil.performTypingAction(getEditor(), '{'); - checkResultByText("fun foo() { \"${}something\" }"); + public void testTypeStringTemplateStartBeforeString() { + doCharTypeTest( + '{', + + "fun foo() { \"$something\" }", + + "fun foo() { \"${}something\" }" + ); } - public void testKT3575() throws Exception { - configureFromFileText("a.kt", "val x = \"$]\""); - EditorTestUtil.performTypingAction(getEditor(), '{'); - checkResultByText("val x = \"${}]\""); + public void testKT3575() { + doCharTypeTest( + '{', + + "val x = \"$]\"", + + "val x = \"${}]\"" + ); } public void testTypeLtInFunDeclaration() throws Exception { @@ -107,6 +130,17 @@ public class TypedHandlerTest extends LightCodeInsightTestCase { checkResultByText("val a: List>"); } + private void doCharTypeTest(char ch, String beforeText, String afterText) { + try { + configureFromFileText("a.kt", beforeText); + EditorTestUtil.performTypingAction(getEditor(), ch); + checkResultByText(afterText); + } + catch (IOException e) { + throw ExceptionUtils.rethrow(e); + } + } + private void doLtGtTestNoAutoClose(String initText) throws Exception { doLtGtTest(initText, false); }