about summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorAlan Pearce2014-09-14 13:35:26 +0100
committerAlan Pearce2014-09-15 19:16:41 +0100
commitd44305ac37fe2d92aad4bb0ef5602133050d4f2a (patch)
tree3414abb1568b56c226260d0d9c67318979f5176d /test
parent11c75c3e47c4afdd419c13e68fa5e0f795daa715 (diff)
downloadmicroformats-d44305ac37fe2d92aad4bb0ef5602133050d4f2a.tar.lz
microformats-d44305ac37fe2d92aad4bb0ef5602133050d4f2a.tar.zst
microformats-d44305ac37fe2d92aad4bb0ef5602133050d4f2a.zip
Switch to expectations test library
Diffstat (limited to 'test')
-rw-r--r--test/microformats/parser_expectations.clj101
-rw-r--r--test/microformats/parser_test.clj132
2 files changed, 101 insertions, 132 deletions
diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj
new file mode 100644
index 0000000..742b8e7
--- /dev/null
+++ b/test/microformats/parser_expectations.clj
@@ -0,0 +1,101 @@
+(ns microformats.parser-expectations
+  (:require [expectations :refer :all]
+            [microformats.parser :refer :all]
+            [net.cgrand.enlive-html :refer [html-snippet]]))
+
+(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 <strong>bar</strong>"
+        (apply str (#'microformats.parser/node-to-html '("Foo " {:tag :strong, :attrs nil, :content ("bar")}))))
+
+(expect {:name "Example User"}
+        (parse-p (first (html-snippet "<p class=\"p-name\">Example User</p>"))))
+
+(expect {:nickname "exuser"}
+        (parse-p (first (html-snippet "<p class=\"p-nickname\">exuser</p>"))))
+
+(expect {:name "Example User"}
+        (parse-p (first (html-snippet "<img class=\"p-name\" alt=\"Example User\">"))))
+
+(expect {:name "Example User"}
+        (parse-p (first (html-snippet "<abbr class=\"p-name\" title=\"Example User\">@example</abbr>"))))
+
+(expect {:name "@example"}
+        (parse-p (first (html-snippet "<abbr class=\"p-name\">@example</abbr>"))))
+
+(expect {:name "Example User"}
+        (parse-p (first (html-snippet "<data class=\"p-name\" value=\"Example User\"></data>"))))
+
+(expect {:name "Example User"}
+        (parse-p (first (html-snippet "<data class=\"p-name\">Example User</data>"))))
+
+(expect {:name ""}
+        (parse-p (first (html-snippet "<br class=\"p-name\"/>"))))
+
+(expect {:name ""}
+        (parse-p (first (html-snippet "<hr class=\"p-name\"/>"))))
+
+(expect {:url "http://example.com"}
+        (parse-u (first (html-snippet "<a class=\"u-url\" href=\"http://example.com\">Awesome example website</a>"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<img class=\"u-photo\" src=\"http://example.com/someimage.png\">"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<area class=\"u-photo\" href=\"http://example.com/someimage.png\"></area>"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<object class=\"u-photo\" data=\"http://example.com/someimage.png\"></object>"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<abbr class=\"u-photo\" title=\"http://example.com/someimage.png\"></abbr>"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<abbr class=\"u-photo\">http://example.com/someimage.png</abbr>"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data>"))))
+
+(expect {:photo "http://example.com/someimage.png"}
+        (parse-u (first (html-snippet "<data class=\"u-photo\">http://example.com/someimage.png</data>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<time class=\"dt-start\" datetime=\"2012-08-05T14:50\"></time>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<time class=\"dt-start\">2012-08-05T14:50</time>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<ins class=\"dt-start\" datetime=\"2012-08-05T14:50\"></ins>"))))
+
+(expect {:end "2012-08-05T18:00"}
+        (parse-dt (first (html-snippet "<del class=\"dt-end\" datetime=\"2012-08-05T18:00\"></del>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<abbr class=\"dt-start\" title=\"2012-08-05T14:50\"></abbr>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<abbr class=\"dt-start\">2012-08-05T14:50</abbr>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<data class=\"dt-start\" value=\"2012-08-05T14:50\"></data>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<data class=\"dt-start\">2012-08-05T14:50</data>"))))
+
+(expect {:start "2012-08-05T14:50"}
+        (parse-dt (first (html-snippet "<input class=\"dt-start\" value=\"2012-08-05T14:50\">"))))
+
+(expect {:content {:html "Here is a load of <strong>embedded markup</strong>" :value "Here is a load of embedded markup"}}
+        (parse-e (first (html-snippet "<div class=\"e-content\">Here is a load of <strong>embedded markup</strong></div>"))))
+
+(expect {:author ["http://example.com/a"]}
+        (parse-rels (html-snippet "<a rel=\"author\" href=\"http://example.com/a\">author a</a>")))
+
+(expect {:author ["http://example.com/a" "http://example.com/b"]}
+        (parse-rels (html-snippet "<a rel=\"author\" href=\"http://example.com/a\">author a</a>
+<a rel=\"author\" href=\"http://example.com/b\">author b</a>")))
diff --git a/test/microformats/parser_test.clj b/test/microformats/parser_test.clj
deleted file mode 100644
index 51c45c7..0000000
--- a/test/microformats/parser_test.clj
+++ /dev/null
@@ -1,132 +0,0 @@
-(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 classes-to-props-property-names
-  (testing "`classes-to-props' should return property name without prefix"
-    (are [ex in] (= ex (into [] ((classes-to-props "p-") in)))
-         [:location]
-         ["someclass" "p-location" "someotherclass"]
-
-         [:location :name]
-         ["someclass" "p-location" "someotherclass" "p-name"])))
-
-(deftest node-to-html-string
-  (testing "`node-to-html' should return a string of HTML content"
-    (are [ex in] (= ex (apply str (#'microformats.parser/node-to-html in)))
-         "Foo <strong>bar</strong>"
-         '("Foo " {:tag :strong, :attrs nil, :content ("bar")}))))
-
-(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>")))
-
-(deftest parse-dt-elements
-  (testing "Tags with dt-* classes should have their values parsed"
-    (are [ex in] (= ex (parse-dt (first (html-snippet in))))
-         {:start "2012-08-05T14:50"}
-         "<time class=\"dt-start\" datetime=\"2012-08-05T14:50\"></time>"
-
-         {:start "2012-08-05T14:50"}
-         "<time class=\"dt-start\">2012-08-05T14:50</time>"
-
-         {:start "2012-08-05T14:50"}
-         "<ins class=\"dt-start\" datetime=\"2012-08-05T14:50\"></ins>"
-
-         {:end "2012-08-05T18:00"}
-         "<del class=\"dt-end\" datetime=\"2012-08-05T18:00\"></del>"
-
-         {:start "2012-08-05T14:50"}
-         "<abbr class=\"dt-start\" title=\"2012-08-05T14:50\"></abbr>"
-
-         {:start "2012-08-05T14:50"}
-         "<abbr class=\"dt-start\">2012-08-05T14:50</abbr>"
-
-         {:start "2012-08-05T14:50"}
-         "<data class=\"dt-start\" value=\"2012-08-05T14:50\"></data>"
-
-         {:start "2012-08-05T14:50"}
-         "<data class=\"dt-start\">2012-08-05T14:50</data>"
-
-         {:start "2012-08-05T14:50"}
-         "<input class=\"dt-start\" value=\"2012-08-05T14:50\">")))
-
-(deftest parse-e-elements
-  (testing "Tags with e-* classes should have ther content parsed"
-    (are [ex in] (= ex (parse-e (first (html-snippet in))))
-         {:content {:html "Here is a load of <strong>embedded markup</strong>" :value "Here is a load of embedded markup"}}
-         "<div class=\"e-content\">Here is a load of <strong>embedded markup</strong></div>")))
-
-(deftest parse-rel-test
-  (testing "link and a tags with rel attributes should be parsed"
-    (are [ex in] (= ex (parse-rels (html-snippet in)))
-         {:author ["http://example.com/a"]}
-         "<a rel=\"author\" href=\"http://example.com/a\">author a</a>"
-
-         {:author ["http://example.com/a" "http://example.com/b"]}
-         "<a rel=\"author\" href=\"http://example.com/a\">author a</a><a rel=\"author\" href=\"http://example.com/b\">author b</a>")))