package com.intellij.codeInsight; import com.intellij.openapi.editor.actionSystem.TypedAction; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.testFramework.LightPlatformCodeInsightTestCase; public abstract class AbstractBasicJavaQuoteTest extends LightPlatformCodeInsightTestCase { public void testDouble1() { doTest("", "\"\""); } public void testDouble2() { doTest("\"\"", "\"\"\"\""); } public void testDoubleClosing() { doTest("\"\"", "\"\""); } public void testDoubleClosingWithText() { doTest("\"text\"", "\"text\""); } public void testDoubleEscape() { doTest(" \"\\\" ", " \"\\\"\" "); } public void testDoubleEscapeClosing() { doTest(" \"\\\\\" ", " \"\\\\\" "); } public void testBeforeIdentifier() { doTest("foo(a);", "foo(\"a);"); } public void testDoubleInString() { doTest("\"Hello\" world\";", "\"Hello\"\" world\";"); } public void testBeforeStringWithEscape() { doTest("foo(P + \"\\n\" + \"xxx\" + E)", "foo(P + \"\"\"\\n\" + \"xxx\" + E)"); } public void testSingleInString() { doTest(" \"\" ", " \"'\" ", '\''); } public void testSingleInComment() { doTest("/* */", "/* ' */", '\''); } public void testSingleInStringAfterEscape() { doTest(" split(text, '\\); ", " split(text, '\\'); ", '\''); } public void testDoubleQuoteInTextBlock() { doTest(" \"\"\" \"\"\" ", " \"\"\" \" \"\"\" "); } public void testSingleQuoteInTextBlock() { doTest(" \"\"\" \"\"\" ", " \"\"\" ' \"\"\" ", '\''); } public void testTextBlockClosing() { doTest(" \"\"\".\"\"\" ", " \"\"\".\"\"\" "); doTest(" \"\"\".\"\"\" ", " \"\"\".\"\"\" "); doTest(" \"\"\".\"\"\" ", " \"\"\".\"\"\" "); } private void doTest(String before, String after, char c) { doFileTest("class C {{\n " + before + "\n}}", "class C {{\n " + after + "\n}}", c); } protected void doTest(String before, String after) { doTest(before, after, '\"'); } protected void doFileTest(String completeBefore, String expectedResult, char c) { configureFromFileText("a.java", completeBefore); TypedAction.getInstance().actionPerformed(getEditor(), c, ((EditorEx)getEditor()).getDataContext()); checkResultByText(expectedResult); } @SuppressWarnings("SameParameterValue") protected void doFileTest(String completeBefore, String expectedResult) { doFileTest(completeBefore, expectedResult, '\"'); } }