From d44305ac37fe2d92aad4bb0ef5602133050d4f2a Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 14 Sep 2014 13:35:26 +0100 Subject: Switch to expectations test library --- project.clj | 2 + test/microformats/parser_expectations.clj | 101 +++++++++++++++++++++++ test/microformats/parser_test.clj | 132 ------------------------------ 3 files changed, 103 insertions(+), 132 deletions(-) create mode 100644 test/microformats/parser_expectations.clj delete mode 100644 test/microformats/parser_test.clj diff --git a/project.clj b/project.clj index a191c8a..5b0d719 100644 --- a/project.clj +++ b/project.clj @@ -5,4 +5,6 @@ :url "http://opensource.org/licenses/MIT"} :dependencies [[org.clojure/clojure "1.6.0"] [enlive "1.1.5"]] + :profiles {:dev {:dependencies [[expectations "2.0.9"]]}} + :plugins [[lein-expectations "0.0.7"]] :main microformats.parser) 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 bar" + (apply str (#'microformats.parser/node-to-html '("Foo " {:tag :strong, :attrs nil, :content ("bar")})))) + +(expect {:name "Example User"} + (parse-p (first (html-snippet "

Example User

")))) + +(expect {:nickname "exuser"} + (parse-p (first (html-snippet "

exuser

")))) + +(expect {:name "Example User"} + (parse-p (first (html-snippet "\"Example")))) + +(expect {:name "Example User"} + (parse-p (first (html-snippet "@example")))) + +(expect {:name "@example"} + (parse-p (first (html-snippet "@example")))) + +(expect {:name "Example User"} + (parse-p (first (html-snippet "")))) + +(expect {:name "Example User"} + (parse-p (first (html-snippet "Example User")))) + +(expect {:name ""} + (parse-p (first (html-snippet "
")))) + +(expect {:name ""} + (parse-p (first (html-snippet "
")))) + +(expect {:url "http://example.com"} + (parse-u (first (html-snippet "Awesome example website")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "http://example.com/someimage.png")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "")))) + +(expect {:photo "http://example.com/someimage.png"} + (parse-u (first (html-snippet "http://example.com/someimage.png")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "")))) + +(expect {:end "2012-08-05T18:00"} + (parse-dt (first (html-snippet "")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "2012-08-05T14:50")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "2012-08-05T14:50")))) + +(expect {:start "2012-08-05T14:50"} + (parse-dt (first (html-snippet "")))) + +(expect {:content {:html "Here is a load of embedded markup" :value "Here is a load of embedded markup"}} + (parse-e (first (html-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"))) 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 bar" - '("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"} - "

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"} - "\"Example" - - {: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"))) - -(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"} - "" - - {:start "2012-08-05T14:50"} - "" - - {:start "2012-08-05T14:50"} - "" - - {:end "2012-08-05T18:00"} - "" - - {:start "2012-08-05T14:50"} - "" - - {:start "2012-08-05T14:50"} - "2012-08-05T14:50" - - {:start "2012-08-05T14:50"} - "" - - {:start "2012-08-05T14:50"} - "2012-08-05T14:50" - - {:start "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 embedded markup" :value "Here is a load of embedded markup"}} - "
Here is a load of embedded markup
"))) - -(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"]} - "author a" - - {:author ["http://example.com/a" "http://example.com/b"]} - "author aauthor b"))) -- cgit 1.4.1