public void testCompositeTagWithDeadlock() throws ParserException { createParser( "<custom>" + "<another>something" + "</custom>" + "<custom>" + "<another>else</another>" + "</custom>"); parser.setNodeFactory( new PrototypicalNodeFactory( new Tag[] { new CustomTag(), new AnotherTag(true), })); parseAndAssertNodeCount(2); assertType("node", CustomTag.class, node[0]); CustomTag customTag = (CustomTag) node[0]; assertEquals("child count", 1, customTag.getChildCount()); assertFalse("custom tag should not be xml end tag", customTag.isEmptyXmlTag()); assertEquals("starting loc", 0, customTag.getStartPosition()); assertEquals("ending loc", 8, customTag.getEndPosition()); assertEquals("starting line position", 0, customTag.getStartingLineNumber()); assertEquals("ending line position", 0, customTag.getEndingLineNumber()); AnotherTag anotherTag = (AnotherTag) customTag.childAt(0); assertEquals("anotherTag child count", 1, anotherTag.getChildCount()); Text stringNode = (Text) anotherTag.childAt(0); assertStringEquals("anotherTag child text", "something", stringNode.toPlainTextString()); assertStringEquals( "first custom tag html", "<custom><another>something</another></custom>", customTag.toHtml()); customTag = (CustomTag) node[1]; assertStringEquals( "second custom tag html", "<custom><another>else</another></custom>", customTag.toHtml()); }
public void testCompositeTagWithTwoNestedTags() throws ParserException { createParser( "<Custom>" + "<Another>" + "Hello" + "</Another>" + "<unknown>" + "World" + "</unknown>" + "<Custom/>" + "</Custom>" + "<Custom/>"); parser.setNodeFactory( new PrototypicalNodeFactory( new Tag[] { new CustomTag(), new AnotherTag(false), })); parseAndAssertNodeCount(2); assertType("first node", CustomTag.class, node[0]); assertType("second node", CustomTag.class, node[1]); CustomTag customTag = (CustomTag) node[0]; assertEquals("first custom tag children count", 5, customTag.getChildCount()); Node node = customTag.childAt(0); assertType("first child", AnotherTag.class, node); AnotherTag anotherTag = (AnotherTag) node; assertEquals("another tag children count", 1, anotherTag.getChildCount()); node = anotherTag.childAt(0); assertType("nested child", Text.class, node); Text text = (Text) node; assertEquals("text", "Hello", text.toPlainTextString()); }
public void testCompositeTagCorrectionWithSplitLines() throws ParserException { createParser("<custom>" + "<another><abcdefg>\n" + "</custom>"); parser.setNodeFactory( new PrototypicalNodeFactory( new Tag[] { new CustomTag(), new AnotherTag(true), })); parseAndAssertNodeCount(1); assertType("node", CustomTag.class, node[0]); CustomTag customTag = (CustomTag) node[0]; assertEquals("child count", 1, customTag.getChildCount()); assertFalse("custom tag should not be xml end tag", customTag.isEmptyXmlTag()); assertEquals("starting loc", 0, customTag.getStartPosition()); assertEquals("ending loc", 8, customTag.getEndPosition()); AnotherTag anotherTag = (AnotherTag) customTag.childAt(0); assertEquals("anotherTag child count", 2, anotherTag.getChildCount()); assertEquals("anotherTag end loc", 27, anotherTag.getEndTag().getEndPosition()); assertEquals("custom end tag begin loc", 27, customTag.getEndTag().getStartPosition()); assertEquals("custom end tag end loc", 36, customTag.getEndTag().getEndPosition()); }
public void testCompositeTagWithErroneousAnotherTagAndLineBreak() throws ParserException { String another = "<another>"; String custom = "<custom>\n</custom>"; createParser(another + custom); parser.setNodeFactory( new PrototypicalNodeFactory( new Tag[] { new CustomTag(), new AnotherTag(false), })); parseAndAssertNodeCount(2); AnotherTag anotherTag = (AnotherTag) node[0]; assertEquals("another tag child count", 0, anotherTag.getChildCount()); CustomTag customTag = (CustomTag) node[1]; assertEquals("child count", 1, customTag.getChildCount()); assertFalse("custom tag should not be xml end tag", customTag.isEmptyXmlTag()); assertEquals("starting loc", 9, customTag.getStartPosition()); assertEquals("ending loc", 17, customTag.getEndPosition()); assertEquals("starting line position", 0, customTag.getStartingLineNumber()); assertEquals("ending line position", 1, customTag.getEndTag().getEndingLineNumber()); assertStringEquals("another tag html", another + "</another>", anotherTag.toHtml()); assertStringEquals("custom tag html", custom, customTag.toHtml()); }