Mercurial > lasercutter
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/test_contrib/test_strint.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,41 @@ 1.4 +; Copyright (c) Stuart Halloway, 2010-. All rights reserved. 1.5 + 1.6 +; The use and distribution terms for this software are covered by the 1.7 +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 1.8 +; which can be found in the file epl-v10.html at the root of this 1.9 +; distribution. 1.10 +; By using this software in any fashion, you are agreeing to be bound by 1.11 +; the terms of this license. 1.12 +; You must not remove this notice, or any other, from this software. 1.13 + 1.14 +(ns clojure.contrib.test-strint 1.15 + (:use clojure.test) 1.16 + (:use [clojure.contrib strint with-ns])) 1.17 + 1.18 +(def silent-read (with-ns 'clojure.contrib.strint silent-read)) 1.19 +(def interpolate (with-ns 'clojure.contrib.strint interpolate)) 1.20 + 1.21 +(deftest test-silent-read 1.22 + (testing "reading a valid form returns [read form, rest of string]" 1.23 + (is (= [[1] "[2]"] (silent-read "[1][2]")))) 1.24 + (testing "reading an invalid form returns nil" 1.25 + (is (= nil (silent-read "["))))) 1.26 + 1.27 +(deftest test-interpolate 1.28 + (testing "a plain old string" 1.29 + (is (= ["a plain old string"] (interpolate "a plain old string")))) 1.30 + (testing "some value replacement forms" 1.31 + (is (= '["" foo " and " bar ""] (interpolate "~{foo} and ~{bar}")))) 1.32 + (testing "some fn-calling forms" 1.33 + (is (= '["" (+ 1 2) " and " (vector 3) ""] (interpolate "~(+ 1 2) and ~(vector 3)"))))) 1.34 + 1.35 +(deftest test-<< 1.36 + (testing "docstring examples" 1.37 + (let [v 30.5 1.38 + m {:a [1 2 3]}] 1.39 + (is (= "This trial required 30.5ml of solution." 1.40 + (<< "This trial required ~{v}ml of solution."))) 1.41 + (is (= "There are 30 days in November." 1.42 + (<< "There are ~(int v) days in November."))) 1.43 + (is (= "The total for your order is $6." 1.44 + (<< "The total for your order is $~(->> m :a (apply +))."))))))