diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/test_clojure/printer.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,83 @@
     1.4 +;   Copyright (c) Rich Hickey. All rights reserved.
     1.5 +;   The use and distribution terms for this software are covered by the
     1.6 +;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
     1.7 +;   which can be found in the file epl-v10.html at the root of this distribution.
     1.8 +;   By using this software in any fashion, you are agreeing to be bound by
     1.9 +;   the terms of this license.
    1.10 +;   You must not remove this notice, or any other, from this software.
    1.11 +
    1.12 +; Author: Stephen C. Gilardi
    1.13 +
    1.14 +;;  clojure.test-clojure.printer
    1.15 +;;
    1.16 +;;  scgilardi (gmail)
    1.17 +;;  Created 29 October 2008
    1.18 +
    1.19 +(ns clojure.test-clojure.printer
    1.20 +  (:use clojure.test))
    1.21 +
    1.22 +(deftest print-length-empty-seq
    1.23 +  (let [coll () val "()"]
    1.24 +    (is (= val (binding [*print-length* 0] (print-str coll))))
    1.25 +    (is (= val (binding [*print-length* 1] (print-str coll))))))
    1.26 +
    1.27 +(deftest print-length-seq
    1.28 +  (let [coll (range 5)
    1.29 +        length-val '((0 "(...)")
    1.30 +                     (1 "(0 ...)")
    1.31 +                     (2 "(0 1 ...)")
    1.32 +                     (3 "(0 1 2 ...)")
    1.33 +                     (4 "(0 1 2 3 ...)")
    1.34 +                     (5 "(0 1 2 3 4)"))]
    1.35 +    (doseq [[length val] length-val]
    1.36 +      (binding [*print-length* length]
    1.37 +        (is (= val (print-str coll)))))))
    1.38 +
    1.39 +(deftest print-length-empty-vec
    1.40 +  (let [coll [] val "[]"]
    1.41 +    (is (= val (binding [*print-length* 0] (print-str coll))))
    1.42 +    (is (= val (binding [*print-length* 1] (print-str coll))))))
    1.43 +
    1.44 +(deftest print-length-vec
    1.45 +  (let [coll [0 1 2 3 4]
    1.46 +        length-val '((0 "[...]")
    1.47 +                     (1 "[0 ...]")
    1.48 +                     (2 "[0 1 ...]")
    1.49 +                     (3 "[0 1 2 ...]")
    1.50 +                     (4 "[0 1 2 3 ...]")
    1.51 +                     (5 "[0 1 2 3 4]"))]
    1.52 +    (doseq [[length val] length-val]
    1.53 +      (binding [*print-length* length]
    1.54 +        (is (= val (print-str coll)))))))
    1.55 +
    1.56 +(deftest print-level-seq
    1.57 +  (let [coll '(0 (1 (2 (3 (4)))))
    1.58 +        level-val '((0 "#")
    1.59 +                    (1 "(0 #)")
    1.60 +                    (2 "(0 (1 #))")
    1.61 +                    (3 "(0 (1 (2 #)))")
    1.62 +                    (4 "(0 (1 (2 (3 #))))")
    1.63 +                    (5 "(0 (1 (2 (3 (4)))))"))]
    1.64 +    (doseq [[level val] level-val]
    1.65 +      (binding [*print-level* level]
    1.66 +        (is (= val (print-str coll)))))))
    1.67 +
    1.68 +(deftest print-level-length-coll
    1.69 +  (let [coll '(if (member x y) (+ (first x) 3) (foo (a b c d "Baz")))
    1.70 +        level-length-val
    1.71 +        '((0 1 "#")
    1.72 +          (1 1 "(if ...)")
    1.73 +          (1 2 "(if # ...)")
    1.74 +          (1 3 "(if # # ...)")
    1.75 +          (1 4 "(if # # #)")
    1.76 +          (2 1 "(if ...)")
    1.77 +          (2 2 "(if (member x ...) ...)")
    1.78 +          (2 3 "(if (member x y) (+ # 3) ...)")
    1.79 +          (3 2 "(if (member x ...) ...)")
    1.80 +          (3 3 "(if (member x y) (+ (first x) 3) ...)")
    1.81 +          (3 4 "(if (member x y) (+ (first x) 3) (foo (a b c d ...)))")
    1.82 +          (3 5 "(if (member x y) (+ (first x) 3) (foo (a b c d Baz)))"))]
    1.83 +    (doseq [[level length val] level-length-val]
    1.84 +      (binding [*print-level* level
    1.85 +                *print-length* length]
    1.86 +        (is (= val (print-str coll)))))))