diff src/clojure/contrib/test_contrib/test_core.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/contrib/test_contrib/test_core.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,42 @@
     1.4 +;   Copyright (c) Laurent Petit, March 2009. All rights reserved.
     1.5 +
     1.6 +;   The use and distribution terms for this software are covered by the
     1.7 +;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
     1.8 +;   which can be found in the file epl-v10.html at the root of this 
     1.9 +;   distribution.
    1.10 +;   By using this software in any fashion, you are agreeing to be bound by
    1.11 +;   the terms of this license.
    1.12 +;   You must not remove this notice, or any other, from this software.
    1.13 +
    1.14 +;; test namespace for clojure.contrib.core
    1.15 +
    1.16 +;; note to other contrib members: feel free to add to this lib
    1.17 +
    1.18 +(ns clojure.contrib.test-core
    1.19 +  (:use clojure.test)
    1.20 +  (:use clojure.contrib.core))
    1.21 +
    1.22 +(deftest test-classic-versions
    1.23 +  (testing "Classic -> throws NPE if passed nil"
    1.24 +    (is (thrown? NullPointerException (-> nil .toString)))
    1.25 +    (is (thrown? NullPointerException (-> "foo" seq next next next .toString))))
    1.26 +  (testing "Classic .. throws NPE if one of the intermediate threaded values is nil"
    1.27 +    (is (thrown? NullPointerException (.. nil toString)))
    1.28 +    (is (thrown? NullPointerException (.. [nil] (get 0) toString)))))
    1.29 +
    1.30 +(deftest test-new-versions
    1.31 +  (testing "Version -?>> falls out on nil"
    1.32 +    (is (nil? (-?>> nil .toString)))
    1.33 +    (is (nil? (-?>> [] seq (map inc))))
    1.34 +    (is (= [] (->> [] seq (map inc)))))
    1.35 +  (testing "Version -?>> completes for non-nil"
    1.36 +    (is (= [3 4] (-?>> [1 2] (map inc) (map inc)))))
    1.37 +  (testing "Version -?> falls out on nil"
    1.38 +    (is (nil? (-?> nil .toString)))
    1.39 +    (is (nil? (-?> "foo" seq next next next .toString))))
    1.40 +  (testing "Version -?> completes for non-nil"
    1.41 +    (is (= [\O \O] (-?> "foo" .toUpperCase rest))))
    1.42 +  (testing "Version .?. returns nil if one of the intermediate threaded values is nil"
    1.43 +    (is (nil? (.?. nil toString)))
    1.44 +    (is (nil? (.?. [nil] (get 0) toString)))))
    1.45 +