diff options
author | Alan Pearce | 2014-09-13 09:27:10 +0100 |
---|---|---|
committer | Alan Pearce | 2014-09-13 09:27:10 +0100 |
commit | 5955c420a37fdb57eeeeb04c0f649b9d922f7fde (patch) | |
tree | 88eaf4f491c0dadf18885cc76b1b91a234ecb7fd /test | |
parent | 6db0ccd25b4e6cd8724f5723027dca926b0e3aae (diff) | |
download | microformats-5955c420a37fdb57eeeeb04c0f649b9d922f7fde.tar.lz microformats-5955c420a37fdb57eeeeb04c0f649b9d922f7fde.tar.zst microformats-5955c420a37fdb57eeeeb04c0f649b9d922f7fde.zip |
Test smaller units of code
Diffstat (limited to 'test')
-rw-r--r-- | test/microformats/parser_test.clj | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/test/microformats/parser_test.clj b/test/microformats/parser_test.clj index 26cb094..57bb9d2 100644 --- a/test/microformats/parser_test.clj +++ b/test/microformats/parser_test.clj @@ -1,6 +1,7 @@ (ns microformats.parser-test (:require [clojure.test :refer :all] - [microformats.parser :refer :all])) + [microformats.parser :refer :all] + [net.cgrand.enlive-html :refer [html-snippet]])) (deftest empty-document (testing "Empty HTML document should return an empty 'items' array and 'rels' hash." @@ -9,51 +10,51 @@ (deftest parse-p-inner-text (testing "Inner text of a p- property should be parsed") - (are [ex in] (= ex (parse in)) - {:items [{:properties {:name "Example User"}}] :rels {}} - "<div class=\"h-card\"><p class=\"p-name\">Example User</p></div>" + (are [ex in] (= ex (parse-p (first (html-snippet in)))) + {:name "Example User"} + "<p class=\"p-name\">Example User</p>" - {:items [{:properties {:nickname "exuser"}}] :rels {}} - "<div class=\"h-card\"><p class=\"p-nickname\">exuser</p></div>")) + {:nickname "exuser"} + "<p class=\"p-nickname\">exuser</p>")) (deftest parse-p-special-elements (testing "img, abbr and data elements should be parsed differently" - (are [ex in] (= ex (parse in)) - {:items [{:properties {:name "Example User"}}] :rels {}} - "<div class=\"h-card\"><img class=\"p-name\" alt=\"Example User\"></div>" + (are [ex in] (= ex (parse-p (first (html-snippet in)))) + {:name "Example User"} + "<img class=\"p-name\" alt=\"Example User\">" - {:items [{:properties {:name "Example User"}}] :rels {}} - "<div class=\"h-card h-person\"><abbr class=\"p-name\" title=\"Example User\">@example</abbr></div>" + {:name "Example User"} + "<abbr class=\"p-name\" title=\"Example User\">@example</abbr>" - {:items [{:properties {:name "Example User"}}] :rels {}} - "<div class=\"h-card\"><data class=\"p-name\" value=\"Example User\"></data></div>"))) + {:name "Example User"} + "<data class=\"p-name\" value=\"Example User\"></data>"))) (deftest parse-p-empty-br-hr (testing "br and hr tags should return empty strings" - (are [ex in] (= ex (parse in)) - {:items [{:properties {:name ""}}] :rels {}} - "<div class=\"h-card\"><br class=\"p-name\"/></div>" + (are [ex in] (= ex (parse-p (first (html-snippet in)))) + {:name ""} + "<br class=\"p-name\"/>" - {:items [{:properties {:name ""}}] :rels {}} - "<div class=\"h-card\"><hr class=\"p-name\"/></div>"))) + {:name ""} + "<hr class=\"p-name\"/>"))) (deftest parse-u-elements (testing "Tags should have their values parsed as a u-* value" - (are [ex in] (= ex (parse in)) - {:items [{:properties {:url "http://example.com"}}] :rels {}} - "<div class=\"h-card\"><a class=\"u-url\" href=\"http://example.com\">Awesome example website</a></div>" + (are [ex in] (= ex (parse-u (first (html-snippet in)))) + {:url "http://example.com"} + "<a class=\"u-url\" href=\"http://example.com\">Awesome example website</a>" - {:items [{:properties {:photo "http://example.com/someimage.png"}}] :rels {}} - "<div class=\"h-card\"><img class=\"u-photo\" src=\"http://example.com/someimage.png\"></div>" + {:photo "http://example.com/someimage.png"} + "<img class=\"u-photo\" src=\"http://example.com/someimage.png\">" - {:items [{:properties {:photo "http://example.com/someimage.png"}}] :rels {}} - "<map class=\"h-card\"><area class=\"u-photo\" href=\"http://example.com/someimage.png\"></area></map>" + {:photo "http://example.com/someimage.png"} + "<area class=\"u-photo\" href=\"http://example.com/someimage.png\"></area>" - {:items [{:properties {:photo "http://example.com/someimage.png"}}] :rels {}} - "<div class=\"h-card\"><object class=\"u-photo\" data=\"http://example.com/someimage.png\"></object></div>" + {:photo "http://example.com/someimage.png"} + "<object class=\"u-photo\" data=\"http://example.com/someimage.png\"></object>" - {:items [{:properties {:photo "http://example.com/someimage.png"}}] :rels {}} - "<div class=\"h-card\"><abbr class=\"u-photo\" title=\"http://example.com/someimage.png\"></abbr></div>" + {:photo "http://example.com/someimage.png"} + "<abbr class=\"u-photo\" title=\"http://example.com/someimage.png\"></abbr>" - {:items [{:properties {:photo "http://example.com/someimage.png"}}] :rels {}} - "<div class=\"h-card\"><data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data></div>"))) + {:photo "http://example.com/someimage.png"} + "<data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data>"))) |