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