diff options
author | j-james | 2022-10-17 09:10:50 +0000 |
---|---|---|
committer | j-james | 2022-10-17 09:10:50 +0000 |
commit | 453372247c8c173c16fa2234b9645bf7a542ed8d (patch) | |
tree | 97b45f4063f706f8bd974958fe317f96b2044c53 /src/test | |
parent | 2bb1c153b693095b6bbafdfad139791817280af4 (diff) |
Some edge cases: check for escaped quotes and ignore multiple whitespace chars
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/model/HtmlParserTest.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/test/model/HtmlParserTest.java b/src/test/model/HtmlParserTest.java index e83c857..4b05cfb 100644 --- a/src/test/model/HtmlParserTest.java +++ b/src/test/model/HtmlParserTest.java @@ -1,21 +1,25 @@ package model; +import model.html.ElementNode; import model.html.HtmlParser; +import model.util.Node; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.*; import static org.junit.jupiter.api.Assertions.*; public class HtmlParserTest { - String idiomaticHtml = "<!DOCTYPE html><html><head></head><body><p>Hello,world!</p></body></html>"; + String idiomaticHtml = "<!DOCTYPE html><html><head></head><body><p>Hello, world!</p></body></html>"; String brokenHtml = "<html><foo><bar></bar><ba"; String trailingTextHtml = "<html><foo><bar></bar>ba"; @Test void testIdiomaticHtml() { String[] idiomaticHtmlArray = {"<!DOCTYPE html>","<html>","<head>","</head>","<body>","<p>","Hello,world!","</p>","</body>","</html>"}; + var parsedHtml = HtmlParser.parseHtmlLL(idiomaticHtml); + displayHtmlTree(parsedHtml); System.out.println(HtmlParser.parseHtmlLL(idiomaticHtml)); // assertEquals(HtmlParser.parseHtmlLL(idiomaticHtml), Arrays.asList(idiomaticHtmlArray)); } @@ -23,12 +27,29 @@ public class HtmlParserTest { @Test void testBrokenHtml() { String[] brokenHtmlArray = {"<html>","<foo>","<bar>","</bar>","<ba>"}; + System.out.println(HtmlParser.parseHtmlLL(brokenHtml)); // assertEquals(HtmlParser.parseHtmlLL(brokenHtml), Arrays.asList(brokenHtmlArray)); } @Test void testTrailingTextHtml() { String[] trailingTextHtmlArray = {"<html>","<foo>","<bar>","</bar>","ba"}; + System.out.println(HtmlParser.parseHtmlLL(trailingTextHtml)); // assertEquals(HtmlParser.parseHtmlLL(trailingTextHtml), Arrays.asList(trailingTextHtmlArray)); } + + private void displayHtmlTree(ArrayList<Node> tree) { + for (Node node : tree) { + if (node instanceof ElementNode) { + System.out.print(((ElementNode) node).getTag() + ": "); + for (Node n : ((ElementNode) node).getChildren()) { + System.out.print(n.getData() + " "); + } + System.out.println(); + displayHtmlTree(((ElementNode) node).getChildren()); + } else { + System.out.println("Text: " + node.getData()); + } + } + } } |