|
9 | 9 | import java.nio.charset.StandardCharsets; |
10 | 10 |
|
11 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 12 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
12 | 13 | import static org.junit.jupiter.api.Assertions.assertNotSame; |
| 14 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 15 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
13 | 16 |
|
14 | 17 | public class ParserTest { |
15 | 18 |
|
@@ -76,4 +79,24 @@ public void testClone() { |
76 | 79 | assertEquals(xmlParser.settings().preserveTagCase(), xmlClone.settings().preserveTagCase()); |
77 | 80 | assertEquals(xmlParser.settings().preserveAttributeCase(), xmlClone.settings().preserveAttributeCase()); |
78 | 81 | } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testCloneCopyTagSet() { |
| 85 | + Parser parser = Parser.htmlParser(); |
| 86 | + parser.tagSet().add(new Tag("foo")); |
| 87 | + parser.tagSet().onNewTag(tag -> tag.set(Tag.SelfClose)); |
| 88 | + Parser clone = parser.clone(); |
| 89 | + |
| 90 | + // Ensure the tagsets are different instances |
| 91 | + assertNotSame(clone.tagSet(), parser.tagSet()); |
| 92 | + // Check that cloned tagset contains same tag |
| 93 | + assertNotNull(clone.tagSet().get("foo", Parser.NamespaceHtml)); |
| 94 | + // Ensure onNewTag customizers are retained |
| 95 | + Tag custom = clone.tagSet().valueOf("qux", Parser.NamespaceHtml); |
| 96 | + assertTrue(custom.isSelfClosing()); |
| 97 | + // Check that cloned tagset uses the original tag as source when original is modified |
| 98 | + assertNull(clone.tagSet().get("bar", Parser.NamespaceHtml)); |
| 99 | + parser.tagSet().add(new Tag("bar")); |
| 100 | + assertNotNull(clone.tagSet().get("bar", Parser.NamespaceHtml)); |
| 101 | + } |
79 | 102 | } |
0 commit comments