mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Xml folding tests
This commit is contained in:
@@ -180,7 +180,8 @@ public class XmlFoldingBuilder implements FoldingBuilder, DumbAware {
|
||||
}
|
||||
}
|
||||
else if (element instanceof XmlAttribute) {
|
||||
return element.getTextRange();
|
||||
final XmlAttributeValue valueElement = ((XmlAttribute)element).getValueElement();
|
||||
return valueElement != null ? valueElement.getValueTextRange() : null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -205,9 +206,13 @@ public class XmlFoldingBuilder implements FoldingBuilder, DumbAware {
|
||||
range.getEndOffset() <= document.getTextLength() // psi and document maybe not in sync after error
|
||||
) {
|
||||
|
||||
if (range.getStartOffset() + MIN_TEXT_RANGE_LENGTH < range.getEndOffset()) {
|
||||
foldings.add(new FoldingDescriptor(elementToFold.getNode(), range));
|
||||
return true;
|
||||
int startLine = document.getLineNumber(range.getStartOffset());
|
||||
int endLine = document.getLineNumber(range.getEndOffset() - 1);
|
||||
if (startLine < endLine || elementToFold instanceof XmlAttribute) {
|
||||
if (range.getStartOffset() + MIN_TEXT_RANGE_LENGTH < range.getEndOffset()) {
|
||||
foldings.add(new FoldingDescriptor(elementToFold.getNode(), range));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,12 +221,9 @@ public class XmlFoldingBuilder implements FoldingBuilder, DumbAware {
|
||||
|
||||
public String getPlaceholderText(@NotNull ASTNode node) {
|
||||
final PsiElement psi = node.getPsi();
|
||||
if(psi instanceof XmlAttribute) {
|
||||
final String attributeName = ((XmlAttribute)psi).getName();
|
||||
return attributeName.isEmpty() ? "..." : attributeName;
|
||||
}
|
||||
if (psi instanceof XmlTag ||
|
||||
psi instanceof XmlComment ||
|
||||
psi instanceof XmlAttribute ||
|
||||
psi instanceof XmlConditionalSection
|
||||
) return "...";
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.xml;
|
||||
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* User: zolotov
|
||||
* Date: 8/3/12
|
||||
*/
|
||||
public class XmlFoldingTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
|
||||
public void testTagFolding() throws Throwable { doTest(); }
|
||||
|
||||
public void testStyleAttributeFolding() throws Throwable { doTest(); }
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
public XmlFoldingTest() {
|
||||
IdeaTestCase.initPlatformPrefix();
|
||||
}
|
||||
|
||||
private void doTest() throws Throwable {
|
||||
myFixture.testFolding(getTestDataPath() + getTestName(true) + ".html");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/xml/tests/testData/folding/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + getBasePath();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<html<fold text='...'>>
|
||||
<body class="c1" id="#seriou" style="<fold text='...'>border: 1px solid black;</fold>"<fold text='...'>>
|
||||
<strong style="<fold text='...'>color: rgb(51,51,51);</fold>"/>
|
||||
</body</fold>>
|
||||
</html</fold>>
|
||||
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html<fold text='...'>>
|
||||
<head<fold text='...'>>
|
||||
<title>Title</title>
|
||||
</head</fold>>
|
||||
<body class="container"<fold text='...'>>
|
||||
<p>this is a</p>
|
||||
<p<fold text='...'>>
|
||||
test
|
||||
</p</fold>>
|
||||
</body</fold>>
|
||||
</html</fold>>
|
||||
Reference in New Issue
Block a user