view src/clojure/test_clojure/printer.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 source
1 ; Copyright (c) Rich Hickey. All rights reserved.
2 ; The use and distribution terms for this software are covered by the
3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 ; which can be found in the file epl-v10.html at the root of this distribution.
5 ; By using this software in any fashion, you are agreeing to be bound by
6 ; the terms of this license.
7 ; You must not remove this notice, or any other, from this software.
9 ; Author: Stephen C. Gilardi
11 ;; clojure.test-clojure.printer
12 ;;
13 ;; scgilardi (gmail)
14 ;; Created 29 October 2008
16 (ns clojure.test-clojure.printer
17 (:use clojure.test))
19 (deftest print-length-empty-seq
20 (let [coll () val "()"]
21 (is (= val (binding [*print-length* 0] (print-str coll))))
22 (is (= val (binding [*print-length* 1] (print-str coll))))))
24 (deftest print-length-seq
25 (let [coll (range 5)
26 length-val '((0 "(...)")
27 (1 "(0 ...)")
28 (2 "(0 1 ...)")
29 (3 "(0 1 2 ...)")
30 (4 "(0 1 2 3 ...)")
31 (5 "(0 1 2 3 4)"))]
32 (doseq [[length val] length-val]
33 (binding [*print-length* length]
34 (is (= val (print-str coll)))))))
36 (deftest print-length-empty-vec
37 (let [coll [] val "[]"]
38 (is (= val (binding [*print-length* 0] (print-str coll))))
39 (is (= val (binding [*print-length* 1] (print-str coll))))))
41 (deftest print-length-vec
42 (let [coll [0 1 2 3 4]
43 length-val '((0 "[...]")
44 (1 "[0 ...]")
45 (2 "[0 1 ...]")
46 (3 "[0 1 2 ...]")
47 (4 "[0 1 2 3 ...]")
48 (5 "[0 1 2 3 4]"))]
49 (doseq [[length val] length-val]
50 (binding [*print-length* length]
51 (is (= val (print-str coll)))))))
53 (deftest print-level-seq
54 (let [coll '(0 (1 (2 (3 (4)))))
55 level-val '((0 "#")
56 (1 "(0 #)")
57 (2 "(0 (1 #))")
58 (3 "(0 (1 (2 #)))")
59 (4 "(0 (1 (2 (3 #))))")
60 (5 "(0 (1 (2 (3 (4)))))"))]
61 (doseq [[level val] level-val]
62 (binding [*print-level* level]
63 (is (= val (print-str coll)))))))
65 (deftest print-level-length-coll
66 (let [coll '(if (member x y) (+ (first x) 3) (foo (a b c d "Baz")))
67 level-length-val
68 '((0 1 "#")
69 (1 1 "(if ...)")
70 (1 2 "(if # ...)")
71 (1 3 "(if # # ...)")
72 (1 4 "(if # # #)")
73 (2 1 "(if ...)")
74 (2 2 "(if (member x ...) ...)")
75 (2 3 "(if (member x y) (+ # 3) ...)")
76 (3 2 "(if (member x ...) ...)")
77 (3 3 "(if (member x y) (+ (first x) 3) ...)")
78 (3 4 "(if (member x y) (+ (first x) 3) (foo (a b c d ...)))")
79 (3 5 "(if (member x y) (+ (first x) 3) (foo (a b c d Baz)))"))]
80 (doseq [[level length val] level-length-val]
81 (binding [*print-level* level
82 *print-length* length]
83 (is (= val (print-str coll)))))))