From c78f45d08b62f9b53b1503d1e9c83e6d7adca83f Mon Sep 17 00:00:00 2001 From: Frantisek Sodomka Date: Thu, 14 May 2009 20:27:45 +0000 Subject: test-clojure: common helper functions in test-utils; control: do --- src/clojure/contrib/test_clojure/control.clj | 46 +++++++++++++++++++++++-- src/clojure/contrib/test_clojure/logic.clj | 8 ++--- src/clojure/contrib/test_clojure/sequences.clj | 5 --- src/clojure/contrib/test_clojure/test_utils.clj | 18 ++++++++++ 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 src/clojure/contrib/test_clojure/test_utils.clj (limited to 'src/clojure/contrib/test_clojure') diff --git a/src/clojure/contrib/test_clojure/control.clj b/src/clojure/contrib/test_clojure/control.clj index 483250d7..134711c8 100644 --- a/src/clojure/contrib/test_clojure/control.clj +++ b/src/clojure/contrib/test_clojure/control.clj @@ -10,17 +10,59 @@ ;; (ns clojure.contrib.test-clojure.control - (:use clojure.contrib.test-is)) + (:use clojure.contrib.test-is + [clojure.contrib.test-clojure.test-utils :only (exception)])) + +;; *** Helper functions *** + +(defn maintains-identity [f] + (are (= (f _) _) + nil + false true + 0 42 + 0.0 3.14 + 2/3 + 0M 1M + \c + "" "abc" + 'sym + :kw + () '(1 2) + [] [1 2] + {} {:a 1 :b 2} + #{} #{1 2} )) + ; http://clojure.org/special_forms ; http://clojure.org/macros -; do +(deftest test-do + (are (= _1 _2) + ; no params => nil + (do) nil + + ; return last + (do 1) 1 + (do 1 2) 2 + (do 1 2 3 4 5) 5 + + ; evaluate and return last + (let [a (atom 0)] + (do (reset! a (+ @a 1)) ; 1 + (reset! a (+ @a 1)) ; 2 + (reset! a (+ @a 1)) ; 3 + @a)) 3 ) + + ; identity (= (do x) x) + (maintains-identity (fn [_] (do _))) ) + + ; loop/recur ; throw, try ; [if (logic.clj)], if-not, if-let ; when, when-not, when-let, when-first + ; cond, condp ; [for, doseq (for.clj)] diff --git a/src/clojure/contrib/test_clojure/logic.clj b/src/clojure/contrib/test_clojure/logic.clj index 1dba6d35..40a94c37 100644 --- a/src/clojure/contrib/test_clojure/logic.clj +++ b/src/clojure/contrib/test_clojure/logic.clj @@ -9,12 +9,8 @@ ;; Created 1/29/2009 (ns clojure.contrib.test-clojure.logic - (:use clojure.contrib.test-is)) - -;; *** Helper functions *** - -(defn exception [] - (throw (new Exception "Exception which should never occur"))) + (:use clojure.contrib.test-is + [clojure.contrib.test-clojure.test-utils :only (exception)])) ;; *** Tests *** diff --git a/src/clojure/contrib/test_clojure/sequences.clj b/src/clojure/contrib/test_clojure/sequences.clj index 72251295..7c2721b4 100644 --- a/src/clojure/contrib/test_clojure/sequences.clj +++ b/src/clojure/contrib/test_clojure/sequences.clj @@ -10,11 +10,6 @@ (ns clojure.contrib.test-clojure.sequences (:use clojure.contrib.test-is)) -;; *** Helper functions *** - -(defn exception [] - (throw (new Exception "Exception which should never occur"))) - ;; *** Tests *** diff --git a/src/clojure/contrib/test_clojure/test_utils.clj b/src/clojure/contrib/test_clojure/test_utils.clj new file mode 100644 index 00000000..6fe22161 --- /dev/null +++ b/src/clojure/contrib/test_clojure/test_utils.clj @@ -0,0 +1,18 @@ +;; Copyright (c) Frantisek Sodomka. 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-clojure.test-utils + (:use [clojure.contrib.combinatorics :only (combinations)])) + + +(defn exception + "Use this function to ensure that execution of a program doesn't + reach certain point." + [] + (throw (new Exception "Exception which should never occur"))) + -- cgit v1.2.3-18-g5258