aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/test/StaticPageTests.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-01-06 13:54:07 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-31 14:29:18 +0100
commitc8a1a80776630535150d041a0aef34c508476cb3 (patch)
tree087c8ea46b7d50edf0c75eb64280397b3179e421 /doc-tool/test/StaticPageTests.scala
parent1dc446fc8973dce2da0bbb3c6eb97aa035d0d191 (diff)
downloaddotty-c8a1a80776630535150d041a0aef34c508476cb3.tar.gz
dotty-c8a1a80776630535150d041a0aef34c508476cb3.tar.bz2
dotty-c8a1a80776630535150d041a0aef34c508476cb3.zip
Add `Page` trait with concrete classes for HTML and MD
Diffstat (limited to 'doc-tool/test/StaticPageTests.scala')
-rw-r--r--doc-tool/test/StaticPageTests.scala106
1 files changed, 106 insertions, 0 deletions
diff --git a/doc-tool/test/StaticPageTests.scala b/doc-tool/test/StaticPageTests.scala
new file mode 100644
index 000000000..1b22665c8
--- /dev/null
+++ b/doc-tool/test/StaticPageTests.scala
@@ -0,0 +1,106 @@
+package dotty.tools
+package dottydoc
+
+import org.junit.Test
+import org.junit.Assert._
+
+import staticsite.{ MarkdownPage, HtmlPage, IllegalFrontMatter }
+
+class StaticPageTests extends DottyDocTest {
+ import scala.collection.JavaConverters._
+
+ @Test def mdHas1Key = {
+ val page = new MarkdownPage(
+ """|---
+ |key:
+ |---
+ |
+ |great""".stripMargin,
+ Map.empty
+ )
+
+ assert(
+ page.yaml == Map("key" -> ""),
+ s"""incorrect yaml, expected "key:" without key in: ${page.yaml}"""
+ )
+
+ assertEquals("<p>great</p>\n", page.html)
+ }
+
+ @Test def yamlPreservesLiquidTags = {
+ val page1 = new MarkdownPage(
+ """|---
+ |key:
+ |---
+ |
+ |{{ content }}""".stripMargin,
+ Map("content" -> "Hello, world!")
+ )
+
+ assert(
+ page1.yaml == Map("key" -> ""),
+ s"""incorrect yaml, expected "key:" without key in: ${page1.yaml}"""
+ )
+
+ assertEquals("<p>Hello, world!</p>\n", page1.html)
+
+ val page2 = new MarkdownPage(
+ """|{{ content }}""".stripMargin,
+ Map("content" -> "hello")
+ )
+ assert(
+ page2.yaml == Map(),
+ s"""incorrect yaml, expected "key:" without key in: ${page2.yaml}"""
+ )
+ assertEquals("<p>hello</p>\n", page2.html)
+
+ val page3 = new MarkdownPage(
+ """|{% if product.title == "Awesome Shoes" %}
+ |These shoes are awesome!
+ |{% endif %}""".stripMargin,
+ Map("product" -> Map("title" -> "Awesome Shoes").asJava)
+ )
+
+ assertEquals(
+ "<p>These shoes are awesome!</p>\n",
+ page3.html
+ )
+ }
+
+ @Test def simpleHtmlPage = {
+ val p1 = new HtmlPage("""<h1>{{ "hello, world!" }}</h1>""", Map.empty)
+ assert(p1.yaml == Map(), "non-empty yaml found")
+ assertEquals("<h1>hello, world!</h1>", p1.html)
+ }
+
+ @Test def htmlPageHasNoYaml = {
+ val page = new HtmlPage(
+ """|---
+ |layout: main
+ |---
+ |
+ |Hello, world!""".stripMargin,
+ Map.empty
+ )
+
+ assert(!page.html.contains("---\nlayout: main\n---"),
+ s"page still contains yaml:\n${page.html}")
+ }
+
+ @Test def illegalYamlFrontMatter = try {
+ val page = new HtmlPage(
+ """|---
+ |layout: main
+ |
+ |
+ |Hello, world!""".stripMargin,
+ Map.empty
+ )
+
+ page.html
+ fail("illegal front matter didn't throw exception")
+ } catch {
+ case IllegalFrontMatter(x) => // success!
+ case t: Throwable => throw t
+ }
+}