Skip to content

Commit a19a9ba

Browse files
committed
Merge branch 'testing' of git://github.com/abedra/compojure into testing
2 parents adfddb0 + cb36033 commit a19a9ba

16 files changed

Lines changed: 247 additions & 206 deletions

build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@
6565
</target>
6666

6767
<target name="test" description="Run tests">
68-
<java fork="true" classname="clojure.lang.Script">
68+
<java fork="true" classname="clojure.main" failonerror="true">
6969
<classpath>
7070
<path refid="classpath"/>
71+
<path location="${tests.dir}"/>
7172
<path location="."/>
7273
</classpath>
7374
<arg value="${tests.dir}/run.clj"/>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(ns test.compojure.crypto
2-
(:use compojure.crypto)
3-
(:use clojure.contrib.test-is))
1+
(ns compojure.crypto-test
2+
(:use compojure.crypto
3+
clojure.contrib.test-is))
44

55
(deftest secret-key-length
66
(are (= (count (gen-secret-key {:key-size _1})) _2)

test/compojure/html/form_helpers.clj

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
(ns compojure.html.form-helpers-test
2+
(:use compojure.html.form-helpers
3+
clojure.contrib.test-is))
4+
5+
(defn attribute
6+
"Get an attribute from a tag vector."
7+
[tag key]
8+
((second tag) key))
9+
10+
(deftest test-hidden-field
11+
(testing "passing in only name"
12+
(is (= [:input {:type "hidden", :name "foo", :id "foo"}]
13+
(hidden-field "foo"))))
14+
(testing "passing in name and value"
15+
(is (= [:input {:value "hidden", :type "hidden", :name "foo", :id "foo"}]
16+
(hidden-field "foo" "hidden")))))
17+
18+
(deftest test-text-field
19+
(testing "passing in only name"
20+
(is (= [:input {:type "text", :id "foo", :name "foo"}]
21+
(text-field :foo))))
22+
(testing "passing in name and value"
23+
(is (= [:input {:value :text-field, :type "text", :name "foo", :id "foo"}]
24+
(text-field :foo :text-field)))))
25+
26+
(deftest test-password-field
27+
(is (= [:input {:type "password", :id "foo", :name "foo" :value ""}]
28+
(password-field "foo"))))
29+
30+
(deftest test-check-box
31+
(testing "passing in only name"
32+
(is (= [:input {:type "checkbox" :id "foo" :name "foo" :value "true" :checked nil}]
33+
(check-box :foo))))
34+
(testing "passing in name and checked"
35+
(is (= [:input {:type "checkbox", :name "foo", :id "foo", :value "true", :checked true}]
36+
(check-box :foo true))))
37+
(testing "passing in name, checked, and value"
38+
(is (= [:input {:type "checkbox", :name "foo", :id "foo", :value "checkbox", :checked false}]
39+
(check-box :foo false "checkbox")))))
40+
41+
(deftest test-radio-button
42+
(testing "passing in only name"
43+
(is (= [:input {:type "radio" :id "foo_true" :name "foo" :value "true" :checked nil}]
44+
(radio-button :foo))))
45+
(testing "passing in name and checked"
46+
(is (= [:input {:type "radio", :name "foo", :id "foo_true", :value "true", :checked true}]
47+
(radio-button :foo true))))
48+
(testing "passing in name, checked, and value"
49+
(is (= [:input {:type "radio", :name "foo", :id "foo_radio", :value "radio", :checked false}]
50+
(radio-button :foo false "radio")))))
51+
52+
(deftest test-select-options
53+
(testing "passing in only options"
54+
(is (= '([:option {:value "1"} "a"]
55+
[:option {:value "2"} "b"]
56+
[:option {:value "3"} "c"])
57+
(select-options [["a" "1"] ["b" "2"] ["c" "3"]]))))
58+
(testing "passing in options and selected"
59+
(is (= '([:option {:selected "selected" :value "1"} "a"]
60+
[:option {:value "2"} "b"])
61+
(select-options [["a" "1"] ["b" "2"]] "1")))))
62+
63+
(deftest test-drop-down
64+
(testing "passing in name and options"
65+
(is (= [:select {:name "foo", :id "foo"}
66+
'([:option {:value "1"} "a"]
67+
[:option {:value "2"} "b"])]
68+
(drop-down :foo [["a" "1"] ["b" "2"]]))))
69+
(testing "passing in name, options, and selected"
70+
(is (= [:select {:id "foo" :name "foo"}
71+
'([:option {:value "1"} "a"]
72+
[:option {:value "2" :selected "selected"} "b"]
73+
[:option {:value "3"} "c"])]
74+
(drop-down :foo [["a" "1"] ["b" "2"] ["c" "3"]] "2")))))
75+
76+
(deftest test-text-area
77+
(testing "passing in only name"
78+
(is (= [:textarea {:name "text", :id "text"} nil]
79+
(text-area "text"))))
80+
(testing "passing in name and value"
81+
(is (= [:textarea {:name "text", :id "text"} "textarea"]
82+
(text-area "text" "textarea")))))
83+
84+
(deftest test-label
85+
(is (= [:label {:for "label"} "labeltext"]
86+
(label "label" "labeltext"))))
87+
88+
(deftest test-submit-button
89+
(is (= [:input {:type "submit", :value "submit"}]
90+
(submit-button "submit"))))
91+
92+
(deftest test-reset-button
93+
(is (= [:input {:type "reset", :value "reset"}]
94+
(reset-button "reset"))))
95+
96+
(deftest test-form-to
97+
(let [form (form-to [:post "action"] [])]
98+
(is (= (attribute form :method) "POST"))))
99+
100+
(deftest test-form-to-update
101+
(let [form (form-to [:update "action"] [])]
102+
(is (= (attribute form :method) "POST"))
103+
(let [hidden (nth form 2)]
104+
(is (= (attribute hidden :value) "UPDATE"))
105+
(is (= (attribute hidden :name) "_method"))
106+
(is (= (attribute hidden :type) "hidden")))))
107+
108+
(deftest test-form-to-attrs
109+
(let [form (form-to {:class "class" } [:post "action"] [])]
110+
(is (= (attribute form :class) "class"))))
111+
112+
(deftest form-input-attrs
113+
(let [field (text-field {:style "color: red;"} :foo)]
114+
(is (= (attribute field :style) "color: red;"))))
115+
116+
(deftest test-with-params
117+
(is (= (with-params {:foo "bar"} (text-field :foo))
118+
[:input {:type "text", :id "foo", :name "foo", :value "bar"}])))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(ns test.compojure.html.gen
2-
(:use compojure.html.gen)
3-
(:use clojure.contrib.test-is))
1+
(ns compojure.html.gen-test
2+
(:use compojure.html.gen
3+
clojure.contrib.test-is))
44

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

