(ns microformats.parser-expectations
(:require [expectations :refer :all]
[microformats.parser :refer :all]
[net.cgrand.enlive-html :refer [html-snippet]]))
(defn- snippet
[html]
(first (html-snippet html)))
(expect [:location]
(into [] ((classes-to-props "p-") ["someclass" "p-location" "someotherclass"])))
(expect [:location :name]
(into [] ((classes-to-props "p-") ["someclass" "p-location" "someotherclass" "p-name"])))
(expect "Foo bar"
(apply str (#'microformats.parser/node-to-html '("Foo " {:tag :strong, :attrs nil, :content ("bar")}))))
(expect "665 3rd St. Suite 207"
(->> "
665 3rd St.
Suite 207
"
snippet :content
(#'microformats.parser/node-to-text)))
(expect '({:tag :div :attrs {:class "h-card"}
:content nil})
(select-h (snippet
"")))
(expect '({:tag :div :attrs {:class "h-card"}
:content ({:tag :a :attrs {:class "h-org"}
:content nil})})
(select-h (snippet
"")))
(expect '({:tag :div :attrs {:class "h-card"}
:content ("\n"
{:tag :p :attrs nil
:content ({:tag :a :attrs {:class "h-org"}
:content nil})}
"\n")})
(select-h (snippet "")))
(expect {:name '("Name")}
(parse-p (snippet "Name
")))
(expect {:name '("Name Endname")}
(parse-p (snippet "Name (this should not be included) Endname
")))
(expect {:name '("Example User")}
(parse-p (snippet "Example User
")))
(expect {:nickname '("exuser")}
(parse-p (snippet "exuser
")))
(expect {:name '("Example User")}
(parse-p (snippet "
")))
(expect {:name '("Example User")}
(parse-p (snippet "@example")))
(expect {:name '("@example")}
(parse-p (snippet "@example")))
(expect {:name '("Example User")}
(parse-p (snippet "")))
(expect {:name '("Example User")}
(parse-p (snippet "Example User")))
(expect {:name '("")}
(parse-p (snippet "
")))
(expect {:name '("")}
(parse-p (snippet "
")))
(expect {:url '("http://example.com")}
(parse-u (snippet "Awesome example website")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "
")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "http://example.com/someimage.png")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "http://example.com/someimage.png")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "")))
(expect {:end '("2012-08-05T18:00")}
(parse-dt (snippet "")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "2012-08-05T14:50")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "2012-08-05T14:50")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "")))
(expect {:content '({:html "Here is a load of embedded markup" :value "Here is a load of embedded markup"})}
(parse-e (snippet "Here is a load of embedded markup
")))
(expect {:author ["http://example.com/a"]}
(parse-rels (html-snippet "author a")))
(expect {:author ["http://example.com/a" "http://example.com/b"]}
(parse-rels (html-snippet "author a
author b")))
(expect {:items [] :rels {}}
(parse ""))
(expect {:items [{:properties {:name '("Example User")} :type ["h-card"]}] :rels {}}
(parse ""))
(expect {:items [{:properties {:name '("Example User")} :type ["h-card"]}] :rels {}}
(parse ""))
(expect {:items [{:properties {:name '("Example User") :url '("http://example.com")}
:type ["h-card"]}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse "Example User
"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User") :url '("http://example.com")}}] :rels {}}
(parse "Example User"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")
:photo '("http://example.com/me.png")}}] :rels {}}
(parse "
"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse "Incorrect"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse "![\"Example]()
"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse "Wrong
"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:photo '("http://example.com/me.png")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")
:photo '("http://example.com/me.png")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:photo '("http://example.com/me.png")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:photo '("http://example.com/me.png")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")
:photo '("http://example.com/me.png")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User") :url '("http://example.com")}}] :rels {}}
(parse ""))
(expect {:items [{:type ["h-card"] :properties {:name '("Example")
:url '("http://example.com"
"http://myblog.com")}}]
:rels {}}
(parse ""))
(expect {:items [{:type ["h-card"]
:properties {:name '("Example")
:tel '("01234567890")}}]
:rels {}}
(parse ""))
(expect
{:items [{:type ["h-adr"],
:properties {:street-address '("665 3rd St."),
:extended-address '("Suite 207"),
:locality '("San Francisco"),
:region '("CA"),
:postal-code '("94107"),
:country-name '("U.S.A."),
:name '("665 3rd St. Suite 207 San Francisco, CA 94107 U.S.A.")}}]
:rels {}}
(parse "
665 3rd St.
Suite 207
San Francisco,
CA
94107
U.S.A.
"))
(expect {:items [{:type ["h-card" "h-org"]
:properties {:name '("Example")}}]
:rels {}}
(parse "Example
"))