PageRenderTime 102ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/test/mdclj/test/html.clj

https://bitbucket.org/BigYellowCactus/mdclj
Clojure | 86 lines | 67 code | 19 blank | 0 comment | 20 complexity | c756981786cca1987aa7259ee49cf54e MD5 | raw file
  1. (ns mdclj.test.html
  2. (:use [mdclj.html])
  3. (:use [mdclj.blocks :only [parse-text]])
  4. (:use [clojure.test]))
  5. (defn- body []
  6. "foobar")
  7. (deftest create-html-element
  8. (is (= (output-element "Foo" {"Attr1" "12" "Attr2" "stuff"} body)
  9. "<Foo Attr1=\"12\" Attr2=\"stuff\">foobar</Foo>")))
  10. (deftest escaping
  11. (let [text "So < what & is \" up ?"
  12. result "<p>So &lt; what &amp; is &quot; up ?</p>"]
  13. (is (= (format-blocks (parse-text text)) result))))
  14. (deftest parse-html-text
  15. (let [text "# Introducing F#
  16. F# is a _functional-first_ language,
  17. which looks like this:
  18. let msg = \"world\"
  19. printfn \"hello %s!\" msg
  20. This sample prints `hello world!`"]
  21. (is (= (format-blocks (parse-text text)) "<h1>Introducing F#</h1><p>F# is a <em>functional-first</em> language,\nwhich looks like this:</p><pre>let msg = \"world\"\nprintfn \"hello %s!\" msg</pre><p>This sample prints <code>hello world!</code></p>"
  22. ))))
  23. (deftest parse-blockqoute
  24. (let [text "> block"]
  25. (is (= (format-blocks (parse-text text)) "<blockquote><p>block</p></blockquote>"))))
  26. (deftest parse-hrules
  27. (is (= (format-blocks (parse-text "123\n\n---\n")) "<p>123</p><hr />")))
  28. (deftest parse-urls
  29. (is (= (format-blocks (parse-text "[Example](http://example.com Click Me!)")) "<p><a href=\"http://example.com\" title=\"Click Me!\">Example</a></p>"))
  30. (is (= (format-blocks (parse-text "[Example](http://example.com \"Click Me!\")")) "<p><a href=\"http://example.com\" title=\"Click Me!\">Example</a></p>"))
  31. (is (= (format-blocks (parse-text "[Example](http://example.com 'Click Me!')")) "<p><a href=\"http://example.com\" title=\"Click Me!\">Example</a></p>"))
  32. (is (= (format-blocks (parse-text "[Example](http://example.com)")) "<p><a href=\"http://example.com\">Example</a></p>"))
  33. (is (= (format-blocks (parse-text "![](http://example.com)")) "<p><img src=\"http://example.com\" /></p>"))
  34. (is (= (format-blocks (parse-text "![Example](http://example.com \"Click Me!\")")) "<p><img src=\"http://example.com\" alt=\"Example\" title=\"Click Me!\" /></p>"))
  35. (is (= (format-blocks (parse-text "![Example](http://example.com 'Click Me!')")) "<p><img src=\"http://example.com\" alt=\"Example\" title=\"Click Me!\" /></p>")))
  36. (deftest parse-urls1
  37. (let [[http-text http-result] ["<http://stuff>" "<p><a href=\"http://stuff\">http://stuff</a></p>"]]
  38. (is (= (format-blocks (parse-text http-text)) http-result))))
  39. (deftest parse-urls2
  40. (let [[https-text https-result] ["<https://stuff>" "<p><a href=\"https://stuff\">https://stuff</a></p>"]]
  41. (is (= (format-blocks (parse-text https-text)) https-result))))
  42. (deftest parse-urls3
  43. (let [[ftp-text ftp-result] ["<ftp://stuff>" "<p><a href=\"ftp://stuff\">ftp://stuff</a></p>"]]
  44. (is (= (format-blocks (parse-text ftp-text)) ftp-result))))
  45. (deftest parse-urls4
  46. (let [[fail-text fail-result] ["<stuff:test>" "<p><stuff:test></p>"]]
  47. (is (= (format-blocks (parse-text fail-text)) fail-result))))
  48. (deftest parse-urls5
  49. (let [[mail-text mail-result] ["<address@example.com>" "<p><a href=\"&#x6D;&#x61;&#x69;&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;&#x73;&#x73;&#x40;&#x65;&#x78;&#x61;&#x6D;&#x70;&#x6C;&#x65;&#x2E;&#x63;&#x6F;&#x6D;\">&#x61;&#x64;&#x64;&#x72;&#x65;&#x73;&#x73;&#x40;&#x65;&#x78;&#x61;&#x6D;&#x70;&#x6C;&#x65;&#x2E;&#x63;&#x6F;&#x6D;</a></p>"]]
  50. (is (= (format-blocks (parse-text mail-text)) mail-result))))
  51. (deftest parse-reference-style-links
  52. (let [expected "<p>I get 10 times more traffic from <a href=\"http://google.com/\" title=\"Google\">Google</a> than from <a href=\"http://search.yahoo.com/\" title=\"Yahoo Search\">Yahoo</a> or <a href=\"http://search.msn.com/\" title=\"MSN Search\">MSN</a>.</p>"
  53. reference-links
  54. "I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3].
  55. [1]: http://google.com/ \"Google\"
  56. [2]: http://search.yahoo.com/ \"Yahoo Search\"
  57. [3]: http://search.msn.com/ \"MSN Search\""
  58. implicit-link-name
  59. "I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
  60. [google]: http://google.com/ \"Google\"
  61. [yahoo]: http://search.yahoo.com/ \"Yahoo Search\"
  62. [msn]: http://search.msn.com/ \"MSN Search\""
  63. inline-link
  64. "I get 10 times more traffic from [Google](http://google.com/ \"Google\") than from [Yahoo](http://search.yahoo.com/ \"Yahoo Search\") or [MSN](http://search.msn.com/ \"MSN Search\")."]
  65. (is (= (format-blocks (parse-text reference-links)) expected))
  66. (is (= (format-blocks (parse-text implicit-link-name)) expected))
  67. (is (= (format-blocks (parse-text inline-link)) expected))))