diff options
author | j-james | 2022-10-17 06:58:44 +0000 |
---|---|---|
committer | j-james | 2022-10-17 07:00:53 +0000 |
commit | 0caf1994dae8e88f7c219bedd87b65190b88aa89 (patch) | |
tree | 6b9302c64eb74194e8ed1f267ec711c038b514cd /src/test | |
parent | 3e9bb5fae16c35938bc1f7f7669c12cc355c9331 (diff) |
Implement LL(1) parsers for HTML and CSS
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/model/CssParserTest.java | 15 | ||||
-rw-r--r-- | src/test/model/HtmlParserTest.java | 34 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/test/model/CssParserTest.java b/src/test/model/CssParserTest.java new file mode 100644 index 0000000..2852da5 --- /dev/null +++ b/src/test/model/CssParserTest.java @@ -0,0 +1,15 @@ +package model; + +import model.css.CssParser; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CssParserTest { + + @Test + void testIdiomaticCss() { + var 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) { div { margin: 0 auto; width: auto; }}"; + System.out.println(CssParser.parseLL(idiomaticCss)); + } +} diff --git a/src/test/model/HtmlParserTest.java b/src/test/model/HtmlParserTest.java new file mode 100644 index 0000000..e83c857 --- /dev/null +++ b/src/test/model/HtmlParserTest.java @@ -0,0 +1,34 @@ +package model; + +import model.html.HtmlParser; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +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 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>"}; + System.out.println(HtmlParser.parseHtmlLL(idiomaticHtml)); +// assertEquals(HtmlParser.parseHtmlLL(idiomaticHtml), Arrays.asList(idiomaticHtmlArray)); + } + + @Test + void testBrokenHtml() { + String[] brokenHtmlArray = {"<html>","<foo>","<bar>","</bar>","<ba>"}; +// assertEquals(HtmlParser.parseHtmlLL(brokenHtml), Arrays.asList(brokenHtmlArray)); + } + + @Test + void testTrailingTextHtml() { + String[] trailingTextHtmlArray = {"<html>","<foo>","<bar>","</bar>","ba"}; +// assertEquals(HtmlParser.parseHtmlLL(trailingTextHtml), Arrays.asList(trailingTextHtmlArray)); + } +} |