diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-08 16:00:35 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-01-31 14:31:04 +0100 |
commit | de4787898fbf91662cd894c5a9a0f30ad097fa5f (patch) | |
tree | 12828f1b20780bc70bddd5bc7fb374d4a33e15e7 /doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala | |
parent | 87f1f5f44585e855a8c8234955e1e48dcbbc3a21 (diff) | |
download | dotty-de4787898fbf91662cd894c5a9a0f30ad097fa5f.tar.gz dotty-de4787898fbf91662cd894c5a9a0f30ad097fa5f.tar.bz2 dotty-de4787898fbf91662cd894c5a9a0f30ad097fa5f.zip |
Fix recursive expansion of templates
Diffstat (limited to 'doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala')
-rw-r--r-- | doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala b/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala new file mode 100644 index 000000000..87358d738 --- /dev/null +++ b/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala @@ -0,0 +1,105 @@ +package dotty.tools +package dottydoc +package staticsite + +import org.junit.Test +import org.junit.Assert._ + +class PageTests 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 + } +} |