rlm@10: ; Copyright (c) Laurent Petit, March 2009. All rights reserved. rlm@10: rlm@10: ; The use and distribution terms for this software are covered by the rlm@10: ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) rlm@10: ; which can be found in the file epl-v10.html at the root of this rlm@10: ; distribution. rlm@10: ; By using this software in any fashion, you are agreeing to be bound by rlm@10: ; the terms of this license. rlm@10: ; You must not remove this notice, or any other, from this software. rlm@10: rlm@10: ;; test namespace for clojure.contrib.core rlm@10: rlm@10: ;; note to other contrib members: feel free to add to this lib rlm@10: rlm@10: (ns clojure.contrib.test-core rlm@10: (:use clojure.test) rlm@10: (:use clojure.contrib.core)) rlm@10: rlm@10: (deftest test-classic-versions rlm@10: (testing "Classic -> throws NPE if passed nil" rlm@10: (is (thrown? NullPointerException (-> nil .toString))) rlm@10: (is (thrown? NullPointerException (-> "foo" seq next next next .toString)))) rlm@10: (testing "Classic .. throws NPE if one of the intermediate threaded values is nil" rlm@10: (is (thrown? NullPointerException (.. nil toString))) rlm@10: (is (thrown? NullPointerException (.. [nil] (get 0) toString))))) rlm@10: rlm@10: (deftest test-new-versions rlm@10: (testing "Version -?>> falls out on nil" rlm@10: (is (nil? (-?>> nil .toString))) rlm@10: (is (nil? (-?>> [] seq (map inc)))) rlm@10: (is (= [] (->> [] seq (map inc))))) rlm@10: (testing "Version -?>> completes for non-nil" rlm@10: (is (= [3 4] (-?>> [1 2] (map inc) (map inc))))) rlm@10: (testing "Version -?> falls out on nil" rlm@10: (is (nil? (-?> nil .toString))) rlm@10: (is (nil? (-?> "foo" seq next next next .toString)))) rlm@10: (testing "Version -?> completes for non-nil" rlm@10: (is (= [\O \O] (-?> "foo" .toUpperCase rest)))) rlm@10: (testing "Version .?. returns nil if one of the intermediate threaded values is nil" rlm@10: (is (nil? (.?. nil toString))) rlm@10: (is (nil? (.?. [nil] (get 0) toString))))) rlm@10: