From 3d7bbc0bde9ae5ab02918572800e765216fbaf5a Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 5 Dec 2014 20:51:37 +0300 Subject: [PATCH] Rewrite to Kotlin: TypedHandlerTest --- .../jetbrains/jet/editor/TypedHandlerTest.kt | 525 ++++++++---------- 1 file changed, 239 insertions(+), 286 deletions(-) diff --git a/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.kt b/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.kt index 01074e8a3d3..42d69297a78 100644 --- a/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.kt +++ b/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-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. @@ -14,321 +14,274 @@ * limitations under the License. */ -package org.jetbrains.jet.editor; +package org.jetbrains.jet.editor -import com.intellij.testFramework.EditorTestUtil; -import com.intellij.testFramework.LightCodeInsightTestCase; -import org.jetbrains.jet.utils.UtilsPackage; +import com.intellij.testFramework.EditorTestUtil +import com.intellij.testFramework.LightCodeInsightTestCase +import com.intellij.testFramework.LightPlatformCodeInsightTestCase -import java.io.IOException; +public class TypedHandlerTest : LightCodeInsightTestCase() { + val amp = '$' -public class TypedHandlerTest extends LightCodeInsightTestCase { - public void testTypeStringTemplateStart() { - doCharTypeTest( - '{', + public fun testTypeStringTemplateStart(): Unit = doCharTypeTest( + '{', + """val x = "$" """, + """val x = "$amp{}" """ + ) - "val x = \"$\"", + public fun testAutoIndentRightOpenBrace(): Unit = doCharTypeTest( + '{', - "val x = \"${}\"" - ); + "fun test() {\n" + + "\n" + + "}", + + "fun test() {\n" + + " {}\n" + + "}" + ) + + public fun testAutoIndentLeftOpenBrace(): Unit = doCharTypeTest( + '{', + + "fun test() {\n" + + " \n" + + "}", + + "fun test() {\n" + + " {}\n" + + "}" + ) + + public fun testTypeStringTemplateStartWithCloseBraceAfter(): Unit = doCharTypeTest( + '{', + """fun foo() { "$" }""", + """fun foo() { "$amp{}" }""" + ) + + public fun testTypeStringTemplateStartBeforeString(): Unit = doCharTypeTest( + '{', + """fun foo() { "$something" }""", + """fun foo() { "$amp{}something" }""" + ) + + public fun testKT3575(): Unit = doCharTypeTest( + '{', + """val x = "$]" """, + """val x = "$amp{}]" """ + ) + + public fun testAutoCloseBraceInFunctionDeclaration(): Unit = doCharTypeTest( + '{', + "fun foo() ", + "fun foo() {}" + ) + + public fun testAutoCloseBraceInLocalFunctionDeclaration(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " fun bar() \n" + + "}", + + "fun foo() {\n" + + " fun bar() {}\n" + + "}" + ) + + public fun testAutoCloseBraceInAssignment(): Unit = doCharTypeTest( + '{', + "fun foo() {\n" + + " val a = \n" + + "}", + + "fun foo() {\n" + + " val a = {}\n" + + "}" + ) + + public fun testDoNotAutoCloseBraceInUnfinishedIfSurroundOnSameLine(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " if() foo()\n" + + "}", + + "fun foo() {\n" + + " if() {foo()\n" + + "}" + ) + + public fun testDoNotAutoCloseBraceInUnfinishedWhileSurroundOnSameLine(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " while() foo()\n" + + "}", + + "fun foo() {\n" + + " while() {foo()\n" + + "}" + ) + + public fun testDoNotAutoCloseBraceInUnfinishedWhileSurroundOnNewLine(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " while()\n" + + "\n" + + " foo()\n" + + "}", + + "fun foo() {\n" + + " while()\n" + + " {\n" + + " foo()\n" + + "}" + ) + + public fun testDoNotAutoCloseBraceInUnfinishedIfSurroundOnOtherLine(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " if(true) \n" + + " foo()\n" + + "}", + + "fun foo() {\n" + + " if(true) {\n" + + " foo()\n" + + "}" + ) + + public fun testDoNotAutoCloseBraceInUnfinishedIfSurroundOnNewLine(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " if(true)\n" + + " \n" + + " foo()\n" + + "}", + + "fun foo() {\n" + + " if(true)\n" + + " {\n" + + " foo()\n" + + "}" + ) + + public fun testAutoCloseBraceInsideFor(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " for (elem in some.filter ) {\n" + + " }\n" + + "}", + + "fun foo() {\n" + + " for (elem in some.filter {}) {\n" + + " }\n" + + "}" + ) + + public fun testAutoCloseBraceInsideForAfterCloseParen(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " for (elem in some.foo(true) ) {\n" + + " }\n" + + "}", + + "fun foo() {\n" + + " for (elem in some.foo(true) {}) {\n" + + " }\n" + + "}" + ) + + public fun testAutoCloseBraceBeforeIf(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " if (true) {}\n" + + "}", + + "fun foo() {\n" + + " {if (true) {}\n" + + "}" + ) + + public fun testAutoCloseBraceInIfCondition(): Unit = doCharTypeTest( + '{', + + "fun foo() {\n" + + " if (some.hello (12) )\n" + + "}", + + "fun foo() {\n" + + " if (some.hello (12) {})\n" + + "}" + ) + + public fun testTypeLtInFunDeclaration() { + doLtGtTest("fun ") } - public void testAutoIndentRightOpenBrace() { - doCharTypeTest( - '{', - - "fun test() {\n" + - "\n" + - "}", - - "fun test() {\n" + - " {}\n" + - "}" - ); + public fun testTypeLtInOngoingConstructorCall() { + doLtGtTest("fun test() { Collection }") } - public void testAutoIndentLeftOpenBrace() { - doCharTypeTest( - '{', - - "fun test() {\n" + - " \n" + - "}", - - "fun test() {\n" + - " {}\n" + - "}" - ); + public fun testTypeLtInClassDeclaration() { + doLtGtTest("class Some {}") } - public void testTypeStringTemplateStartWithCloseBraceAfter() { - doCharTypeTest( - '{', - - "fun foo() { \"$\" }", - - "fun foo() { \"${}\" }" - ); + public fun testTypeLtInPropertyType() { + doLtGtTest("val a: List ") } - public void testTypeStringTemplateStartBeforeString() { - doCharTypeTest( - '{', - - "fun foo() { \"$something\" }", - - "fun foo() { \"${}something\" }" - ); + public fun testTypeLtInExtensionFunctionReceiver() { + doLtGtTest("fun Collection ") } - public void testKT3575() { - doCharTypeTest( - '{', - - "val x = \"$]\"", - - "val x = \"${}]\"" - ); + public fun testTypeLtInFunParam() { + doLtGtTest("fun some(a : HashSet)") } - public void testAutoCloseBraceInFunctionDeclaration() { - doCharTypeTest( - '{', - - "fun foo() ", - - "fun foo() {}" - ); + public fun testTypeLtInFun() { + doLtGtTestNoAutoClose("fun some() { < }") } - public void testAutoCloseBraceInLocalFunctionDeclaration() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " fun bar() \n" + - "}", - - "fun foo() {\n" + - " fun bar() {}\n" + - "}" - ); + public fun testTypeLtInLess() { + doLtGtTestNoAutoClose("fun some() { val a = 12; a < }") } - public void testAutoCloseBraceInAssignment() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " val a = \n" + - "}", - - "fun foo() {\n" + - " val a = {}\n" + - "}" - ); + public fun testMoveThroughGT() { + LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List>>") + EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>') + EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>') + checkResultByText("val a: List>") } - public void testDoNotAutoCloseBraceInUnfinishedIfSurroundOnSameLine() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " if() foo()\n" + - "}", - - "fun foo() {\n" + - " if() {foo()\n" + - "}" - ); + private fun doCharTypeTest(ch: Char, beforeText: String, afterText: String) { + LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", beforeText) + EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), ch) + checkResultByText(afterText) } - public void testDoNotAutoCloseBraceInUnfinishedWhileSurroundOnSameLine() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " while() foo()\n" + - "}", - - "fun foo() {\n" + - " while() {foo()\n" + - "}" - ); + private fun doLtGtTestNoAutoClose(initText: String) { + doLtGtTest(initText, false) } - public void testDoNotAutoCloseBraceInUnfinishedWhileSurroundOnNewLine() { - doCharTypeTest( - '{', + private fun doLtGtTest(initText: String, shouldCloseBeInsert: Boolean) { + LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", initText) - "fun foo() {\n" + - " while()\n" + - "\n" + - " foo()\n" + - "}", + EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '<') + checkResultByText(if (shouldCloseBeInsert) initText.replace("", "<>") else initText.replace("", "<")) - "fun foo() {\n" + - " while()\n" + - " {\n" + - " foo()\n" + - "}" - ); + EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), EditorTestUtil.BACKSPACE_FAKE_CHAR) + checkResultByText(initText) } - public void testDoNotAutoCloseBraceInUnfinishedIfSurroundOnOtherLine() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " if(true) \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " if(true) {\n" + - " foo()\n" + - "}" - ); - } - - public void testDoNotAutoCloseBraceInUnfinishedIfSurroundOnNewLine() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " if(true)\n" + - " \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " if(true)\n" + - " {\n" + - " foo()\n" + - "}" - ); - } - - public void testAutoCloseBraceInsideFor() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " for (elem in some.filter ) {\n" + - " }\n" + - "}", - - "fun foo() {\n" + - " for (elem in some.filter {}) {\n" + - " }\n" + - "}" - ); - } - - public void testAutoCloseBraceInsideForAfterCloseParen() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " for (elem in some.foo(true) ) {\n" + - " }\n" + - "}", - - "fun foo() {\n" + - " for (elem in some.foo(true) {}) {\n" + - " }\n" + - "}" - ); - } - - public void testAutoCloseBraceBeforeIf() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " if (true) {}\n" + - "}", - - "fun foo() {\n" + - " {if (true) {}\n" + - "}" - ); - } - - public void testAutoCloseBraceInIfCondition() { - doCharTypeTest( - '{', - - "fun foo() {\n" + - " if (some.hello (12) )\n" + - "}", - - "fun foo() {\n" + - " if (some.hello (12) {})\n" + - "}" - ); - } - - public void testTypeLtInFunDeclaration() throws Exception { - doLtGtTest("fun "); - } - - public void testTypeLtInOngoingConstructorCall() throws Exception { - doLtGtTest("fun test() { Collection }"); - } - - public void testTypeLtInClassDeclaration() throws Exception { - doLtGtTest("class Some {}"); - } - - public void testTypeLtInPropertyType() throws Exception { - doLtGtTest("val a: List "); - } - - public void testTypeLtInExtensionFunctionReceiver() throws Exception { - doLtGtTest("fun Collection "); - } - - public void testTypeLtInFunParam() throws Exception { - doLtGtTest("fun some(a : HashSet)"); - } - - public void testTypeLtInFun() throws Exception { - doLtGtTestNoAutoClose("fun some() { < }"); - } - - public void testTypeLtInLess() throws Exception { - doLtGtTestNoAutoClose("fun some() { val a = 12; a < }"); - } - - public void testMoveThroughGT() throws Exception { - configureFromFileText("a.kt", "val a: List>>"); - EditorTestUtil.performTypingAction(getEditor(), '>'); - EditorTestUtil.performTypingAction(getEditor(), '>'); - checkResultByText("val a: List>"); - } - - private void doCharTypeTest(char ch, String beforeText, String afterText) { - configureFromFileText("a.kt", beforeText); - EditorTestUtil.performTypingAction(getEditor(), ch); - checkResultByText(afterText); - } - - private void doLtGtTestNoAutoClose(String initText) throws Exception { - doLtGtTest(initText, false); - } - - private void doLtGtTest(String initText, boolean shouldCloseBeInsert) throws Exception { - configureFromFileText("a.kt", initText); - - EditorTestUtil.performTypingAction(getEditor(), '<'); - checkResultByText(shouldCloseBeInsert ? initText.replace("", "<>") : initText.replace("", "<")); - - EditorTestUtil.performTypingAction(getEditor(), EditorTestUtil.BACKSPACE_FAKE_CHAR); - checkResultByText(initText); - } - - private void doLtGtTest(String initText) throws Exception { - doLtGtTest(initText, true); + private fun doLtGtTest(initText: String) { + doLtGtTest(initText, true) } }