rlm@10
|
1 ; Copyright (c) Laurent Petit, March 2009. All rights reserved.
|
rlm@10
|
2
|
rlm@10
|
3 ; The use and distribution terms for this software are covered by the
|
rlm@10
|
4 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
rlm@10
|
5 ; which can be found in the file epl-v10.html at the root of this
|
rlm@10
|
6 ; distribution.
|
rlm@10
|
7 ; By using this software in any fashion, you are agreeing to be bound by
|
rlm@10
|
8 ; the terms of this license.
|
rlm@10
|
9 ; You must not remove this notice, or any other, from this software.
|
rlm@10
|
10
|
rlm@10
|
11 ;; test namespace for clojure.contrib.core
|
rlm@10
|
12
|
rlm@10
|
13 ;; note to other contrib members: feel free to add to this lib
|
rlm@10
|
14
|
rlm@10
|
15 (ns clojure.contrib.test-core
|
rlm@10
|
16 (:use clojure.test)
|
rlm@10
|
17 (:use clojure.contrib.core))
|
rlm@10
|
18
|
rlm@10
|
19 (deftest test-classic-versions
|
rlm@10
|
20 (testing "Classic -> throws NPE if passed nil"
|
rlm@10
|
21 (is (thrown? NullPointerException (-> nil .toString)))
|
rlm@10
|
22 (is (thrown? NullPointerException (-> "foo" seq next next next .toString))))
|
rlm@10
|
23 (testing "Classic .. throws NPE if one of the intermediate threaded values is nil"
|
rlm@10
|
24 (is (thrown? NullPointerException (.. nil toString)))
|
rlm@10
|
25 (is (thrown? NullPointerException (.. [nil] (get 0) toString)))))
|
rlm@10
|
26
|
rlm@10
|
27 (deftest test-new-versions
|
rlm@10
|
28 (testing "Version -?>> falls out on nil"
|
rlm@10
|
29 (is (nil? (-?>> nil .toString)))
|
rlm@10
|
30 (is (nil? (-?>> [] seq (map inc))))
|
rlm@10
|
31 (is (= [] (->> [] seq (map inc)))))
|
rlm@10
|
32 (testing "Version -?>> completes for non-nil"
|
rlm@10
|
33 (is (= [3 4] (-?>> [1 2] (map inc) (map inc)))))
|
rlm@10
|
34 (testing "Version -?> falls out on nil"
|
rlm@10
|
35 (is (nil? (-?> nil .toString)))
|
rlm@10
|
36 (is (nil? (-?> "foo" seq next next next .toString))))
|
rlm@10
|
37 (testing "Version -?> completes for non-nil"
|
rlm@10
|
38 (is (= [\O \O] (-?> "foo" .toUpperCase rest))))
|
rlm@10
|
39 (testing "Version .?. returns nil if one of the intermediate threaded values is nil"
|
rlm@10
|
40 (is (nil? (.?. nil toString)))
|
rlm@10
|
41 (is (nil? (.?. [nil] (get 0) toString)))))
|
rlm@10
|
42
|