From f378b2717141fa2a7e72c042a60a383c5cd28671 Mon Sep 17 00:00:00 2001 From: Plinio Balduino Date: Fri, 13 Apr 2012 23:00:02 -0300 Subject: [PATCH] Added some matchers --- src/north/core.clj | 40 ++++++++++++++++++++++++++++++++++++--- test/north/test/core.clj | 41 +++++++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/north/core.clj b/src/north/core.clj index fe3b3f6..9478e25 100644 --- a/src/north/core.clj +++ b/src/north/core.clj @@ -1,13 +1,47 @@ (ns north.core) +(set! *warn-on-reflection* true) + (def ^:dynamic test-map {}) (defmacro describe [description & body] `(do (in-ns 'north.core) - (def test-map (assoc test-map (keyword ~description) {})) - (println test-map) + (println (format "before %s" test-map)) + + (println (format "description %s" ~description)) + + (def test-map + (assoc test-map + (keyword ~description) {})) + + (println (format "after %s" test-map)) ~body)) (defmacro context [description & body] `(do - ())) \ No newline at end of file + ~body)) + +(defmacro it [description & body] + `(defn (symbol ~description) [] + ~body)) + +(defn should + ([result matcher] + (matcher result)) + ([result matcher expectation] + (matcher result expectation))) + +(defn- verify [result expectation operation description] + (assert (operation result expectation) (format "Assertion failed. %s was expected to be %s %s" result description expectation))) + +(defn be-not-equals [result expectation] + (verify result expectation not= "different than")) + +(defn be-equals [result expectation] + (assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation))) + +(defn be-true [result] + (be-equals result true)) + +(defn be-false [result] + (be-equals result false)) \ No newline at end of file diff --git a/test/north/test/core.clj b/test/north/test/core.clj index f4383c8..a6dd777 100644 --- a/test/north/test/core.clj +++ b/test/north/test/core.clj @@ -1,10 +1,37 @@ (ns north.test.core (:use [north.core])) -(describe "North" - (context "using context" - (it "should test simple assertions" - (should (= 1 1) be-true) - (should (= 1 0) be-false) - (should (+ 1 1) be-equals 2) - (should (+ 1 1) be-not-equals 1)))) \ No newline at end of file +(println +(macroexpand + '(describe "North" + (context "using context" + (it "should test simple assertions" + (should (= 1 1) be-true) + (should (= 1 0) be-false) + (should (+ 1 1) be-equals 2) + (should (+ 1 1) be-not-equals 1)))))) + +(do + (clojure.core/in-ns + (quote north.core)) + (clojure.core/println + (clojure.core/format "before %s" north.core/test-map)) + (clojure.core/println + (clojure.core/format "description %s" "North")) + (def north.core/test-map + (clojure.core/assoc north.core/test-map + (clojure.core/keyword "North") {})) + (clojure.core/println + (clojure.core/format "after %s" north.core/test-map)) + ((context "using context" + (it "should test simple assertions" + (should (= 1 1) be-true) + (should (= 1 0) be-false) + (should (+ 1 1) be-not-equals 1) + (should (+ 1 1) be-equals 2) + + true + ) + ) + ) + ) \ No newline at end of file