From 453372247c8c173c16fa2234b9645bf7a542ed8d Mon Sep 17 00:00:00 2001 From: j-james Date: Mon, 17 Oct 2022 02:10:50 -0700 Subject: Some edge cases: check for escaped quotes and ignore multiple whitespace chars --- src/test/model/HtmlParserTest.java | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/test') 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 = "

Hello,world!

"; + String idiomaticHtml = "

Hello, world!

"; String brokenHtml = "","","","","","

","Hello,world!","

","",""}; + 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 = {"","","","",""}; + System.out.println(HtmlParser.parseHtmlLL(brokenHtml)); // assertEquals(HtmlParser.parseHtmlLL(brokenHtml), Arrays.asList(brokenHtmlArray)); } @Test void testTrailingTextHtml() { String[] trailingTextHtmlArray = {"","","","","ba"}; + System.out.println(HtmlParser.parseHtmlLL(trailingTextHtml)); // assertEquals(HtmlParser.parseHtmlLL(trailingTextHtml), Arrays.asList(trailingTextHtmlArray)); } + + private void displayHtmlTree(ArrayList 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()); + } + } + } } -- cgit v1.2.3-70-g09d2