aboutsummaryrefslogtreecommitdiff
path: root/modules/strint/src
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2010-08-10 21:40:47 -0400
committerStuart Sierra <mail@stuartsierra.com>2010-08-10 21:40:47 -0400
commit38743f83bdd60d6687dabcea3864b04bbd554a6c (patch)
tree44b31d4900c2d5720679abe911694d64fc516d0a /modules/strint/src
parenta6a92b9b3d2bfd9a56e1e5e9cfba706d1aeeaae5 (diff)
Add test sources to their respective modules
Diffstat (limited to 'modules/strint/src')
-rw-r--r--modules/strint/src/test/clojure/clojure/contrib/test_strint.clj41
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/strint/src/test/clojure/clojure/contrib/test_strint.clj b/modules/strint/src/test/clojure/clojure/contrib/test_strint.clj
new file mode 100644
index 00000000..83ff1f86
--- /dev/null
+++ b/modules/strint/src/test/clojure/clojure/contrib/test_strint.clj
@@ -0,0 +1,41 @@
+; Copyright (c) Stuart Halloway, 2010-. All rights reserved.
+
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html 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.
+
+(ns clojure.contrib.test-strint
+ (:use clojure.test)
+ (:use [clojure.contrib strint with-ns]))
+
+(def silent-read (with-ns 'clojure.contrib.strint silent-read))
+(def interpolate (with-ns 'clojure.contrib.strint interpolate))
+
+(deftest test-silent-read
+ (testing "reading a valid form returns [read form, rest of string]"
+ (is (= [[1] "[2]"] (silent-read "[1][2]"))))
+ (testing "reading an invalid form returns nil"
+ (is (= nil (silent-read "[")))))
+
+(deftest test-interpolate
+ (testing "a plain old string"
+ (is (= ["a plain old string"] (interpolate "a plain old string"))))
+ (testing "some value replacement forms"
+ (is (= '["" foo " and " bar ""] (interpolate "~{foo} and ~{bar}"))))
+ (testing "some fn-calling forms"
+ (is (= '["" (+ 1 2) " and " (vector 3) ""] (interpolate "~(+ 1 2) and ~(vector 3)")))))
+
+(deftest test-<<
+ (testing "docstring examples"
+ (let [v 30.5
+ m {:a [1 2 3]}]
+ (is (= "This trial required 30.5ml of solution."
+ (<< "This trial required ~{v}ml of solution.")))
+ (is (= "There are 30 days in November."
+ (<< "There are ~(int v) days in November.")))
+ (is (= "The total for your order is $6."
+ (<< "The total for your order is $~(->> m :a (apply +))."))))))