summaryrefslogtreecommitdiff
path: root/compojure-3.2/test/compojure/html/gen_test.clj
blob: 5d64b7c500e6688cf85fc7b40b786a9ca412a88d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(ns compojure.html.gen-test
  (:use compojure.html.gen
        clojure.contrib.test-is))

(deftest tag-text
  (is (= (html [:text "Lorem Ipsum"]) "<text>Lorem Ipsum</text>")))

(deftest empty-tags
  (is (= (html [:text]) "<text />")))

(deftest empty-block-tags
  (is (= (html [:div]) "<div></div>"))
  (is (= (html [:h1]) "<h1></h1>"))
  (is (= (html [:script]) "<script></script>")))

(deftest empty-links-tag
  (is (= (html [:a]) "<a></a>")))

(deftest tags-can-be-strs
  (is (= (html ["div"] "<div></div>"))))

(deftest tags-can-be-symbols
  (is (= (html ['div] "<div></div>"))))

(deftest tag-concatenation
  (is (= (html [:body "foo" "bar"]) "<body>foobar</body>"))
  (is (= (html [:body [:p] [:br]])) "<body><p /><br /></body>"))

(deftest tag-seq-expand
  (is (= (html [:body (list "foo" "bar")])
         "<body>foobar</body>")))

(deftest html-seq-expand
  (is (= (html (list [:p "a"] [:p "b"]))
         "<p>a</p><p>b</p>")))

(deftest nested-tags
  (is (= (html [:div [:p]] "<div><p /></div>")))
  (is (= (html [:div [:b]] "<div><b></b></div>")))
  (is (= (html [:p [:span [:a "foo"]]])
         "<p><span><a>foo</a></span></p>")))

(deftest attribute-maps
  (is (= (html [:xml {:a "1", :b "2"}])
         "<xml a=\"1\" b=\"2\" />")))

(deftest blank-attribute-map
  (is (= (html [:xml {}]) "<xml />")))

(deftest escaped-chars
  (is (= (escape-html "\"") "&quot;"))
  (is (= (escape-html "<") "&lt;"))
  (is (= (escape-html ">") "&gt;"))
  (is (= (escape-html "&") "&amp;")))

(deftest escaped-attrs
  (is (= (html [:div {:id "\""}])
         "<div id=\"&quot;\"></div>")))

(deftest attrs-can-be-strs
  (is (= (html [:img {"id" "foo"}]) "<img id=\"foo\" />")))

(deftest attrs-can-be-symbols
  (is (= (html [:img {'id "foo"}]) "<img id=\"foo\" />")))

(deftest attr-keys-different-types
  (is (= (html [:xml {:a "1", 'b "2", "c" "3"}])
         "<xml a=\"1\" b=\"2\" c=\"3\" />")))

(deftest tag-class-sugar
  (is (= (html [:div.foo]) "<div class=\"foo\"></div>")))

(deftest tag-many-class-sugar
  (is (= (html [:div.a.b]) "<div class=\"a b\"></div>"))
  (is (= (html [:div.a.b.c]) "<div class=\"a b c\"></div>")))

(deftest tag-id-sugar
  (is (= (html [:div#foo]) "<div id=\"foo\"></div>")))

(deftest tag-id-and-classes
  (is (= (html [:div#foo.bar.baz])
         "<div class=\"bar baz\" id=\"foo\"></div>")))

(deftest html-not-indented
  (is (= (html [:p "Lorem\nIpsum"]) "<p>Lorem\nIpsum</p>")))

(deftest attrs-bool-true
  (is (= (html [:input {:type "checkbox" :checked true}])
         "<input checked=\"checked\" type=\"checkbox\" />")))

(deftest attrs-bool-false
  (is (= (html [:input {:type "checkbox" :checked false}])
         "<input type=\"checkbox\" />")))