aboutsummaryrefslogtreecommitdiff
path: root/src/test/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/model')
-rw-r--r--src/test/model/HtmlParserTest.java25
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());
+ }
+ }
+ }
}