PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/test/test_zenweb_plugins_markdown.rb

https://github.com/seattlerb/zenweb
Ruby | 298 lines | 250 code | 47 blank | 1 comment | 47 complexity | e409b51704fa118d223f2affd5aaea65 MD5 | raw file
  1. #!/usr/bin/ruby -w
  2. require "rubygems"
  3. require "minitest/autorun"
  4. require "zenweb/site"
  5. require "test/helper"
  6. class MarkdownTest < Minitest::Test
  7. attr_accessor :site, :page
  8. def setup
  9. super
  10. self.site = Zenweb::Site.new
  11. self.page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
  12. end
  13. end
  14. class TestUgh < MarkdownTest
  15. def assert_markdown_code lang, line, *exps
  16. act = page.markdown "``` #{lang}\n#{line}\n```"
  17. exps.each do |exp|
  18. assert_includes act, exp, act
  19. end
  20. end
  21. def test_coderay_ruby
  22. assert_markdown_code("ruby",
  23. "def x\n 42\nend",
  24. '<div class="language-ruby highlighter-coderay"><table class="CodeRay"><tr>',
  25. '<span class="keyword">def</span>')
  26. end
  27. def test_coderay_clojure
  28. assert_markdown_code("clojure",
  29. "(+ 1 1)",
  30. '<pre>(<span class="keyword">+</span>',
  31. '<span class="integer">1</span>',
  32. '<span class="integer">1</span>)')
  33. end
  34. def test_coderay_elisp
  35. assert_markdown_code("elisp",
  36. "(+ 1 1)",
  37. '<pre>(<span class="keyword">+</span>',
  38. '<span class="integer">1</span>',
  39. '<span class="integer">1</span>)')
  40. end
  41. end
  42. class TestZenwebPageMarkdown < MarkdownTest
  43. include ChdirTest("example-site")
  44. def test_attr_h
  45. assert_equal "{:blah=\"42\"}", page.attr("blah" => 42)
  46. end
  47. def test_attr_name
  48. assert_equal "{:blah}", page.attr("blah")
  49. end
  50. def test_css_class
  51. assert_equal "{:.blah}", page.css_class("blah")
  52. end
  53. def test_css_id
  54. assert_equal "{:#blah}", page.css_id("blah")
  55. end
  56. def test_link
  57. assert_equal "[mytitle](myurl)", page.link("myurl", "mytitle")
  58. end
  59. def test_image
  60. assert_equal "![myurl](myurl)", page.image("myurl")
  61. assert_equal "![myalt](myurl)", page.image("myurl", "myalt")
  62. end
  63. def test_render_md
  64. act = page.render_md page, nil
  65. exp = "<p>Not really much here to see.</p>\n"
  66. assert_equal exp, act
  67. end
  68. def test_render_md_content
  69. act = page.render_md page, "woot"
  70. exp = "<p>woot</p>\n"
  71. assert_equal exp, act
  72. end
  73. def test_markdown
  74. act = page.markdown "woot"
  75. exp = "<p>woot</p>\n"
  76. assert_equal exp, act
  77. end
  78. def test_sitemap
  79. build_fake_site %w[a/index.html.md
  80. a/b/index.html.md
  81. a/b/2012-01-02-p1.html
  82. a/b/2012-02-03-p2.html
  83. a/b/2012-03-04-p3.html]
  84. page = site.pages["a/index.html.md"]
  85. act = page.sitemap
  86. exp = <<-END.cleanup
  87. * [Title for a/b/index.html.md](/a/b/)
  88. * 2012-03:
  89. * [Title for a/b/2012-03-04-p3.html](/a/b/2012/03/04/p3.html)
  90. * 2012-02:
  91. * [Title for a/b/2012-02-03-p2.html](/a/b/2012/02/03/p2.html)
  92. * 2012-01:
  93. * [Title for a/b/2012-01-02-p1.html](/a/b/2012/01/02/p1.html)
  94. END
  95. assert_equal exp, act
  96. end
  97. def test_sitemap_folded_sorting
  98. build_fake_site %w[
  99. a/index.html.md
  100. a/ZenWeb.html.md
  101. a/autotest.html.md
  102. ]
  103. page = site.pages["a/index.html.md"]
  104. act = page.sitemap
  105. exp = <<-END.cleanup
  106. * [Title for a/autotest.html.md](/a/autotest.html)
  107. * [Title for a/ZenWeb.html.md](/a/ZenWeb.html)
  108. END
  109. assert_equal exp, act
  110. end
  111. def test_sitemap_multidir
  112. build_fake_site %w[a/index.html.md
  113. a/b/index.html.md
  114. a/b/p1.html
  115. a/b/p2.html
  116. a/b/p3.html]
  117. page = site.pages["a/index.html.md"]
  118. act = page.sitemap
  119. exp = <<-END.cleanup
  120. * [Title for a/b/index.html.md](/a/b/)
  121. * [Title for a/b/p1.html](/a/b/p1.html)
  122. * [Title for a/b/p2.html](/a/b/p2.html)
  123. * [Title for a/b/p3.html](/a/b/p3.html)
  124. END
  125. assert_equal exp, act
  126. end
  127. def test_sitemap_multidir_excluded
  128. build_fake_site %w[a/index.html.md
  129. a/b/index.html.md
  130. a/b/p1.html
  131. a/b/p2.html
  132. a/b/p3.html]
  133. site.pages["a/b/p1.html"].config.h["no_index"] = true
  134. page = site.pages["a/index.html.md"]
  135. act = page.sitemap
  136. exp = <<-END.cleanup
  137. * [Title for a/b/index.html.md](/a/b/)
  138. * [Title for a/b/p2.html](/a/b/p2.html)
  139. * [Title for a/b/p3.html](/a/b/p3.html)
  140. END
  141. assert_equal exp, act
  142. end
  143. def test_sitemap_subdir
  144. build_fake_site %w[a/index.html
  145. a/b/index.html.md
  146. a/b/p1.html
  147. a/b/p2.html
  148. a/b/p3.html]
  149. page = site.pages["a/b/index.html.md"]
  150. act = page.sitemap
  151. exp = <<-END.cleanup
  152. * [Title for a/b/p1.html](/a/b/p1.html)
  153. * [Title for a/b/p2.html](/a/b/p2.html)
  154. * [Title for a/b/p3.html](/a/b/p3.html)
  155. END
  156. assert_equal exp, act
  157. end
  158. def test_sitemap_subdir_mixed
  159. build_fake_site %w[index.html.md
  160. a/index.html.md
  161. a/a.html
  162. a/b.html
  163. a/c.html
  164. a/2012-01-02-p1.html
  165. a/2012-01-03-p2.html
  166. a/2012-01-04-p3.html
  167. a/2012-02-02-p1.html
  168. a/2012-02-03-p2.html
  169. a/2012-02-04-p3.html
  170. c/index.html.md
  171. c/a.html
  172. c/b.html
  173. c/c.html
  174. c/d/index.html.md
  175. c/d/e.html
  176. c/d/f.html
  177. c/d/g.html
  178. d/index.html.md
  179. d/2012-01-02-p1.html
  180. d/2012-01-03-p2.html
  181. d/2012-01-04-p3.html
  182. some_random_page.html
  183. ]
  184. page = site.pages["index.html.md"]
  185. act = page.sitemap
  186. exp = <<-END.cleanup
  187. * [Title for a/index.html.md](/a/)
  188. * [Title for a/a.html](/a/a.html)
  189. * [Title for a/b.html](/a/b.html)
  190. * [Title for a/c.html](/a/c.html)
  191. * 2012-02:
  192. * [Title for a/2012-02-04-p3.html](/a/2012/02/04/p3.html)
  193. * [Title for a/2012-02-03-p2.html](/a/2012/02/03/p2.html)
  194. * [Title for a/2012-02-02-p1.html](/a/2012/02/02/p1.html)
  195. * 2012-01:
  196. * [Title for a/2012-01-04-p3.html](/a/2012/01/04/p3.html)
  197. * [Title for a/2012-01-03-p2.html](/a/2012/01/03/p2.html)
  198. * [Title for a/2012-01-02-p1.html](/a/2012/01/02/p1.html)
  199. * [Title for c/index.html.md](/c/)
  200. * [Title for c/a.html](/c/a.html)
  201. * [Title for c/b.html](/c/b.html)
  202. * [Title for c/c.html](/c/c.html)
  203. * [Title for c/d/index.html.md](/c/d/)
  204. * [Title for c/d/e.html](/c/d/e.html)
  205. * [Title for c/d/f.html](/c/d/f.html)
  206. * [Title for c/d/g.html](/c/d/g.html)
  207. * [Title for d/index.html.md](/d/)
  208. * 2012-01:
  209. * [Title for d/2012-01-04-p3.html](/d/2012/01/04/p3.html)
  210. * [Title for d/2012-01-03-p2.html](/d/2012/01/03/p2.html)
  211. * [Title for d/2012-01-02-p1.html](/d/2012/01/02/p1.html)
  212. * [Title for some_random_page.html](/some_random_page.html)
  213. END
  214. assert_equal exp, act
  215. end
  216. def test_sitemap_subdir_bloggish
  217. build_fake_site %w[index.html.md
  218. 2012-01-02-p1.html
  219. 2012-01-03-p2.html
  220. 2012-01-04-p3.html
  221. 2012-02-02-p1.html
  222. 2012-02-03-p2.html
  223. 2012-02-04-p3.html
  224. sitemap.html
  225. some_random_page.html
  226. ]
  227. page = site.pages["index.html.md"]
  228. act = page.sitemap
  229. exp = <<-END.cleanup
  230. * [Title for sitemap.html](/sitemap.html)
  231. * [Title for some_random_page.html](/some_random_page.html)
  232. * 2012-02:
  233. * [Title for 2012-02-04-p3.html](/2012/02/04/p3.html)
  234. * [Title for 2012-02-03-p2.html](/2012/02/03/p2.html)
  235. * [Title for 2012-02-02-p1.html](/2012/02/02/p1.html)
  236. * 2012-01:
  237. * [Title for 2012-01-04-p3.html](/2012/01/04/p3.html)
  238. * [Title for 2012-01-03-p2.html](/2012/01/03/p2.html)
  239. * [Title for 2012-01-02-p1.html](/2012/01/02/p1.html)
  240. END
  241. assert_equal exp, act
  242. end
  243. def test_toc
  244. assert_equal "* \n{:toc}\n", page.toc
  245. end
  246. end
  247. class String
  248. def cleanup indent = 4
  249. self.gsub(/^\ {#{indent}}/, '').chomp
  250. end
  251. end