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 testParentConnections() throws ParserException { String tag1 = "<custom>"; String tag2 = "<custom>something</custom>"; String tag3 = "</custom>"; createParser(tag1 + tag2 + tag3); parser.setNodeFactory( new PrototypicalNodeFactory( new Tag[] { new CustomTag(false), new AnotherTag(false), })); parseAndAssertNodeCount(3); CustomTag customTag = (CustomTag) node[0]; assertStringEquals("first custom tag html", tag1 + "</custom>", customTag.toHtml()); assertNull("first custom tag should have no parent", customTag.getParent()); customTag = (CustomTag) node[1]; assertStringEquals("second custom tag html", tag2, customTag.toHtml()); assertNull("second custom tag should have no parent", customTag.getParent()); Node firstChild = customTag.childAt(0); assertType("firstChild", Text.class, firstChild); Node parent = firstChild.getParent(); assertNotNull("first child parent should not be null", parent); assertSame("parent and custom tag should be the same", customTag, parent); Tag endTag = (Tag) node[2]; assertStringEquals("third custom tag html", tag3, endTag.toHtml()); assertNull("end tag should have no parent", endTag.getParent()); }
public void testTwoConsecutiveErroneousCompositeTags() throws ParserException { String tag1 = "<custom>something"; String tag2 = "<custom></endtag>"; createParser(tag1 + tag2); parser.setNodeFactory(new PrototypicalNodeFactory(new CustomTag(false))); parseAndAssertNodeCount(2); 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("ending loc of custom tag", 17, customTag.getEndTag().getEndPosition()); assertEquals("starting line position", 0, customTag.getStartingLineNumber()); assertEquals("ending line position", 0, customTag.getEndTag().getEndingLineNumber()); assertStringEquals("1st custom tag", tag1 + "</custom>", customTag.toHtml()); customTag = (CustomTag) node[1]; assertStringEquals("2nd custom tag", tag2 + "</custom>", customTag.toHtml()); }
public void testEmptyCompositeTagAnotherStyle() throws ParserException { String html = "<Custom></Custom>"; createParser(html); CustomTag customTag = parseCustomTag(1); assertEquals("child count", 0, 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()); assertEquals("html", html, customTag.toHtml()); }
public void testErroneousCompositeTagWithChildrenAndLineBreak() throws ParserException { String html = "<custom>" + "<firstChild>" + "\n" + "<secondChild>"; createParser(html); CustomTag customTag = parseCustomTag(1); assertEquals("child count", 3, 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", 1, customTag.getEndTag().getEndingLineNumber()); assertStringEquals("html", html + "</custom>", customTag.toHtml()); }
public void testCompositeTagWithSelfChildren() throws ParserException { String tag1 = "<custom>"; String tag2 = "<custom>something</custom>"; String tag3 = "</custom>"; createParser(tag1 + tag2 + tag3); parser.setNodeFactory( new PrototypicalNodeFactory( new Tag[] { new CustomTag(false), new AnotherTag(false), })); parseAndAssertNodeCount(3); CustomTag customTag = (CustomTag) node[0]; assertEquals("child count", 0, customTag.getChildCount()); assertFalse("custom tag should not be xml end tag", customTag.isEmptyXmlTag()); assertStringEquals("first custom tag html", tag1 + "</custom>", customTag.toHtml()); customTag = (CustomTag) node[1]; assertStringEquals("second custom tag html", tag2, customTag.toHtml()); Tag endTag = (Tag) node[2]; assertStringEquals("third custom tag html", tag3, endTag.toHtml()); }
public void testCompositeTagWithErroneousAnotherTag() throws ParserException { createParser("<custom>" + "<another>" + "</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 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("another tag ending loc", 17, anotherTag.getEndPosition()); assertEquals("starting line position", 0, customTag.getStartingLineNumber()); assertEquals("ending line position", 0, customTag.getEndingLineNumber()); assertStringEquals("html", "<custom><another></another></custom>", customTag.toHtml()); }
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()); }