test/microformats/parser_test.clj (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | (ns microformats.parser-test (:require [clojure.test :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." (is (= {:items [] :rels {}} (parse ""))))) (deftest parse-p-inner-text (testing "Inner text of a p- property should be parsed") (are [ex in] (= ex (parse-p (first (html-snippet in)))) {:name "Example User"} "<p class=\"p-name\">Example User</p>" {: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-p (first (html-snippet in)))) {:name "Example User"} "<img class=\"p-name\" alt=\"Example User\">" {:name "Example User"} "<abbr class=\"p-name\" title=\"Example User\">@example</abbr>" {:name "@example"} "<abbr class=\"p-name\">@example</abbr>" {:name "Example User"} "<data class=\"p-name\" value=\"Example User\"></data>" {:name "Example User"} "<data class=\"p-name\">Example User</data>"))) (deftest parse-p-empty-br-hr (testing "br and hr tags should return empty strings" (are [ex in] (= ex (parse-p (first (html-snippet in)))) {:name ""} "<br class=\"p-name\"/>" {: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-u (first (html-snippet in)))) {:url "http://example.com"} "<a class=\"u-url\" href=\"http://example.com\">Awesome example website</a>" {:photo "http://example.com/someimage.png"} "<img class=\"u-photo\" src=\"http://example.com/someimage.png\">" {:photo "http://example.com/someimage.png"} "<area class=\"u-photo\" href=\"http://example.com/someimage.png\"></area>" {:photo "http://example.com/someimage.png"} "<object class=\"u-photo\" data=\"http://example.com/someimage.png\"></object>" {:photo "http://example.com/someimage.png"} "<abbr class=\"u-photo\" title=\"http://example.com/someimage.png\"></abbr>" {:photo "http://example.com/someimage.png"} "<abbr class=\"u-photo\">http://example.com/someimage.png</abbr>" {:photo "http://example.com/someimage.png"} "<data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data>" {:photo "http://example.com/someimage.png"} "<data class=\"u-photo\">http://example.com/someimage.png</data>"))) |