package model; import model.html.ElementNode; import model.html.HtmlParser; import model.util.Node; import org.junit.jupiter.api.Test; import java.util.*; public class HtmlParserTest { String idiomaticHtml = "

Hello, world!

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

","Hello,world!","

","",""}; HtmlParser parser = new HtmlParser(); displayHtmlTree(parser.parseHtml(idiomaticHtml)); // assertEquals(HtmlParser.parseHtmlLL(idiomaticHtml), Arrays.asList(idiomaticHtmlArray)); } @Test void testBrokenHtml() { String[] brokenHtmlArray = {"","","","",""}; HtmlParser parser = new HtmlParser(); displayHtmlTree(parser.parseHtml(brokenHtml)); // assertEquals(HtmlParser.parseHtmlLL(brokenHtml), Arrays.asList(brokenHtmlArray)); } @Test void testTrailingTextHtml() { String[] trailingTextHtmlArray = {"","","","","ba"}; HtmlParser parser = new HtmlParser(); displayHtmlTree(parser.parseHtml(trailingTextHtml)); // assertEquals(HtmlParser.parseHtmlLL(trailingTextHtml), Arrays.asList(trailingTextHtmlArray)); } /** * Simple helper function for debugging. * EFFECTS: prints a representation of the tree to the console for debugging purposes */ 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()); } } } }