(ns hiccup2.core-test (:require [clojure.test :refer :all] [hiccup2.core :refer :all] [hiccup.util :as util])) (deftest return-types #_(testing "html returns a RawString" (is (util/raw-string? (html [:div])))) (testing "converting to string" (= (str (html [:div])) "
"))) (deftest tag-names (testing "basic tags" (is (= (str (html [:div])) "")) (is (= (str (html ["div"])) "")) (is (= (str (html ['div])) ""))) (testing "tag syntax sugar" (is (= (str (html [:div#foo])) "")) (is (= (str (html [:div.foo])) "")) (is (= (str (html [:div.foo (str "bar" "baz")])) "a
b
"))) (testing "keywords are turned into strings" (is (= (str (html [:div :foo])) "
")))
(testing "boolean attributes"
(is (= (str (html {:mode :xml} [:input {:type "checkbox" :checked true}]))
""))
(is (= (str (html {:mode :sgml} [:input {:type "checkbox" :checked true}]))
"")))
(testing "laziness and binding scope"
(is (= (str (html {:mode :sgml} [:html [:link] (list [:link])]))
"")))
(testing "function binding scope"
(let [f #(html [:p "<>" [:br]])]
(is (= (str (html (f))) "
<>
<>
<>
<>
<foo>
<bar>
")) (is (= (str (html ((constantly "<>
")) (is (= (str (html [:p :<>])) "<>
")) (is (= (str (html [:p {} {"{"<foo>" "<bar>"}
")) (is (= (str (html [:p {} #{"#{"<foo>"}
")) (is (= (str (html [:p {:class "<\">"}])) "")) (is (= (str (html [:p {:class ["<\">"]}])) "")) (is (= (str (html [:ul [:li "<>
")) (is (= (str (html [:ul (html [:li "<>"])])) "<>
")) (is (= (str (html {:escape-strings? false} [:p "<>"])) "<>
"))) (testing "dynamic generation" (let [x [:p "<>"]] (is (= (str (html {:escape-strings? true} x)) "<>
")) (is (= (str (html {:escape-strings? false} x)) "<>
")))) (testing "attributes" (is (= (str (html {:escape-strings? true} [:p {:class "<>"}])) "")) (is (= (str (html {:escape-strings? false} [:p {:class "<>"}])) ""))) (testing "raw strings" (is (= (str (html {:escape-strings? true} [:p (util/raw-string "<>")])) "<>
")) (is (= (str (html {:escape-strings? false} [:p (util/raw-string "<>")])) "<>
")) #_(is (= (str (html {:escape-strings? true} [:p (raw "<>")])) "<>
")) #_(is (= (str (html {:escape-strings? false} [:p (raw "<>")])) "<>
"))))