(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"}
"
Example User
"
{:nickname "exuser"}
"exuser
"))
(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"}
"
"
{:name "Example User"}
"@example"
{:name "@example"}
"@example"
{:name "Example User"}
""
{:name "Example User"}
"Example User")))
(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 ""}
"
"
{: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"}
"Awesome example website"
{:photo "http://example.com/someimage.png"}
"
"
{:photo "http://example.com/someimage.png"}
""
{:photo "http://example.com/someimage.png"}
""
{:photo "http://example.com/someimage.png"}
""
{:photo "http://example.com/someimage.png"}
"http://example.com/someimage.png"
{:photo "http://example.com/someimage.png"}
""
{:photo "http://example.com/someimage.png"}
"http://example.com/someimage.png")))