test/compojure/html/page_helpers.clj

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(ns compojure.html.page-helpers-test
2+
(:use compojure.html.page-helpers
3+
clojure.contrib.test-is))
4+
5+
(deftest test-doctype
6+
(testing "html4"
7+
(is (= (doctype :html4)
8+
(str "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "
9+
"\"http://www.w3.org/TR/html4/strict.dtd\">\n"))))
10+
(testing "xhtml-strict"
11+
(is (= (doctype :xhtml-strict)
12+
(str "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
13+
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"))))
14+
(testing "html5"
15+
(is (= (doctype :html5)
16+
(str "<!DOCTYPE html>"))))
17+
(testing "xhtml-transitional"
18+
(is (= (doctype :xhtml-transitional)
19+
(str "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
20+
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n")))))
21+
22+
(deftest test-xhtml-tag
23+
(is (= (xhtml-tag "test")
24+
[:html {:xmlns "http://www.w3.org/1999/xhtml", "xml:lang" "test", :lang "test"} nil])))
25+
26+
(deftest test-include-js
27+
(testing "one"
28+
(is (= (include-js "foo.js")
29+
'([:script {:type "text/javascript", :src "foo.js"}]))))
30+
(testing "many"
31+
(is (= (include-js "foo.js" "bar.js" "baz.js")
32+
'([:script {:type "text/javascript", :src "foo.js"}]
33+
[:script {:type "text/javascript", :src "bar.js"}]
34+
[:script {:type "text/javascript", :src "baz.js"}])))))
35+
36+
(deftest test-include-css
37+
(testing "one"
38+
(is (= (include-css "foo.css")
39+
'([:link {:type "text/css" :href "foo.css" :rel "stylesheet"}]))))
40+
(testing "many"
41+
(is (= (include-css "foo.css" "bar.css" "baz.css")
42+
'([:link {:type "text/css", :href "foo.css", :rel "stylesheet"}]
43+
[:link {:type "text/css", :href "bar.css", :rel "stylesheet"}]
44+
[:link {:type "text/css", :href "baz.css", :rel "stylesheet"}])))))
45+
46+
(deftest test-javascript-tag
47+
(is (= (javascript-tag "alert('hi');")
48+
[:script {:type "text/javascript"}
49+
(str "//<![CDATA[\n" "alert('hi');" "\n//]]>")])))
50+
51+
(deftest test-link-to
52+
(is (= (link-to "http://compojure.org")
53+
[:a {:href "http://compojure.org"} nil])))
54+
55+
(deftest test-url-encode
56+
(is (= (url-encode "foo&bar*/baz.net")
57+
(str "foo%26bar*%2Fbaz.net"))))
58+
59+
(deftest test-url-params
60+
(is (= (url-params "http://example.com" {:lang "en", :offset 10})
61+
"http://example.com?lang=en&offset=10")))
62+
63+
(deftest test-unordered-list
64+
(is (= (unordered-list ["a" "b"])
65+
[:ul {}
66+
'([:li "a"] [:li "b"])])))
67+
68+
(deftest test-ordered-list
69+
(is (= (ordered-list ["b" "a"])
70+
[:ol {}
71+
'([:li "b"] [:li "a"])])))
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
(ns test.compojure.http.helpers
2-
(:use compojure.http.helpers)
3-
(:use compojure.http.routes)
4-
(:use compojure.control)
5-
(:use clojure.contrib.test-is))
1+
(ns compojure.http.helpers-test
2+
(:use compojure.http.helpers
3+
compojure.http.routes
4+
compojure.control
5+
clojure.contrib.test-is))
66

77
(deftest test-set-cookie
88
(is (= (set-cookie :foo "bar")
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
(ns test.compojure.http.middleware
2-
(:use compojure.http.middleware)
3-
(:use compojure.http.routes)
4-
(:use clojure.contrib.test-is))
1+
(ns compojure.http.middleware-test
2+
(:use compojure.http.middleware
3+
compojure.http.routes
4+
clojure.contrib.test-is))
55

66
(deftest test-header-option
77
(is (= (header-option [:name "value"])

0 commit comments

Comments
 (0)