rlm@10: ; Copyright (c) Rich Hickey. All rights reserved. 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 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: ; Author: Frantisek Sodomka rlm@10: rlm@10: rlm@10: (ns clojure.test-clojure.other-functions rlm@10: (:use clojure.test)) rlm@10: rlm@10: ; http://clojure.org/other_functions rlm@10: rlm@10: ; [= not= (tests in data_structures.clj and elsewhere)] rlm@10: rlm@10: rlm@10: (deftest test-identity rlm@10: ; exactly 1 argument needed rlm@10: (is (thrown? IllegalArgumentException (identity))) rlm@10: (is (thrown? IllegalArgumentException (identity 1 2))) rlm@10: rlm@10: (are [x] (= (identity x) x) rlm@10: nil rlm@10: false true rlm@10: 0 42 rlm@10: 0.0 3.14 rlm@10: 2/3 rlm@10: 0M 1M rlm@10: \c rlm@10: "" "abc" rlm@10: 'sym rlm@10: :kw rlm@10: () '(1 2) rlm@10: [] [1 2] rlm@10: {} {:a 1 :b 2} rlm@10: #{} #{1 2} ) rlm@10: rlm@10: ; evaluation rlm@10: (are [x y] (= (identity x) y) rlm@10: (+ 1 2) 3 rlm@10: (> 5 0) true )) rlm@10: rlm@10: rlm@10: (deftest test-name rlm@10: (are [x y] (= x (name y)) rlm@10: "foo" :foo rlm@10: "bar" 'bar rlm@10: "quux" "quux")) rlm@10: rlm@10: (deftest test-fnil rlm@10: (let [f1 (fnil vector :a) rlm@10: f2 (fnil vector :a :b) rlm@10: f3 (fnil vector :a :b :c)] rlm@10: (are [result input] (= result [(apply f1 input) (apply f2 input) (apply f3 input)]) rlm@10: [[1 2 3 4] [1 2 3 4] [1 2 3 4]] [1 2 3 4] rlm@10: [[:a 2 3 4] [:a 2 3 4] [:a 2 3 4]] [nil 2 3 4] rlm@10: [[:a nil 3 4] [:a :b 3 4] [:a :b 3 4]] [nil nil 3 4] rlm@10: [[:a nil nil 4] [:a :b nil 4] [:a :b :c 4]] [nil nil nil 4] rlm@10: [[:a nil nil nil] [:a :b nil nil] [:a :b :c nil]] [nil nil nil nil])) rlm@10: (are [x y] (= x y) rlm@10: ((fnil + 0) nil 42) 42 rlm@10: ((fnil conj []) nil 42) [42] rlm@10: (reduce #(update-in %1 [%2] (fnil inc 0)) {} rlm@10: ["fun" "counting" "words" "fun"]) rlm@10: {"words" 1, "counting" 1, "fun" 2} rlm@10: (reduce #(update-in %1 [(first %2)] (fnil conj []) (second %2)) {} rlm@10: [[:a 1] [:a 2] [:b 3]]) rlm@10: {:b [3], :a [1 2]})) rlm@10: rlm@10: ; time assert comment doc rlm@10: rlm@10: ; partial rlm@10: ; comp rlm@10: ; complement rlm@10: ; constantly rlm@10: rlm@10: ; Printing rlm@10: ; pr prn print println newline rlm@10: ; pr-str prn-str print-str println-str [with-out-str (vars.clj)] rlm@10: rlm@10: ; Regex Support rlm@10: ; re-matcher re-find re-matches re-groups re-seq rlm@10: