PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/google-wiki-syntax/test/wiki_syntax_test.rb

http://chrisroos.googlecode.com/
Ruby | 542 lines | 429 code | 113 blank | 0 comment | 6 complexity | 0c15f9806f72be4eca4b503d8c89ce8f MD5 | raw file
  1. require 'test/unit'
  2. require File.join(File.dirname(__FILE__), '..', 'lib', 'wiki_syntax')
  3. module Kernel
  4. alias_method :__original_p, :p
  5. def p(*args)
  6. __original_p(*args)
  7. end
  8. end
  9. class WikiSyntaxHtmlEscapingTest < Test::Unit::TestCase
  10. def test_should_html_escape_wiki_content
  11. assert_equal "<p>this &amp; that. 1 &lt; 2. 2 &gt; 1.</p>", WikiSyntax.new('this & that. 1 < 2. 2 > 1.').to_html
  12. end
  13. end
  14. class WikiSyntaxParagraphTest < Test::Unit::TestCase
  15. def test_should_surround_content_on_one_line_in_one_html_paragraph_tag
  16. assert_equal "<p>line 1</p>", WikiSyntax.new('line 1').to_html
  17. end
  18. def test_should_surround_content_on_two_subsequent_lines_in_one_html_paragraph_tag
  19. assert_equal "<p>line 1 line 2</p>", WikiSyntax.new("line 1\nline 2").to_html
  20. end
  21. def test_should_surround_content_separated_by_a_new_line_in_two_html_paragraph_tags
  22. assert_equal "<p>line 1</p><p>line 2</p>", WikiSyntax.new("line 1\n\nline 2").to_html
  23. end
  24. def test_should_ignore_newlines_at_the_end_of_the_wiki_content
  25. assert_equal "<p>line 1</p>", WikiSyntax.new("line 1\n\n\n").to_html
  26. end
  27. def test_should_create_two_paragraphs_and_ignore_newlines_at_the_end_of_the_wiki_content
  28. assert_equal "<p>line 1</p><p>line 2</p>", WikiSyntax.new("line 1\n\n\nline 2\n\n").to_html
  29. end
  30. def test_should_create_a_paragraph_when_the_string_contains_a_block_level_html_tag
  31. assert_equal "<p>paragraph including an html tag: pre</p>", WikiSyntax.new("paragraph including an html tag: pre").to_html
  32. end
  33. end
  34. class WikiSyntaxTypefaceTest < Test::Unit::TestCase
  35. def test_should_enclose_text_in_html_italic_tags
  36. assert_equal "<p><i>italic</i></p>", WikiSyntax.new('_italic_').to_html
  37. end
  38. def test_should_not_enclose_text_in_html_italic_tags
  39. assert_equal "<p>_notitalic</p>", WikiSyntax.new('_notitalic').to_html
  40. end
  41. def test_should_enclose_text_in_html_strong_tags
  42. assert_equal "<p><strong>bold</strong></p>", WikiSyntax.new('*bold*').to_html
  43. end
  44. def test_should_not_enclose_text_in_html_strong_tags
  45. assert_equal "<p>*not_bold</p>", WikiSyntax.new('*not_bold').to_html
  46. end
  47. def test_should_enclose_text_in_html_sup_tags
  48. assert_equal "<p><sup>super</sup>script</p>", WikiSyntax.new('^super^script').to_html
  49. end
  50. def test_should_not_enclose_text_in_html_sup_tags
  51. assert_equal "<p>^not_superscript</p>", WikiSyntax.new('^not_superscript').to_html
  52. end
  53. def test_should_enclose_text_in_html_sub_tags
  54. assert_equal "<p><sub>sub</sub>script</p>", WikiSyntax.new(',,sub,,script').to_html
  55. end
  56. def test_should_not_enclose_text_in_html_sub_tags
  57. assert_equal "<p>,,not_subscript</p>", WikiSyntax.new(',,not_subscript').to_html
  58. end
  59. def test_should_enclose_text_in_html_strike_tags
  60. assert_equal "<p><strike>strikeout</strike></p>", WikiSyntax.new('~~strikeout~~').to_html
  61. end
  62. def test_should_not_enclose_text_in_html_strike_tags
  63. assert_equal "<p>~~not_strikeout</p>", WikiSyntax.new('~~not_strikeout').to_html
  64. end
  65. def test_should_enclose_strong_tags_within_italic_tags
  66. assert_equal "<p><i><strong>bold</strong> in italics</i></p>", WikiSyntax.new("_*bold* in italics_").to_html
  67. end
  68. def test_should_enclose_italic_tags_within_strong_tags
  69. assert_equal "<p><strong><i>italics</i> in bold</strong></p>", WikiSyntax.new("*_italics_ in bold*").to_html
  70. end
  71. def test_should_strike_words_within_strong_tags
  72. assert_equal "<p><strong><strike>strike</strike> works too</strong></p>", WikiSyntax.new("*~~strike~~ works too*").to_html
  73. end
  74. def test_should_italicise_one_of_the_striked_words
  75. assert_equal "<p><strike>as well as <i>this</i> way round</strike></p>", WikiSyntax.new("~~as well as _this_ way round~~").to_html
  76. end
  77. end
  78. class WikiSyntaxCodeTest < Test::Unit::TestCase
  79. def test_should_deal_with_over_10_code_blocks
  80. letters = %w(A B C D E F G H I J K)
  81. assert letters.length > 10
  82. wiki_content = letters.collect { |letter| "{{{ code-block-#{letter} }}}" }.join(' ')
  83. expected_html = letters.collect { |letter| %%<code>code-block-#{letter}</code>% }.join(' ')
  84. assert_equal "<p>#{expected_html}</p>", WikiSyntax.new(wiki_content).to_html
  85. end
  86. def test_should_enclose_text_in_backticks_in_html_code_tags
  87. assert_equal "<p><code>code</code></p>", WikiSyntax.new('`code`').to_html
  88. end
  89. def test_should_enclose_text_in_triple_braces_in_html_code_tags
  90. assert_equal "<p><code>code</code></p>", WikiSyntax.new('{{{code}}}').to_html
  91. end
  92. def test_should_enclose_multiline_text_in_triple_braces_in_html_pre_tags
  93. assert_equal "<pre>line 1\nline 2</pre>", WikiSyntax.new("{{{\nline 1\nline 2\n}}}").to_html
  94. end
  95. def test_should_not_alter_code_in_backticks
  96. assert_equal "<p><code>_foo = *bar</code></p>", WikiSyntax.new("`_foo = *bar`").to_html
  97. end
  98. def test_should_not_alter_code_in_triple_braces
  99. assert_equal "<p><code>_foo = *bar</code></p>", WikiSyntax.new("{{{_foo = *bar}}}").to_html
  100. end
  101. def test_should_not_alter_multiline_code_in_triple_braces
  102. assert_equal "<pre>_foo = *bar</pre>", WikiSyntax.new("{{{\n_foo = *bar\n}}}").to_html
  103. end
  104. def test_should_surround_two_multiline_code_blocks_with_pre_tags
  105. assert_equal "<pre>line1</pre><pre>line2</pre>", WikiSyntax.new("{{{\nline1\n}}}\n{{{\nline2\n}}}").to_html
  106. end
  107. end
  108. class WikiSyntaxHeadingsTest < Test::Unit::TestCase
  109. def test_should_generate_h1
  110. assert_equal "<h1>heading</h1>", WikiSyntax.new("= heading =").to_html
  111. end
  112. def test_should_not_generate_h1
  113. assert_equal '<p>= no heading</p>', WikiSyntax.new("= no heading").to_html
  114. end
  115. def test_should_generate_h2
  116. assert_equal "<h2>heading 2</h2>", WikiSyntax.new("== heading 2 ==").to_html
  117. end
  118. def test_should_not_generate_h2
  119. assert_equal '<p>== no heading</p>', WikiSyntax.new("== no heading").to_html
  120. end
  121. def test_should_generate_h3
  122. assert_equal "<h3>heading 3</h3>", WikiSyntax.new("=== heading 3 ===").to_html
  123. end
  124. def test_should_not_generate_h3
  125. assert_equal '<p>=== no heading</p>', WikiSyntax.new("=== no heading").to_html
  126. end
  127. def test_should_generate_h4
  128. assert_equal "<h4>heading 4</h4>", WikiSyntax.new("==== heading 4 ====").to_html
  129. end
  130. def test_should_not_generate_h4
  131. assert_equal '<p>==== no heading</p>', WikiSyntax.new("==== no heading").to_html
  132. end
  133. def test_should_generate_h5
  134. assert_equal "<h5>heading 5</h5>", WikiSyntax.new("===== heading 5 =====").to_html
  135. end
  136. def test_should_not_generate_h5
  137. assert_equal '<p>===== no heading</p>', WikiSyntax.new("===== no heading").to_html
  138. end
  139. def test_should_generate_h6
  140. assert_equal "<h6>heading 6</h6>", WikiSyntax.new("====== heading 6 ======").to_html
  141. end
  142. def test_should_not_generate_h6
  143. assert_equal '<p>====== no heading</p>', WikiSyntax.new("====== no heading").to_html
  144. end
  145. end
  146. class WikiSyntaxDividerTest < Test::Unit::TestCase
  147. def test_should_generate_horizontal_rule
  148. assert_equal '<hr/>', WikiSyntax.new('----').to_html
  149. end
  150. def test_should_not_generate_horizontal_rule
  151. assert_equal '<p>---</p>', WikiSyntax.new('---').to_html
  152. end
  153. def test_should_not_generate_horizontal_rule_when_there_is_something_other_than_dashes_on_the_line
  154. assert_equal '<p>hello ---- world</p>', WikiSyntax.new('hello ---- world').to_html
  155. end
  156. end
  157. class WikiSyntaxListTest < Test::Unit::TestCase
  158. def test_should_deal_with_over_10_lists
  159. letters = %w(A B C D E F G H I J K)
  160. assert letters.length > 10
  161. wiki_content = letters.collect { |letter| " * list-item-#{letter}" }.join("\n\n")
  162. expected_html = letters.collect { |letter| %%<ul><li>list-item-#{letter}</li></ul>% }.join
  163. assert_equal "#{expected_html}", WikiSyntax.new(wiki_content).to_html
  164. end
  165. def test_should_generate_a_one_item_ordered_list_with_no_space_between_the_hash_and_list_item
  166. assert_equal '<ul><li>list item</li></ul>', WikiSyntax.new(' *list item').to_html
  167. end
  168. def test_should_generate_a_one_item_unordered_list
  169. assert_equal '<ul><li>list item</li></ul>', WikiSyntax.new(' * list item').to_html
  170. end
  171. def test_should_generate_a_one_item_unordered_list_when_more_than_one_space_appears_at_the_beginning_of_the_line
  172. assert_equal '<ul><li>list item</li></ul>', WikiSyntax.new(' * list item').to_html
  173. end
  174. def test_should_generate_a_multi_item_unordered_list
  175. assert_equal '<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>', WikiSyntax.new(" * item 1\n * item 2\n * item 3").to_html
  176. end
  177. def test_should_generate_a_multi_item_ordered_list
  178. assert_equal '<ol><li>item 1</li><li>item 2</li><li>item 3</li></ol>', WikiSyntax.new(" # item 1\n # item 2\n # item 3").to_html
  179. end
  180. def test_should_generate_a_multi_level_multi_item_unordered_list
  181. assert_equal '<ul><li>level 1 item 1</li><ul><li>level 2 item 2</li></ul></ul>', WikiSyntax.new(" * level 1 item 1\n * level 2 item 2").to_html
  182. end
  183. def test_should_generate_an_unordered_list_that_contains_an_ordered_list
  184. assert_equal '<ul><li>level 1 ul 1</li><ol><li>level 2 ol</li></ol><li>level 1 ul 2</li></ul>', WikiSyntax.new(" * level 1 ul 1\n # level 2 ol\n * level 1 ul 2").to_html
  185. end
  186. def test_should_generate_an_ordered_list_that_contains_an_unordered_list
  187. assert_equal '<ol><li>ol 1</li><ul><li>ul 1</li></ul><li>ol 2</li></ol>', WikiSyntax.new(" # ol 1\n * ul 1\n # ol 2").to_html
  188. end
  189. def test_should_generate_two_unordered_lists_separateed_by_a_paragraph
  190. assert_equal '<ul><li>list 1</li></ul><p>between lists</p><ul><li>list 2</li></ul>', WikiSyntax.new(" * list 1\n\nbetween lists\n\n * list 2").to_html
  191. end
  192. def test_should_allow_wiki_formatting_within_the_generated_list
  193. assert_equal '<ul><li><strong>bold</strong> list item</li></ul>', WikiSyntax.new(" * *bold* list item").to_html
  194. end
  195. def test_should_generate_deep_nested_list
  196. assert_equal '<ul><li>ul 1</li><ul><li>ul 2</li><ul><li>ul 3</li></ul></ul></ul>', WikiSyntax.new(" * ul 1\n * ul 2\n * ul 3").to_html
  197. end
  198. end
  199. class WikiSyntaxBlockQuoteTest # < Test::Unit::TestCase
  200. def test_should_generate_two_blockquotes_when_two_newlines_separate_the_quotes
  201. assert_equal '<blockquote>first</blockquote><blockquote>second</blockquote><p>no quote</p>', WikiSyntax.new(" first\n\n second\nthird").to_html
  202. end
  203. def test_should_generate_one_blockquote_when_one_newline_separates_the_quotes
  204. assert_equal "<blockquote>first\nsecond</blockquote><p>third</p>", WikiSyntax.new(" first\n second\nthird").to_html
  205. end
  206. end
  207. class WikiSyntaxLinkTest < Test::Unit::TestCase
  208. def test_should_deal_with_over_10_wiki_links
  209. letters = %w(A B C D E F G H I J K)
  210. assert letters.length > 10
  211. wiki_content = letters.collect { |letter| "[Link#{letter}]" }.join(' ')
  212. expected_html = letters.collect { |letter| %%<a href="Link#{letter}.html">Link#{letter}</a>% }.join(' ')
  213. assert_equal "<p>#{expected_html}</p>", WikiSyntax.new(wiki_content).to_html
  214. end
  215. def test_should_allow_wiki_words_to_be_used_in_the_description_of_wiki_links
  216. assert_equal '<p><a href="MyWikiWord.html">MultiWord WikiLinkDescription</a></p>', WikiSyntax.new('[MyWikiWord MultiWord WikiLinkDescription]').to_html
  217. end
  218. def test_should_generate_a_relative_link_for_a_wiki_word_that_does_not_follow_wiki_syntax
  219. assert_equal '<p><a href="Mylink.html">Mylink</a></p>', WikiSyntax.new('[Mylink]').to_html
  220. assert_equal '<p>Text with a <a href="Mylink.html">Mylink</a> in the middle</p>', WikiSyntax.new('Text with a [Mylink] in the middle').to_html
  221. end
  222. def test_should_add_an_html_extension_to_wiki_words
  223. assert_equal '<p><a href="MyLink.html">MyLink</a></p>', WikiSyntax.new('MyLink').to_html
  224. assert_equal '<p>Text with a <a href="MyLink.html">MyLink</a> in the middle</p>', WikiSyntax.new('Text with a MyLink in the middle').to_html
  225. end
  226. def test_should_generate_a_relative_link_for_a_wiki_word
  227. assert_equal '<p><a href="MyLink.html">MyLink</a></p>', WikiSyntax.new('MyLink').to_html
  228. assert_equal '<p>Text with a <a href="MyLink.html">MyLink</a> in the middle</p>', WikiSyntax.new('Text with a MyLink in the middle').to_html
  229. end
  230. def test_should_generate_a_paragraph_containing_the_escaped_wiki_word
  231. assert_equal '<p>MyLink</p>', WikiSyntax.new('!MyLink').to_html
  232. assert_equal '<p>Text with a WikiWord in the middle</p>', WikiSyntax.new('Text with a !WikiWord in the middle').to_html
  233. end
  234. def test_should_generate_a_link_to_external_http_urls
  235. assert_equal '<p><a href="http://www.google.com">http://www.google.com</a></p>', WikiSyntax.new('http://www.google.com').to_html
  236. assert_equal '<p>Click <a href="http://example.com">http://example.com</a> to visit</p>', WikiSyntax.new('Click http://example.com to visit').to_html
  237. end
  238. def test_should_generate_a_link_with_specific_anchor_text_to_external_http_urls
  239. assert_equal '<p><a href="http://www.google.com">google home page</a></p>', WikiSyntax.new('[http://www.google.com google home page]').to_html
  240. assert_equal '<p>Click <a href="http://www.google.com">google home page</a> to visit</p>', WikiSyntax.new('Click [http://www.google.com google home page] to visit').to_html
  241. end
  242. def test_should_generate_a_relative_link_with_specific_anchor_text_for_a_wiki_word
  243. assert_equal '<p><a href="MyLink.html">my link</a></p>', WikiSyntax.new('[MyLink my link]').to_html
  244. assert_equal '<p>Click <a href="MyLink.html">my link</a> to visit</p>', WikiSyntax.new('Click [MyLink my link] to visit').to_html
  245. end
  246. def test_should_generate_a_link_to_external_ftp_urls
  247. assert_equal '<p><a href="ftp://ftp.kernel.org">ftp://ftp.kernel.org</a></p>', WikiSyntax.new('ftp://ftp.kernel.org').to_html
  248. assert_equal '<p>Click <a href="ftp://ftp.kernel.org">ftp://ftp.kernel.org</a> to visit</p>', WikiSyntax.new('Click ftp://ftp.kernel.org to visit').to_html
  249. end
  250. def test_should_generate_a_link_to_external_ftp_urls
  251. assert_equal '<p><a href="ftp://ftp.kernel.org">kernel ftp site</a></p>', WikiSyntax.new('[ftp://ftp.kernel.org kernel ftp site]').to_html
  252. assert_equal '<p>Click <a href="ftp://ftp.kernel.org">kernel ftp site</a> to visit</p>', WikiSyntax.new('Click [ftp://ftp.kernel.org kernel ftp site] to visit').to_html
  253. end
  254. end
  255. class WikiSyntaxImageTest < Test::Unit::TestCase
  256. def test_should_insert_a_png_image
  257. assert_equal '<p><img src="http://www.example.com/image.png" /></p>', WikiSyntax.new('http://www.example.com/image.png').to_html
  258. assert_equal '<p>My first <img src="http://www.example.com/image.png" /> image</p>', WikiSyntax.new('My first http://www.example.com/image.png image').to_html
  259. end
  260. def test_should_insert_a_gif_image
  261. assert_equal '<p><img src="http://www.example.com/image.gif" /></p>', WikiSyntax.new('http://www.example.com/image.gif').to_html
  262. assert_equal '<p>My first <img src="http://www.example.com/image.gif" /> image</p>', WikiSyntax.new('My first http://www.example.com/image.gif image').to_html
  263. end
  264. def test_should_insert_a_jpg_image
  265. assert_equal '<p><img src="http://www.example.com/image.jpg" /></p>', WikiSyntax.new('http://www.example.com/image.jpg').to_html
  266. assert_equal '<p>My first <img src="http://www.example.com/image.jpg" /> image</p>', WikiSyntax.new('My first http://www.example.com/image.jpg image').to_html
  267. end
  268. def test_should_insert_a_jpeg_image
  269. assert_equal '<p><img src="http://www.example.com/image.jpeg" /></p>', WikiSyntax.new('http://www.example.com/image.jpeg').to_html
  270. assert_equal '<p>My first <img src="http://www.example.com/image.jpeg" /> image</p>', WikiSyntax.new('My first http://www.example.com/image.jpeg image').to_html
  271. end
  272. end
  273. class WikiSyntaxLinkedImagesTest < Test::Unit::TestCase
  274. def test_should_link_to_a_png_image
  275. assert_equal '<p><a href="http://www.example.com"><img src="http://www.example.com/image.png" /></a></p>', WikiSyntax.new('[http://www.example.com http://www.example.com/image.png]').to_html
  276. assert_equal '<p>My first <a href="http://www.example.com"><img src="http://www.example.com/image.png" /></a> image</p>', WikiSyntax.new('My first [http://www.example.com http://www.example.com/image.png] image').to_html
  277. end
  278. end
  279. class WikiSyntaxTableTest < Test::Unit::TestCase
  280. def test_should_deal_with_over_10_tables
  281. letters = %w(A B C D E F G H I J K)
  282. assert letters.length > 10
  283. wiki_content = letters.collect { |letter| "||table-#{letter}||" }.join("\n\n")
  284. expected_html = letters.collect { |letter| %%<p><table><tr><td>table-#{letter}</td></tr></table></p>% }.join
  285. assert_equal "#{expected_html}", WikiSyntax.new(wiki_content).to_html
  286. end
  287. def test_should_not_generate_a_table
  288. assert_equal "<p>|| no table here</p>", WikiSyntax.new("|| no table here").to_html
  289. end
  290. def test_should_generate_a_table_with_one_row_and_one_cell
  291. assert_equal "<p><table><tr><td> cell1 </td></tr></table></p>", WikiSyntax.new("|| cell1 ||").to_html
  292. end
  293. def test_should_generate_a_table_with_one_row_and_multiple_cells
  294. assert_equal "<p><table><tr><td> cell1 </td><td> cell2 </td><td> cell3 </td></tr></table></p>", WikiSyntax.new("|| cell1 || cell2 || cell3 ||").to_html
  295. end
  296. def test_should_generate_a_table_with_two_rows_and_one_cell
  297. assert_equal "<p><table><tr><td> cell1 </td></tr><tr><td> cell2 </td></tr></table></p>", WikiSyntax.new("|| cell1 ||\n|| cell2 ||").to_html
  298. end
  299. def test_should_generate_a_table_with_two_rows_and_multiple_cells
  300. assert_equal "<p><table><tr><td> cell1 </td><td> cell2 </td><td> cell3 </td></tr><tr><td> cell4 </td><td> cell5 </td><td> cell6 </td></tr></table></p>", WikiSyntax.new("|| cell1 || cell2 || cell3 ||\n|| cell4 || cell5 || cell6 ||").to_html
  301. end
  302. def test_should_generate_two_tables
  303. assert_equal "<p><table><tr><td> cell1 </td></tr></table></p><p><table><tr><td> cell2 </td></tr></table></p>", WikiSyntax.new("|| cell1 ||\n\n|| cell2 ||").to_html
  304. end
  305. end
  306. class WikiSyntaxSummaryTest < Test::Unit::TestCase
  307. def test_should_render_the_summary_in_a_paragraph
  308. assert_equal '<p class="summary">summary of the page</p>', WikiSyntax.new('#summary summary of the page').to_html
  309. end
  310. end
  311. class WikiSyntaxLabelsTest < Test::Unit::TestCase
  312. def test_should_render_the_labels_in_a_paragraph
  313. assert_equal '<p class="labels">label1, label2</p>', WikiSyntax.new('#labels label1, label2').to_html
  314. end
  315. end
  316. begin
  317. require 'tidy'
  318. rescue LoadError
  319. warn "Skipping the next couple of tests because the tidy gem or binary wasn't found"
  320. exit
  321. end
  322. Tidy.path = '/opt/local/lib/libtidy.dylib'
  323. class WikiSyntaxFullTest < Test::Unit::TestCase
  324. def test_should_construct_html_document
  325. expected_html = Tidy.new.clean(self.expected_html)
  326. actual_html = Tidy.new.clean(WikiSyntax.new(wiki_markup).to_html)
  327. assert_equal expected_html, actual_html
  328. end
  329. def wiki_markup
  330. <<-EndWikiMarkup
  331. #summary The document.doctype property ...
  332. #labels about-dom,is-dom-property
  333. == Values ==
  334. The `document.doctype` property returns a string.
  335. This property is read-only.
  336. == Usage ==
  337. == Browser compatibility ==
  338. || *Test* || *IE8* || *IE7* || *IE6* || *FF3* || *FF2* || *Saf3* ||
  339. || [http://doctype.googlecode.com/svn/trunk/tests/js/document/document-doctype-typeof-test.html typeOf(document.doctype) != 'undefined'] || Y || Y || Y || Y || Y || Y ||
  340. == Further reading ==
  341. * [http://developer.mozilla.org/en/docs/DOM:document.doctype The document.doctype property on Mozilla Developer Center]
  342. * [http://msdn2.microsoft.com/en-us/library/ms533737.aspx The document.doctype property on MSDN]
  343. EndWikiMarkup
  344. end
  345. def expected_html
  346. <<EndHtml
  347. <p class="summary">The document.doctype property ...</p>
  348. <p class="labels">about-dom,is-dom-property</p>
  349. <h2>Values</h2>
  350. <p>The <code>document.doctype</code> property returns a string.</p>
  351. <p>This property is read-only.</p>
  352. <h2>Usage</h2>
  353. <h2>Browser compatibility</h2>
  354. <table>
  355. <tr>
  356. <td><strong>Test</strong></td>
  357. <td><strong>IE8</strong></td>
  358. <td><strong>IE7</strong></td>
  359. <td><strong>IE6</strong></td>
  360. <td><strong>FF3</strong></td>
  361. <td><strong>FF2</strong></td>
  362. <td><strong>Saf3</strong></td>
  363. </tr>
  364. <tr>
  365. <td><a href="http://doctype.googlecode.com/svn/trunk/tests/js/document/document-doctype-typeof-test.html">typeOf(document.doctype) != 'undefined'</a></td>
  366. <td>Y</td>
  367. <td>Y</td>
  368. <td>Y</td>
  369. <td>Y</td>
  370. <td>Y</td>
  371. <td>Y</td>
  372. </tr>
  373. </table>
  374. <h2>Further reading</h2>
  375. <ul>
  376. <li><a href="http://developer.mozilla.org/en/docs/DOM:document.doctype">The document.doctype property on Mozilla Developer Center</a></li>
  377. <li><a href="http://msdn2.microsoft.com/en-us/library/ms533737.aspx">The document.doctype property on MSDN</a></li>
  378. </ul>
  379. EndHtml
  380. end
  381. end
  382. class WikiSyntaxToHtmlDocumentTest < Test::Unit::TestCase
  383. def test_should_create_a_complete_html_document
  384. expected_html = Tidy.new.clean(self.expected_html)
  385. actual_html = Tidy.new.clean(WikiSyntax.new(self.wiki_markup).to_html_document('PageTitle'))
  386. assert_equal expected_html, actual_html
  387. end
  388. def wiki_markup
  389. <<EndWikiMarkup
  390. = My Wiki Page =
  391. Some text on my wiki page
  392. EndWikiMarkup
  393. end
  394. def expected_html
  395. <<EndHtml
  396. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  397. <html>
  398. <head>
  399. <title>PageTitle</title>
  400. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  401. </head>
  402. <body>
  403. <h1>My Wiki Page</h1>
  404. <p>Some text on my wiki page</p>
  405. </body>
  406. </html>
  407. EndHtml
  408. end
  409. end