Permalink
Browse files

Adding vec spec tests for types

  • Loading branch information...
1 parent d9cef7e commit 28505ea7339e40ce80b8bdb16c08f058475b62d4 @fogus fogus committed Dec 8, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 test/fogus/me/invariant_tests.clj
View
10 test/fogus/me/invariant_tests.clj
@@ -12,7 +12,7 @@
;; remove this notice, or any other, from this software.
(ns fogus.me.invariant-tests
- (:use [trammel.core :only [defconstrainedrecord]])
+ (:use [trammel.core :only [defconstrainedrecord defconstrainedtype]])
(:use [clojure.test :only [deftest is]]))
@@ -21,6 +21,9 @@
Object
(toString [this] (str "record Foo has " a " and " b)))
+(defconstrainedtype Bar [a b]
+ [(every? number? [a b])])
+
(deftest test-constrained-record-with-vector-spec
(is (= (:a (->Foo)) 1))
(is (= (:b (->Foo)) 2))
@@ -34,6 +37,11 @@
(is (thrown? Error (->Foo :a :b)))
(is (thrown? Error (->Foo :a 42 :b nil))))
+(deftest test-constrained-type-with-vector-spec
+ (is (= (.a (->Bar 1 2)) 1))
+ (is (= (:b (->Bar 1 2)) 2))
+ (is (thrown? Error (->Bar :a :b))))
+
;; testing default clojure pre/post maps
(defconstrainedrecord Bar [a 1 b 2]

0 comments on commit 28505ea

Please sign in to comment.