annotate src/clojure/contrib/test_contrib/test_strint.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
rev   line source
rlm@10 1 ; Copyright (c) Stuart Halloway, 2010-. All rights reserved.
rlm@10 2
rlm@10 3 ; The use and distribution terms for this software are covered by the
rlm@10 4 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 5 ; which can be found in the file epl-v10.html at the root of this
rlm@10 6 ; distribution.
rlm@10 7 ; By using this software in any fashion, you are agreeing to be bound by
rlm@10 8 ; the terms of this license.
rlm@10 9 ; You must not remove this notice, or any other, from this software.
rlm@10 10
rlm@10 11 (ns clojure.contrib.test-strint
rlm@10 12 (:use clojure.test)
rlm@10 13 (:use [clojure.contrib strint with-ns]))
rlm@10 14
rlm@10 15 (def silent-read (with-ns 'clojure.contrib.strint silent-read))
rlm@10 16 (def interpolate (with-ns 'clojure.contrib.strint interpolate))
rlm@10 17
rlm@10 18 (deftest test-silent-read
rlm@10 19 (testing "reading a valid form returns [read form, rest of string]"
rlm@10 20 (is (= [[1] "[2]"] (silent-read "[1][2]"))))
rlm@10 21 (testing "reading an invalid form returns nil"
rlm@10 22 (is (= nil (silent-read "[")))))
rlm@10 23
rlm@10 24 (deftest test-interpolate
rlm@10 25 (testing "a plain old string"
rlm@10 26 (is (= ["a plain old string"] (interpolate "a plain old string"))))
rlm@10 27 (testing "some value replacement forms"
rlm@10 28 (is (= '["" foo " and " bar ""] (interpolate "~{foo} and ~{bar}"))))
rlm@10 29 (testing "some fn-calling forms"
rlm@10 30 (is (= '["" (+ 1 2) " and " (vector 3) ""] (interpolate "~(+ 1 2) and ~(vector 3)")))))
rlm@10 31
rlm@10 32 (deftest test-<<
rlm@10 33 (testing "docstring examples"
rlm@10 34 (let [v 30.5
rlm@10 35 m {:a [1 2 3]}]
rlm@10 36 (is (= "This trial required 30.5ml of solution."
rlm@10 37 (<< "This trial required ~{v}ml of solution.")))
rlm@10 38 (is (= "There are 30 days in November."
rlm@10 39 (<< "There are ~(int v) days in November.")))
rlm@10 40 (is (= "The total for your order is $6."
rlm@10 41 (<< "The total for your order is $~(->> m :a (apply +))."))))))