use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlInsightTest method testAttributeDescriptor1.
public void testAttributeDescriptor1() throws Exception {
XmlFile file = createFile("<root><a attr1=''></a><a attr2='' attr1=''></a></root>");
XmlNSDescriptor descriptor = createDescriptor(file);
XmlTag rootTag = file.getDocument().getRootTag();
XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
element = element.getElementsDescriptors(rootTag)[0];
XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
assertEquals("attr1", attributes[0].getName());
assertTrue(attributes[0].isRequired());
assertEquals("attr2", attributes[1].getName());
assertTrue(!attributes[1].isRequired());
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlInsightTest method testElementDescriptor2.
public void testElementDescriptor2() throws Exception {
XmlFile file = createFile("<root><a><b/></a><a><c/></a></root>");
XmlNSDescriptor descriptor = createDescriptor(file);
XmlTag rootTag = file.getDocument().getRootTag();
XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
element = element.getElementsDescriptors(rootTag)[0];
XmlElementDescriptor[] elements = element.getElementsDescriptors(rootTag.getSubTags()[0]);
assertEquals(2, elements.length);
assertEquals("b", elements[0].getName());
assertEquals("c", elements[1].getName());
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlDtdTest method testEmbeddedDtd1.
public void testEmbeddedDtd1() throws Exception {
XmlFile xmlFile = (XmlFile) createFile("test.xml", "<!DOCTYPE tv [ <!ELEMENT tv (date)*> <!ELEMENT date (#PCDATA)> ]> <tv></tv>");
final XmlTag tag = xmlFile.getDocument().getRootTag();
assertNotNull(tag);
final XmlElementDescriptor desc = xmlFile.getDocument().getRootTagNSDescriptor().getElementDescriptor(tag);
assertNotNull(desc);
final XmlElementDescriptor[] elements = desc.getElementsDescriptors(tag);
assertEquals(1, elements.length);
assertEquals("date", elements[0].getName());
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlTextTest method testDisplayToPhysical.
public void testDisplayToPhysical() throws Exception {
String xml = "<div>&abc</div>";
XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
XmlTag root = file.getDocument().getRootTag();
final XmlText text = root.getValue().getTextElements()[0];
assertEquals("&abc", text.getValue());
assertEquals(0, text.displayToPhysical(0));
assertEquals(5, text.displayToPhysical(1));
assertEquals(6, text.displayToPhysical(2));
assertEquals(7, text.displayToPhysical(3));
assertEquals(8, text.displayToPhysical(4));
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlTextTest method testPhysicalToDisplayIfHasGaps2.
public void testPhysicalToDisplayIfHasGaps2() throws Exception {
String xml = "<div>&abc</div>";
XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
XmlTag root = file.getDocument().getRootTag();
final XmlText text = root.getValue().getTextElements()[0];
assertEquals("&abc", text.getValue());
assertEquals(0, text.physicalToDisplay(0));
assertEquals(1, text.physicalToDisplay(5));
assertEquals(2, text.physicalToDisplay(6));
assertEquals(3, text.physicalToDisplay(7));
assertEquals(4, text.physicalToDisplay(8));
}
Aggregations