diff options
-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>"))) |