Commits

Anonymous committed fac5604

add unit tests for comma-sep-str and echo

  • Participants
  • Parent commits 483ce41

Comments (0)

Files changed (2)

File src/main/clj/org/bituf/clj_miscutil.clj

     (pp/pprint whatever w)))
 
 
+(defn comma-sep-str
+  "Return comma separated string for a given collection of values."
+  [coll]
+  (apply str (interpose ", " coll)))
+
+
+(defn echo
+  "Print argument using 'pprint' and then return it."
+  [x]
+  (pp/pprint x)
+  x)
+
+
 ;; ===== Numbers detection =====
 
 
 ;; ===== Assertion helpers =====
 
 
-(defn comma-sep-str
-  "Return comma separated string for a given collection of values."
-  [coll]
-  (apply str (interpose ", " coll)))
-
-
 (defmacro verify-arg
   "Like assert, except for the following differences:
   1. does not check for *assert* flag
     true))
 
 
-(defn echo
-  "Print argument using 'pprint' and then return it."
-  [x]
-  (pp/pprint x)
-  x)
-
-
 ;; ===== Type annotation =====
 
 (defn implied-types

File src/test/clj/org/bituf/test_clj_miscutil.clj

       (is (= ltx "java.lang.ArithmeticException: Divide by zero"))))
   (testing "pprint-str"
     (let [x (take 12 (iterate inc 0))]
-      (is (= (with-out-str (clojure.pprint/pprint x)) (pprint-str x))))))
+      (is (= (with-out-str (clojure.pprint/pprint x)) (pprint-str x)))))
+  (testing "comma-sep-str"
+    (is (= "1, 2, 3" (comma-sep-str [1 2 3]))))
+  (testing "echo"
+    (let [t "hello"
+          r (echo t)
+          s (with-out-str (echo t))]
+      (is (= r t))
+      (is (= s (format "\"%s\"\n" t))))))
 
 
 (deftest test-var-metadata