diff --git a/project.clj b/project.clj index 547388b..ee5c8e5 100644 --- a/project.clj +++ b/project.clj @@ -11,9 +11,11 @@ :all (constantly true)} :auto-clean false - :aliases {"cleantest" ["do" "clean," "test"] - "install" ["do" "clean," "install"] - "deploy" ["do" "clean," "deploy" "clojars"]} + :aliases {"test-cljs" ["doo" "rhino" "test" "once"] + "test" ["do" "test," "test-cljs"] + "cleantest" ["do" "clean," "test"] + "install" ["do" "clean," "install"] + "deploy" ["do" "clean," "deploy" "clojars"]} :source-paths ["src/clj" "src/cljc" "src/cljs"] :cljsbuild @@ -25,11 +27,21 @@ :pretty-print false}} :dev {:compiler {:optimizations :whitespace - :pretty-print true}}}} + :pretty-print true}} + + :test + {:source-paths ["src/cljc" "src/cljs" "test"] + :compiler {:output-to "target/unit-test.js" + :output-dir "target" + :main mdtest.runner + :optimizations :whitespace}}}} :profiles {:dev {:jvm-opts ["-XX:-TieredCompilation"] :dependencies [[criterium "0.4.3" :scope "test"] [commons-lang "2.6" :scope "test"] - [org.clojure/clojurescript "1.7.145"]] - :plugins [[lein-cljsbuild "1.0.6"]]}}) + [org.clojure/clojurescript "1.7.145"] + [org.mozilla/rhino "1.7.7"]] + :plugins [[lein-cljsbuild "1.0.6"] + [lein-doo "0.1.6"]]}} + :doo {:paths {:rhino "lein run -m org.mozilla.javascript.tools.shell.Main"}}) diff --git a/test/mdtest_runner.cljs b/test/mdtest_runner.cljs new file mode 100644 index 0000000..d0e1d11 --- /dev/null +++ b/test/mdtest_runner.cljs @@ -0,0 +1,5 @@ +(ns mdtest.runner + (:require [doo.runner :refer-macros [doo-tests]] + [mdtests])) + +(doo-tests 'mdtests) diff --git a/test/mdtests.clj b/test/mdtests.cljc similarity index 51% rename from test/mdtests.clj rename to test/mdtests.cljc index 3aabc8e..e52d51c 100644 --- a/test/mdtests.clj +++ b/test/mdtests.cljc @@ -1,112 +1,118 @@ (ns mdtests (:require [markdown.core :as markdown] [markdown.transformers :as transformers] - [markdown.tables :as tables]) - (:use clojure.test)) + [markdown.tables :as tables] + #?(:clj [clojure.test :refer :all] + :cljs [cljs.test :refer-macros [deftest is testing]]) + #?(:cljs [goog.string]))) + +(def entry-function + #?(:clj markdown/md-to-html-string + :cljs markdown/md->html)) (deftest heading1 - (is (= "
foo
foo \n
bar" (markdown/md-to-html-string "```\nfoo \nbar```"))))
+ (is (= "foo
foo \n
bar" (entry-function "```\nfoo \nbar```"))))
(deftest hr
- (is (= "foo
" (markdown/md-to-html-string "*foo*")))) + (is (= "foo
" (entry-function "*foo*")))) (deftest italics - (is (= "foo
" (markdown/md-to-html-string "_foo_")))) + (is (= "foo
" (entry-function "_foo_")))) (deftest strong - (is (= "foo
" (markdown/md-to-html-string "**foo**")))) + (is (= "foo
" (entry-function "**foo**")))) (deftest bold - (is (= "foo
" (markdown/md-to-html-string "__foo__")))) + (is (= "foo
" (entry-function "__foo__")))) (deftest strong-inside-em - (is (= "foobarbaz
" (markdown/md-to-html-string "*foo**bar**baz*")))) + (is (= "foobarbaz
" (entry-function "*foo**bar**baz*")))) (deftest em-inside-strong - (is (= "foobarbaz
" (markdown/md-to-html-string "**foo*bar*baz**")))) + (is (= "foobarbaz
" (entry-function "**foo*bar*baz**")))) (deftest paragraph (is (= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
" - (markdown/md-to-html-string "\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore")))) + (entry-function "\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore")))) (deftest paragraph-multiline (is (= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
" - (markdown/md-to-html-string "\nLorem ipsum dolor\nsit amet, consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut labore")))) + (entry-function "\nLorem ipsum dolor\nsit amet, consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut labore")))) (deftest mulitple-paragraphs (is (= "foo bar baz
foo bar baz
" - (markdown/md-to-html-string "\nfoo bar baz\n\n\nfoo bar baz")))) + (entry-function "\nfoo bar baz\n\n\nfoo bar baz")))) (deftest ul (is (= "paragraph next line
" - (markdown/md-to-html-string "* foo\n* bar\n* baz\n\nparagraph\nnext line")))) + (entry-function "* foo\n* bar\n* baz\n\nparagraph\nnext line")))) (deftest ul-followed-by-multiline-paragraph (is (= "paragraph
" - (markdown/md-to-html-string "* foo\n* bar\n* baz\n\nparagraph")))) + (entry-function "* foo\n* bar\n* baz\n\nparagraph")))) (deftest ul-nested (is (= "foo bar baz x = y + z;
foo
<?xml version='1.0' encoding='UTF-8'?><channel></channel>
foo bar baz (fn [x & xs] (str "x:" x))
foo
x = 5\ny = 6\nz = x + y
"
- (markdown/md-to-html-string " x = 5\n y = 6\n z = x + y")))
+ (entry-function " x = 5\n y = 6\n z = x + y")))
(is (= "x = 5\ny = 6\nz = x + y\n(fn [x & xs] (str "x"))
"
- (markdown/md-to-html-string " x = 5\n y = 6\n z = x + y\n (fn [x & xs] (str \"x\"))"))))
+ (entry-function " x = 5\n y = 6\n z = x + y\n (fn [x & xs] (str \"x\"))"))))
(deftest codeblock
(is (= "(defn- write [writer text]\n (doseq [c text]\n (.write writer (int c))))\n
"
- (markdown/md-to-html-string "``` (defn- write [writer text]\n (doseq [c text]\n (.write writer (int c))))\n```")))
+ (entry-function "``` (defn- write [writer text]\n (doseq [c text]\n (.write writer (int c))))\n```")))
(is (= "(fn [x & xs]\n (str "x"))\n
"
- (markdown/md-to-html-string "``` (fn [x & xs]\n (str \"x\"))\n```")))
+ (entry-function "``` (fn [x & xs]\n (str \"x\"))\n```")))
(is (= "(fn [x & xs]\n (str "x"))\n
"
- (markdown/md-to-html-string "```\n(fn [x & xs]\n (str \"x\"))\n```")))
+ (entry-function "```\n(fn [x & xs]\n (str \"x\"))\n```")))
(is (= "(fn [x & xs]\n (str "x"))\n
"
- (markdown/md-to-html-string "```clojure (fn [x & xs]\n (str \"x\"))\n```")))
+ (entry-function "```clojure (fn [x & xs]\n (str \"x\"))\n```")))
(is (= "------------\n============\n ------------\n ============\n
"
- (markdown/md-to-html-string
+ (entry-function
"
```nohighlight
------------
@@ -151,141 +157,124 @@
------------
============
```
-"
- ))))
+"))))
(deftest stirkethrough
(is (= "foo
foobar baz
" - (markdown/md-to-html-string "foo^bar baz")))) + (entry-function "foo^bar baz")))) (deftest link (is (= "" - (markdown/md-to-html-string "[github](http://github.com)"))) + (entry-function "[github](http://github.com)"))) (is (= "" - (markdown/md-to-html-string "[github](http://github.com/~)"))) + (entry-function "[github](http://github.com/~)"))) (is (= "" - (markdown/md-to-html-string "[github](http://github.com/^)"))) + (entry-function "[github](http://github.com/^)"))) (is (= "" - (markdown/md-to-html-string "[github](http://github.com/*)"))) + (entry-function "[github](http://github.com/*)"))) (is (= "" - (markdown/md-to-html-string "* [github](http://github.com/*)"))) + (entry-function "* [github](http://github.com/*)"))) (is (= "[github](http://github.comfooo
" - (markdown/md-to-html-string "[github](http://github.comfooo"))) + (entry-function "[github](http://github.comfooo"))) (is (= "[github] no way (http://github.com)
" - (markdown/md-to-html-string "[github] no way (http://github.com)")))) + (entry-function "[github] no way (http://github.com)")))) (deftest bad-link-title (is (= "[github(http://github.comfooo)
" - (markdown/md-to-html-string "[github(http://github.comfooo)")))) + (entry-function "[github(http://github.comfooo)")))) (deftest blockquote (is (= "" - (markdown/md-to-html-string ">Foo bar baz")))) + (entry-function ">Foo bar baz")))) (deftest blockquote-footer (is (= "Foo bar baz
" - (markdown/md-to-html-string "> Foo bar baz\n>- Leo Tolstoy")))) + (entry-function "> Foo bar baz\n>- Leo Tolstoy")))) (deftest blockquote-empty-footer (is (= "Foo bar baz
" - (markdown/md-to-html-string "> Foo bar baz\n>-")))) + (entry-function "> Foo bar baz\n>-")))) (deftest blockquote-multiline-without-leading-angle-bracket (is (= "Foo bar baz
" - (markdown/md-to-html-string "> Foo bar\nbaz")))) + (entry-function "> Foo bar\nbaz")))) (deftest blockquote-multiple-paragraphs (is (= "Foo bar baz
" - (markdown/md-to-html-string "> Foo bar\n>\n> baz")))) + (entry-function "> Foo bar\n>\n> baz")))) (deftest escaped-characters (is (= "Foo bar
baz
*‘_{}[]footest
bar{x}[y]
test bold and italic
" - (markdown/md-to-html-string "1. a\n2. b\n\ntest **bold** and *italic*")))) + (entry-function "1. a\n2. b\n\ntest **bold** and *italic*")))) (deftest paragraph-close-before-list (is (= "in paragraph
http://foo https://bar/baz foo bar
" - (markdown/md-to-html-string "The fish was 192.8 lbs and was amazing to see.
" - (markdown/md-to-html-string "The fish was\n192.8 lbs and was amazing to see.")))) + (entry-function "The fish was\n192.8 lbs and was amazing to see.")))) (deftest dont-encode-chars-in-hrefs (is (= "example_link with tilde ~ and carat ^ and splat *
" - (markdown/md-to-html-string "[example_link with tilde ~ and carat ^ and splat *](http://www.google.com/example_link_foo~_^*)")))) + (entry-function "[example_link with tilde ~ and carat ^ and splat *](http://www.google.com/example_link_foo~_^*)")))) (deftest complex-link-with-terminal-encoding-inside-header (is (= "boo – bar
" (markdown/md-to-html-string "boo -- bar")))) + (is (= "boo – bar
" (entry-function "boo -- bar")))) (deftest m-dash - (is (= "boo — bar
" (markdown/md-to-html-string "boo --- bar")))) + (is (= "boo — bar
" (entry-function "boo --- bar")))) diff --git a/test/mdtests_file.clj b/test/mdtests_file.clj new file mode 100644 index 0000000..f0ce1fb --- /dev/null +++ b/test/mdtests_file.clj @@ -0,0 +1,40 @@ +(ns mdtests-file + (:require [markdown.core :as markdown] + [markdown.transformers :as transformers] + [markdown.tables :as tables] + [clojure.test :refer :all])) + +(deftest references + (let [wrt (java.io.StringWriter.)] + (markdown/md-to-html (str "test" java.io.File/separator "references.md") wrt :reference-links? true) + (is (= (slurp (str "test" java.io.File/separator "references.html")) (.toString wrt))))) + +(deftest footnotes + (let [wrt (java.io.StringWriter.)] + (markdown/md-to-html (str "test" java.io.File/separator "footnotes.md") wrt :footnotes? true) + (is (= (slurp (str "test" java.io.File/separator "footnotes.html")) (.toString wrt))))) + +(deftest all-together + (let [wrt (java.io.StringWriter.)] + (markdown/md-to-html (str "test" java.io.File/separator "test.md") wrt) + (is (= (slurp (str "test" java.io.File/separator "test.html")) (.toString wrt))))) + +(deftest tables + (let [wrt (java.io.StringWriter.)] + (markdown/md-to-html (str "test" java.io.File/separator "tables.md") wrt) + (is (= (slurp (str "test" java.io.File/separator "tables.html")) (.toString wrt))))) + +(deftest md-metadata + (testing "Finds all metadata and correctly parses rest of file." + (let [md (slurp (str "test/metadata.md")) + {:keys [metadata html]} (markdown/md-to-html-string-with-meta md)] + (is (= "