diff --git a/xml/tests/src/com/intellij/codeInsight/XmlEnterActionTest.java b/xml/tests/src/com/intellij/codeInsight/XmlEnterActionTest.java new file mode 100644 index 000000000000..acf154b57f6d --- /dev/null +++ b/xml/tests/src/com/intellij/codeInsight/XmlEnterActionTest.java @@ -0,0 +1,113 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.codeInsight; + +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.formatter.xml.XmlCodeStyleSettings; +import com.intellij.testFramework.PlatformTestUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public class XmlEnterActionTest extends AbstractEnterActionTestCase { + @Override + protected @NotNull String getTestDataPath() { + return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/xml/tests/testData"; + } + + public void testInXml1() { + String path = "/codeInsight/enterAction/xml/"; + + configureByFile(path + "state0.xml"); + performAction(); + checkResultByFile(path + "state1.xml"); + } + + public void testInXml2() { + String path = "/codeInsight/enterAction/xml/"; + + configureByFile(path + "state2.xml"); + performAction(); + PsiDocumentManager.getInstance(getProject()).commitDocument(getEditor().getDocument()); + assertEquals(getFile().getText(), getEditor().getDocument().getText()); + //checkResultByFile(path + "state3.xml"); + } + + public void testInXml3() { + String path = "/codeInsight/enterAction/xml/"; + + configureByFile(path + "state4.xml"); + performAction(); + PsiDocumentManager.getInstance(getProject()).commitDocument(getEditor().getDocument()); + assertEquals(getFile().getText(), getEditor().getDocument().getText()); + // checkResultByFile(path + "state5.xml"); + } + + public void testInXml4() { + getCodeStyleSettings().getCustomSettings(XmlCodeStyleSettings.class).XML_ALIGN_ATTRIBUTES = true; + String path = "/codeInsight/enterAction/xml/"; + + configureByFile(path + "before1.xml"); + performAction(); + checkResultByFile(path + "after1.xml"); + } + + public void testIndentInXmlInfiniteLoop() { + configureByFile("/codeInsight/enterAction/indent/XmlInfiniteLoop.xml"); + performAction(); + } + + public void testSCR19905() { + configureByFile("/codeInsight/enterAction/SCR19905.xml"); + performAction(); + assertEquals(getEditor().getDocument().getText(), getFile().getText()); + } + + public void testHtml1() { + configureByFile("/codeInsight/enterAction/html/1.html"); + performAction(); + checkResultByFile(null, "/codeInsight/enterAction/html/1_after.html", false); + } + + public void testHtml2() { + configureByFile("/codeInsight/enterAction/html/2.html"); + performAction(); + checkResultByFile(null, "/codeInsight/enterAction/html/2_after.html", false); + } + + public void testBeginOfTag() { + doTextTest("xml", "\n" + " \n" + " \n" + "", + "\n" + " \n" + " \n" + " \n" + ""); + } + + public void testAssertionInXml() { + doTextTest("xml", "", ""); + } + + public void testEnterAtTheEndOfFile() { + doTextTest("xml", "\n" + " ", "\n" + " \n" + " "); + } + + public void testEnterAfterEmptyTag() { + doTextTest("html", + "
\n" + + " \n" + + " \n" + + " ", + "
\n" + + " \n" + + " \n" + + " \n" + + "
"); + } + + public void testWeb6656() { + doTextTest( + "html", + + "", + + "\n" + + "" + ); + } +} diff --git a/xml/tests/testData/codeInsight/enterAction/SCR19905.xml b/xml/tests/testData/codeInsight/enterAction/SCR19905.xml new file mode 100644 index 000000000000..efeeb807832c --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/SCR19905.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/html/1.html b/xml/tests/testData/codeInsight/enterAction/html/1.html new file mode 100644 index 000000000000..c2be00f88713 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/html/1.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/html/1_after.html b/xml/tests/testData/codeInsight/enterAction/html/1_after.html new file mode 100644 index 000000000000..96e886b6c553 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/html/1_after.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/html/2.html b/xml/tests/testData/codeInsight/enterAction/html/2.html new file mode 100644 index 000000000000..246da16acd93 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/html/2.html @@ -0,0 +1,4 @@ + +
+ Cancel (L10n) + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/html/2_after.html b/xml/tests/testData/codeInsight/enterAction/html/2_after.html new file mode 100644 index 000000000000..827b70066675 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/html/2_after.html @@ -0,0 +1,5 @@ + + + Cancel (L10n) + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/indent/XmlInfiniteLoop.xml b/xml/tests/testData/codeInsight/enterAction/indent/XmlInfiniteLoop.xml new file mode 100644 index 000000000000..f779154991bc --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/indent/XmlInfiniteLoop.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/after1.xml b/xml/tests/testData/codeInsight/enterAction/xml/after1.xml new file mode 100644 index 000000000000..7c404658edbb --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/after1.xml @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/before1.xml b/xml/tests/testData/codeInsight/enterAction/xml/before1.xml new file mode 100644 index 000000000000..114efd6df183 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/before1.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/state0.xml b/xml/tests/testData/codeInsight/enterAction/xml/state0.xml new file mode 100644 index 000000000000..096ceb5b33f6 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/state0.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/state1.xml b/xml/tests/testData/codeInsight/enterAction/xml/state1.xml new file mode 100644 index 000000000000..c46434beec70 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/state1.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/state2.xml b/xml/tests/testData/codeInsight/enterAction/xml/state2.xml new file mode 100644 index 000000000000..d960481a9183 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/state2.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/state3.xml b/xml/tests/testData/codeInsight/enterAction/xml/state3.xml new file mode 100644 index 000000000000..6d9db9d04ce8 --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/state3.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/state4.xml b/xml/tests/testData/codeInsight/enterAction/xml/state4.xml new file mode 100644 index 000000000000..62e9bb0a13ef --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/state4.xml @@ -0,0 +1,5 @@ + + + </a> + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/test1-state0.xml b/xml/tests/testData/codeInsight/enterAction/xml/test1-state0.xml new file mode 100644 index 000000000000..efeeb807832c --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/test1-state0.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/xml/tests/testData/codeInsight/enterAction/xml/test1-state1.xml b/xml/tests/testData/codeInsight/enterAction/xml/test1-state1.xml new file mode 100644 index 000000000000..9188739f817f --- /dev/null +++ b/xml/tests/testData/codeInsight/enterAction/xml/test1-state1.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file