From fa24c1428e12b51fa6b4b78e6179ef7b71bbff78 Mon Sep 17 00:00:00 2001 From: scgilardi Date: Thu, 30 Oct 2008 03:32:55 +0000 Subject: add printer tests, restructure test-clojure --- src/clojure/contrib/test_clojure/printer.clj | 76 ++++++++++++ src/clojure/contrib/test_clojure/reader.clj | 128 ++++++++++++++++++++ src/clojure/contrib/test_clojure/reader/reader.clj | 133 --------------------- src/clojure/contrib/test_clojure/test_clojure.clj | 7 +- 4 files changed, 208 insertions(+), 136 deletions(-) create mode 100644 src/clojure/contrib/test_clojure/printer.clj create mode 100644 src/clojure/contrib/test_clojure/reader.clj delete mode 100644 src/clojure/contrib/test_clojure/reader/reader.clj (limited to 'src/clojure/contrib') diff --git a/src/clojure/contrib/test_clojure/printer.clj b/src/clojure/contrib/test_clojure/printer.clj new file mode 100644 index 00000000..d5779ec1 --- /dev/null +++ b/src/clojure/contrib/test_clojure/printer.clj @@ -0,0 +1,76 @@ +;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and +;; distribution terms for this software are covered by the Common Public +;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found +;; in the file CPL.TXT at the root of this distribution. By using this +;; software in any fashion, you are agreeing to be bound by the terms of +;; this license. You must not remove this notice, or any other, from this +;; software. +;; +;; scgilardi (gmail) +;; Created 29 October 2008 + +(deftest t-print-length-empty-seq + (let [coll () val "()"] + (is (= val (binding [*print-length* 0] (print-str coll)))) + (is (= val (binding [*print-length* 1] (print-str coll)))))) + +(deftest t-print-length-seq + (let [coll (range 5) + length-val '((0 "(...)") + (1 "(0 ...)") + (2 "(0 1 ...)") + (3 "(0 1 2 ...)") + (4 "(0 1 2 3 ...)") + (5 "(0 1 2 3 4)"))] + (doseq [length val] length-val + (binding [*print-length* length] + (is (= val (print-str coll))))))) + +(deftest t-print-length-empty-vec + (let [coll [] val "[]"] + (is (= val (binding [*print-length* 0] (print-str coll)))) + (is (= val (binding [*print-length* 1] (print-str coll)))))) + +(deftest t-print-length-vec + (let [coll [0 1 2 3 4] + length-val '((0 "[...]") + (1 "[0 ...]") + (2 "[0 1 ...]") + (3 "[0 1 2 ...]") + (4 "[0 1 2 3 ...]") + (5 "[0 1 2 3 4]"))] + (doseq [length val] length-val + (binding [*print-length* length] + (is (= val (print-str coll))))))) + +(deftest t-print-level-seq + (let [coll '(0 (1 (2 (3 (4))))) + level-val '((0 "#") + (1 "(0 #)") + (2 "(0 (1 #))") + (3 "(0 (1 (2 #)))") + (4 "(0 (1 (2 (3 #))))") + (5 "(0 (1 (2 (3 (4)))))"))] + (doseq [level val] level-val + (binding [*print-level* level] + (is (= val (print-str coll))))))) + +(deftest t-print-level-length-coll + (let [coll '(if (member x y) (+ (first x) 3) (foo (a b c d "Baz"))) + level-length-val + '((0 1 "#") + (1 1 "(if ...)") + (1 2 "(if # ...)") + (1 3 "(if # # ...)") + (1 4 "(if # # #)") + (2 1 "(if ...)") + (2 2 "(if (member x ...) ...)") + (2 3 "(if (member x y) (+ # 3) ...)") + (3 2 "(if (member x ...) ...)") + (3 3 "(if (member x y) (+ (first x) 3) ...)") + (3 4 "(if (member x y) (+ (first x) 3) (foo (a b c d ...)))") + (3 5 "(if (member x y) (+ (first x) 3) (foo (a b c d Baz)))"))] + (doseq [level length val] level-length-val + (binding [*print-level* level + *print-length* length] + (is (= val (print-str coll))))))) diff --git a/src/clojure/contrib/test_clojure/reader.clj b/src/clojure/contrib/test_clojure/reader.clj new file mode 100644 index 00000000..7517b588 --- /dev/null +++ b/src/clojure/contrib/test_clojure/reader.clj @@ -0,0 +1,128 @@ +;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and +;; distribution terms for this software are covered by the Common Public +;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found +;; in the file CPL.TXT at the root of this distribution. By using this +;; software in any fashion, you are agreeing to be bound by the terms of +;; this license. You must not remove this notice, or any other, from this +;; software. +;; +;; Tests for the Clojure functions documented at the URL: +;; +;; http://clojure.org/Reader +;; +;; scgilardi (gmail) +;; Created 22 October 2008 + +;; Symbols + +(deftest t-Symbols + (is (= 'abc (symbol "abc"))) + (is (= '*+!-_? (symbol "*+!-_?"))) + (is (= 'abc:def:ghi (symbol "abc:def:ghi"))) + (is (= 'abc/def (symbol "abc" "def"))) + (is (= 'abc.def/ghi (symbol "abc.def" "ghi"))) + (is (= 'abc/def.ghi (symbol "abc" "def.ghi"))) + (is (= 'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno"))) + (is (instance? clojure.lang.Symbol 'alphabet)) + ) + +;; Literals + +;; Strings + +(deftest t-Strings + (is (= "abcde" (str \a \b \c \d \e))) + (is (= "abc + def" (str \a \b \c \newline \space \space \d \e \f))) + ) + +;; Numbers + +(deftest t-Numbers) + +;; Characters + +(deftest t-Characters) + +;; nil + +(deftest t-nil) + +;; Booleans + +(deftest t-Booleans) + +;; Keywords + +(deftest t-Keywords) + +;; Lists + +(deftest t-Lists) + +;; Vectors + +(deftest t-Vectors) + +;; Maps + +(deftest t-Maps) + +;; Sets + +(deftest t-Sets) + +;; Macro characters + +;; Quote (') + +(deftest t-Quote) + +;; Character (\) + +(deftest t-Character) + +;; Comment (;) + +(deftest t-Comment) + +;; Meta (^) + +(deftest t-Meta) + +;; Deref (@) + +(deftest t-Deref) + +;; Dispatch (#) + +;; #{} - see Sets above + +;; Regex patterns (#"pattern") + +(deftest t-Regex) + +;; Metadata (#^) + +(deftest t-Metadata) + +;; Var-quote (#') + +(deftest t-Var-quote) + +;; Anonymous function literal (#()) + +(deftest t-Anonymouns-function-literal) + +;; Syntax-quote (`, note, the "backquote" character), Unquote (~) and +;; Unquote-splicing (~@) + +(deftest t-Syntax-quote) + +;; (read) +;; (read stream) +;; (read stream eof-is-error) +;; (read stream eof-is-error eof-value) +;; (read stream eof-is-error eof-value is-recursive) + +(deftest t-read) diff --git a/src/clojure/contrib/test_clojure/reader/reader.clj b/src/clojure/contrib/test_clojure/reader/reader.clj deleted file mode 100644 index 4f436e93..00000000 --- a/src/clojure/contrib/test_clojure/reader/reader.clj +++ /dev/null @@ -1,133 +0,0 @@ -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and -;; distribution terms for this software are covered by the Common Public -;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found -;; in the file CPL.TXT at the root of this distribution. By using this -;; software in any fashion, you are agreeing to be bound by the terms of -;; this license. You must not remove this notice, or any other, from this -;; software. -;; -;; clojure.contrib.test-clojure.Reader.clj -;; -;; Tests for the Clojure functions documented at the URL: -;; -;; http://clojure.org/Reader -;; -;; scgilardi (gmail) -;; Created 22 October 2008 - -(ns clojure.contrib.test-clojure.reader - (:use clojure.contrib.test-is)) - -;; Symbols - -(deftest t-Symbols - (is (= 'abc (symbol "abc"))) - (is (= '*+!-_? (symbol "*+!-_?"))) - (is (= 'abc:def:ghi (symbol "abc:def:ghi"))) - (is (= 'abc/def (symbol "abc" "def"))) - (is (= 'abc.def/ghi (symbol "abc.def" "ghi"))) - (is (= 'abc/def.ghi (symbol "abc" "def.ghi"))) - (is (= 'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno"))) - (is (instance? clojure.lang.Symbol 'alphabet)) - ) - -;; Literals - -;; Strings - -(deftest t-Strings - (is (= "abcde" (str \a \b \c \d \e))) - (is (= "abc - def" (str \a \b \c \newline \space \space \d \e \f))) - ) - -;; Numbers - -(deftest t-Numbers) - -;; Characters - -(deftest t-Characters) - -;; nil - -(deftest t-nil) - -;; Booleans - -(deftest t-Booleans) - -;; Keywords - -(deftest t-Keywords) - -;; Lists - -(deftest t-Lists) - -;; Vectors - -(deftest t-Vectors) - -;; Maps - -(deftest t-Maps) - -;; Sets - -(deftest t-Sets) - -;; Macro characters - -;; Quote (') - -(deftest t-Quote) - -;; Character (\) - -(deftest t-Character) - -;; Comment (;) - -(deftest t-Comment) - -;; Meta (^) - -(deftest t-Meta) - -;; Deref (@) - -(deftest t-Deref) - -;; Dispatch (#) - -;; #{} - see Sets above - -;; Regex patterns (#"pattern") - -(deftest t-Regex) - -;; Metadata (#^) - -(deftest t-Metadata) - -;; Var-quote (#') - -(deftest t-Var-quote) - -;; Anonymous function literal (#()) - -(deftest t-Anonymouns-function-literal) - -;; Syntax-quote (`, note, the "backquote" character), Unquote (~) and -;; Unquote-splicing (~@) - -(deftest t-Syntax-quote) - -;; (read) -;; (read stream) -;; (read stream eof-is-error) -;; (read stream eof-is-error eof-value) -;; (read stream eof-is-error eof-value is-recursive) - -(deftest t-read) diff --git a/src/clojure/contrib/test_clojure/test_clojure.clj b/src/clojure/contrib/test_clojure/test_clojure.clj index e6adc194..b839b142 100644 --- a/src/clojure/contrib/test_clojure/test_clojure.clj +++ b/src/clojure/contrib/test_clojure/test_clojure.clj @@ -14,8 +14,9 @@ ;; Created 22 October 2008 (ns clojure.contrib.test-clojure - (:use (clojure.contrib test-is) - (clojure.contrib.test-clojure reader))) + (:use clojure.contrib.test-is) + (:load "reader.clj" "printer.clj")) (binding [*test-out* (java.io.PrintWriter. *out*)] - (run-tests 'clojure.contrib.test-clojure.reader)) + (run-tests) + (println)) -- cgit v1.2.3-18-g5258