mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DOM stubs: more tests
This commit is contained in:
@@ -38,7 +38,7 @@ public class AttributeStubSerializer implements ObjectStubSerializer<AttributeSt
|
||||
@Override
|
||||
public void serialize(AttributeStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeUTFFast(stub.getValue());
|
||||
dataStream.writeUTFFast(stub.getValue() == null ? "" : stub.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<foo>
|
||||
<bar string></bar>
|
||||
</foo>
|
||||
@@ -0,0 +1,3 @@
|
||||
<foo>
|
||||
<bar notStubbed = "foo"/>
|
||||
</foo>
|
||||
@@ -1,11 +1,6 @@
|
||||
package com.intellij.util.xml.stubs;
|
||||
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.stubs.ObjectStubTree;
|
||||
import com.intellij.psi.stubs.StubTreeLoader;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.xml.XmlName;
|
||||
import com.intellij.util.xml.reflect.DomExtender;
|
||||
@@ -26,12 +21,19 @@ public class DomStubBuilderTest extends DomStubTest {
|
||||
}
|
||||
|
||||
public void testFoo() throws Exception {
|
||||
doTest("foo.xml", "File:foo\n" +
|
||||
" Element:foo\n" +
|
||||
" Element:bar\n" +
|
||||
" Attribute:string:xxx\n" +
|
||||
" Attribute:int:666\n" +
|
||||
" Element:bar\n");
|
||||
doBuilderTest("foo.xml", "File:foo\n" +
|
||||
" Element:foo\n" +
|
||||
" Element:bar\n" +
|
||||
" Attribute:string:xxx\n" +
|
||||
" Attribute:int:666\n" +
|
||||
" Element:bar\n");
|
||||
}
|
||||
|
||||
public void testIncompleteAttribute() throws Exception {
|
||||
doBuilderTest("incompleteAttribute.xml", "File:foo\n" +
|
||||
" Element:foo\n" +
|
||||
" Element:bar\n" +
|
||||
" Attribute:string:\n");
|
||||
}
|
||||
|
||||
public void testDomExtension() throws Exception {
|
||||
@@ -40,11 +42,11 @@ public class DomStubBuilderTest extends DomStubTest {
|
||||
ep.extenderClassName = TestExtender.class.getName();
|
||||
PlatformTestUtil.registerExtension(Extensions.getRootArea(), DomExtenderEP.EP_NAME, ep, myTestRootDisposable);
|
||||
|
||||
doTest("extender.xml", "File:foo\n" +
|
||||
" Element:foo\n" +
|
||||
" Element:bar\n" +
|
||||
" Attribute:extend:xxx\n" +
|
||||
" Element:bar\n");
|
||||
doBuilderTest("extender.xml", "File:foo\n" +
|
||||
" Element:foo\n" +
|
||||
" Element:bar\n" +
|
||||
" Attribute:extend:xxx\n" +
|
||||
" Element:bar\n");
|
||||
}
|
||||
|
||||
public static class TestExtender extends DomExtender<Bar> {
|
||||
@@ -54,22 +56,4 @@ public class DomStubBuilderTest extends DomStubTest {
|
||||
registrar.registerAttributeChildExtension(new XmlName("extend"), Custom.class);
|
||||
}
|
||||
}
|
||||
|
||||
private ElementStub getRootStub(String filePath) {
|
||||
PsiFile psiFile = myFixture.configureByFile(filePath);
|
||||
|
||||
StubTreeLoader loader = StubTreeLoader.getInstance();
|
||||
VirtualFile file = psiFile.getVirtualFile();
|
||||
assertTrue(loader.canHaveStub(file));
|
||||
ObjectStubTree stubTree = loader.readFromVFile(getProject(), file);
|
||||
assertNotNull(stubTree);
|
||||
ElementStub root = (ElementStub)stubTree.getRoot();
|
||||
assertNotNull(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
private void doTest(String file, String stubText) {
|
||||
ElementStub stub = getRootStub(file);
|
||||
assertEquals(stubText, DebugUtil.stubTreeToString(stub));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
*/
|
||||
package com.intellij.util.xml.stubs;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.stubs.ObjectStubTree;
|
||||
import com.intellij.psi.stubs.StubTreeLoader;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.xml.DomFileDescription;
|
||||
import com.intellij.util.xml.DomManager;
|
||||
@@ -44,4 +49,22 @@ public abstract class DomStubTest extends LightCodeInsightFixtureTestCase {
|
||||
protected String getBasePath() {
|
||||
return "/xml/dom-tests/testData/stubs";
|
||||
}
|
||||
|
||||
protected ElementStub getRootStub(String filePath) {
|
||||
PsiFile psiFile = myFixture.configureByFile(filePath);
|
||||
|
||||
StubTreeLoader loader = StubTreeLoader.getInstance();
|
||||
VirtualFile file = psiFile.getVirtualFile();
|
||||
assertTrue(loader.canHaveStub(file));
|
||||
ObjectStubTree stubTree = loader.readFromVFile(getProject(), file);
|
||||
assertNotNull(stubTree);
|
||||
ElementStub root = (ElementStub)stubTree.getRoot();
|
||||
assertNotNull(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
protected void doBuilderTest(String file, String stubText) {
|
||||
ElementStub stub = getRootStub(file);
|
||||
assertEquals(stubText, DebugUtil.stubTreeToString(stub));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.stubs.StubTreeLoader;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import com.intellij.util.xml.DomFileElement;
|
||||
import com.intellij.util.xml.DomManager;
|
||||
import com.intellij.util.xml.GenericAttributeValue;
|
||||
@@ -94,6 +95,14 @@ public class DomStubUsingTest extends DomStubTest {
|
||||
assertFalse(element.getFile().getNode().isParsed());
|
||||
}
|
||||
|
||||
public void testParent() throws Exception {
|
||||
DomFileElement<Foo> element = prepare("parent.xml");
|
||||
Bar bar = element.getRootElement().getBars().get(0);
|
||||
GenericAttributeValue<Integer> notStubbed = bar.getNotStubbed();
|
||||
DomElement parent = notStubbed.getParent();
|
||||
assertEquals(bar, parent);
|
||||
}
|
||||
|
||||
private DomFileElement<Foo> prepare(String path) {
|
||||
PsiFile file = myFixture.configureByFile(path);
|
||||
assertFalse(file.getNode().isParsed());
|
||||
|
||||
@@ -34,4 +34,6 @@ public interface Bar extends DomElement {
|
||||
@Stubbed
|
||||
@Attribute("class")
|
||||
GenericAttributeValue<PsiClass> getClazz();
|
||||
|
||||
GenericAttributeValue<Integer> getNotStubbed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user