diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/model/css/CssParserTest.java | 16 | ||||
-rw-r--r-- | src/test/model/html/HtmlParserTest.java | 40 |
2 files changed, 25 insertions, 31 deletions
diff --git a/src/test/model/css/CssParserTest.java b/src/test/model/css/CssParserTest.java index 42cdd9f..e6ea519 100644 --- a/src/test/model/css/CssParserTest.java +++ b/src/test/model/css/CssParserTest.java @@ -1,6 +1,5 @@ package model.css; -import model.css.CssParser; import org.javatuples.Pair; import org.junit.jupiter.api.Test; @@ -10,15 +9,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class CssParserTest { + String idiomaticCss = "body { background-color: '#\\'f0f0f2'; margin: 0; padding: 0; font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe\\\" UI\", 'Open\\' Sans', \"Helvetica Neue\", Helvetica, Arial, sans-serif;}div { width: 600px; margin: 5em auto; padding: 2em; background-color: #fdfdff; border-radius: 0.5em; box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);}a:link, a:visited { color: #38488f; text-decoration: none;}@media (max - width : 700px) { @media () {div { margin: 0 auto; width: auto }}}"; + @Test void testIdiomaticCss() { - String idiomaticCss = "body { background-color: '#\\'f0f0f2'; margin: 0; padding: 0; font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe\\\" UI\", 'Open\\' Sans', \"Helvetica Neue\", Helvetica, Arial, sans-serif;}div { width: 600px; margin: 5em auto; padding: 2em; background-color: #fdfdff; border-radius: 0.5em; box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);}a:link, a:visited { color: #38488f; text-decoration: none;}@media (max - width : 700px) { @media () {div { margin: 0 auto; width: auto }}}"; - - ArrayList<Pair<String, ArrayList<Pair<String, String>>>> expected = new ArrayList<>(); - ArrayList<Pair<String, String>> body = new ArrayList<>(); - ArrayList<Pair<String, String>> divOne = new ArrayList<>(); - ArrayList<Pair<String, String>> selectors = new ArrayList<>(); - ArrayList<Pair<String, String>> divTwo = new ArrayList<>(); + var expected = new ArrayList<Pair<String, ArrayList<Pair<String, String>>>>(); + var body = new ArrayList<Pair<String, String>>(); + var divOne = new ArrayList<Pair<String, String>>(); + var selectors = new ArrayList<Pair<String, String>>(); + var divTwo = new ArrayList<Pair<String, String>>(); expected.add(new Pair<>("body", body)); expected.add(new Pair<>("div", divOne)); expected.add(new Pair<>("a:link,a:visited", selectors)); @@ -40,7 +39,6 @@ public class CssParserTest { CssParser parser = new CssParser(); assertEqualsCss(parser.parseCSS(idiomaticCss), expected); - // System.out.println(parser.parseCSS(idiomaticCss)); } @Test diff --git a/src/test/model/html/HtmlParserTest.java b/src/test/model/html/HtmlParserTest.java index 4a35320..743f9f7 100644 --- a/src/test/model/html/HtmlParserTest.java +++ b/src/test/model/html/HtmlParserTest.java @@ -16,57 +16,54 @@ public class HtmlParserTest { @Test void testIdiomaticHtml() { - ArrayList<Node> expected = new ArrayList<>(); - ArrayList<Node> expectedChildren = new ArrayList<>(); - ArrayList<Node> expectedGrandChildren = new ArrayList<>(); - ArrayList<Node> expectedGreatGrandChildren = new ArrayList<>(); + var expected = new ArrayList<Node>(); + var expectedChildren = new ArrayList<Node>(); + var expectedGrandChildren = new ArrayList<Node>(); + var expectedGreatGrandChildren = new ArrayList<Node>(); expected.add(new ElementNode("html", new ArrayList<>(), expectedChildren)); expectedChildren.add(new ElementNode("head")); expectedChildren.add(new ElementNode("body", new ArrayList<>(), expectedGrandChildren)); expectedGrandChildren.add(new ElementNode("p", new ArrayList<>(), expectedGreatGrandChildren)); expectedGreatGrandChildren.add(new TextNode("Hello, world!")); - HtmlParser parser = new HtmlParser(); + var parser = new HtmlParser(); assertEqualsHtml(parser.parseHtml(idiomaticHtml), expected); - // displayHtmlTree(parser.parseHtml(idiomaticHtml)); } @Test void testBrokenHtml() { - ArrayList<Node> expected = new ArrayList<>(); - ArrayList<Node> expectedChildren = new ArrayList<>(); - ArrayList<Node> expectedGrandChildren = new ArrayList<>(); + var expected = new ArrayList<Node>(); + var expectedChildren = new ArrayList<Node>(); + var expectedGrandChildren = new ArrayList<Node>(); expected.add(new ElementNode("html", new ArrayList<>(), expectedChildren)); expectedChildren.add(new ElementNode("foo", new ArrayList<>(), expectedGrandChildren)); expectedGrandChildren.add(new ElementNode("bar", new ArrayList<>())); expectedGrandChildren.add(new TextNode("<>")); - HtmlParser parser = new HtmlParser(); + var parser = new HtmlParser(); assertEqualsHtml(parser.parseHtml(brokenHtml), expected); - // displayHtmlTree(parser.parseHtml(brokenHtml)); } @Test void testTrailingTextHtml() { - ArrayList<Node> expected = new ArrayList<>(); - ArrayList<Node> expectedChildren = new ArrayList<>(); - ArrayList<Node> expectedGrandChildren = new ArrayList<>(); + var expected = new ArrayList<Node>(); + var expectedChildren = new ArrayList<Node>(); + var expectedGrandChildren = new ArrayList<Node>(); expected.add(new TextNode("bot")); expected.add(new ElementNode("html", new ArrayList<>(), expectedChildren)); expected.add(new TextNode("ba")); expectedChildren.add(new ElementNode("foo", new ArrayList<>(), expectedGrandChildren)); expectedGrandChildren.add(new ElementNode("bar", new ArrayList<>())); - HtmlParser parser = new HtmlParser(); + var parser = new HtmlParser(); assertEqualsHtml(parser.parseHtml(trailingTextHtml), expected); - // displayHtmlTree(parser.parseHtml(trailingTextHtml)); } @Test void testAttributesHtml() { - ArrayList<Node> expected = new ArrayList<>(); - ArrayList<Node> expectedChildren = new ArrayList<>(); - ArrayList<Pair<String, String>> expectedAttributes = new ArrayList<>(); + var expected = new ArrayList<Node>(); + var expectedChildren = new ArrayList<Node>(); + var expectedAttributes = new ArrayList<Pair<String, String>>(); expected.add(new ElementNode("html", new ArrayList<>(), expectedChildren)); expectedChildren.add(new ElementNode("attr", expectedAttributes)); expectedAttributes.add(new Pair<>("hello", "world")); @@ -74,8 +71,8 @@ public class HtmlParserTest { expectedAttributes.add(new Pair<>("strange", "cha\"rm")); expectedAttributes.add(new Pair<>("up", "do'wn")); - HtmlParser parser = new HtmlParser(); - ArrayList<Node> parsed = parser.parseHtml(attributesHtml); + var parser = new HtmlParser(); + var parsed = parser.parseHtml(attributesHtml); displayHtmlTree(parsed); assertEqualsHtml(parsed, expected); } @@ -86,7 +83,6 @@ public class HtmlParserTest { private static void assertEqualsHtml(ArrayList<Node> html, ArrayList<Node> expected) { for (int i = 0; i < html.size(); i++) { assertEquals(html.get(i).data(), expected.get(i).data()); - // System.out.println(html.get(i).getData() + " " + expected.get(i).getData()); switch (html.get(i)) { case ElementNode e -> assertEqualsHtml(e.children, ((ElementNode) expected.get(i)).children); |