From 49ed30908feb17d4ca6ea5dd2536b7cf79e395d1 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 10 Oct 2014 16:12:53 +0100 Subject: Use zippers all the way down Includes an ugly "workaround" for interface differences in enlive between select and zip-select --- test/microformats/parser_expectations.clj | 42 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj index 0e72e10..6ce942e 100644 --- a/test/microformats/parser_expectations.clj +++ b/test/microformats/parser_expectations.clj @@ -4,9 +4,13 @@ [clojure.zip :as z] [net.cgrand.enlive-html :refer [html-snippet]])) +(defn- snippets + [html] + (map z/xml-zip (html-snippet html))) + (defn- snippet [html] - (first (html-snippet html))) + (first (snippets html))) (expect [:location] (into [] ((classes-to-props "p-") ["someclass" "p-location" "someotherclass"]))) @@ -22,34 +26,34 @@ 665 3rd St. Suite 207

" - snippet :content + snippet z/node :content (#'microformats.parser/node-to-text))) (expect '({:tag :div :attrs {:class "h-card"} :content nil}) - (map-h identity (z/xml-zip (snippet - "
")))) + (map-h z/node (snippet + "
"))) (expect '({:tag :div :attrs {:class "h-card"} :content nil}) - (map-h identity (z/xml-zip (snippet - "
")))) + (map-h z/node (snippet + "
"))) (expect '({:tag :div :attrs {:class "h-card"} :content ({:tag :a :attrs {:class "h-org"} :content nil})}) - (map-h identity (z/xml-zip (snippet - "
")))) - -(expect '({:tag :div :attrs {:class "h-card"} - :content ("\n" - {:tag :p :attrs nil - :content ({:tag :a :attrs {:class "h-org"} - :content nil})} - "\n")}) - (map-h identity (z/xml-zip (snippet "
+ (map-h z/node (snippet + "
"))) + +(expect {:tag :div :attrs {:class "h-card"} + :content ["\n" + {:tag :p :attrs nil + :content [{:tag :a :attrs {:class "h-org"} + :content nil}]} + "\n"]} + (z/node (snippet "

-
")))) +
"))) (expect "http://example.com" (get-base-url (snippet ""))) @@ -151,10 +155,10 @@ (parse-e (snippet "
Here is a load of embedded markup
"))) (expect {:author '("http://example.com/a")} - (parse-rels (html-snippet "author a"))) + (parse-rels (snippets "author a"))) (expect {:author '("http://example.com/a" "http://example.com/b")} - (parse-rels (html-snippet "author a + (parse-rels (snippets "author a author b"))) (expect {:items nil :rels {}} -- cgit 1.4.1