summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/jester/types_test.clj37
1 files changed, 25 insertions, 12 deletions
diff --git a/test/jester/types_test.clj b/test/jester/types_test.clj
index 84b28fe..da57047 100644
--- a/test/jester/types_test.clj
+++ b/test/jester/types_test.clj
@@ -3,10 +3,13 @@
[clojure.test.check :refer [quick-check]]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :refer [for-all]]
+ [clojure.test.check.clojure-test :refer [defspec]]
[jester.types :as sut]))
+(alter-meta! #'for-all assoc :style/indent 1)
+
(def string-enum-gen (gen/fmap #(cons 'enum %) (gen/vector gen/string)))
-(def number-enum-gen (gen/fmap #(cons 'enum %) (gen/vector gen/double)))
+(def number-enum-gen (gen/fmap #(cons 'enum %) (gen/vector (gen/double* {:NaN? false}))))
(def boolean-enum-gen (gen/fmap #(cons 'enum %) (gen/vector gen/boolean)))
(def enum-gen (gen/one-of [string-enum-gen
number-enum-gen
@@ -27,15 +30,13 @@
(gen/fmap #(list 'list %) subgen))
(defn array-type-gen [subgen]
- (gen/recursive-gen (fn [gen]
- (gen/fmap (fn [[main rest]]
- (into main (when rest ['& rest])))
- (gen/tuple (gen/vector gen)
- (gen/one-of
- [(gen/return nil)
- (array-type-gen gen)
- (list-type-gen gen)]))))
- subgen))
+ (gen/fmap (fn [[main rest]]
+ (into main (when rest ['& rest])))
+ (gen/tuple (gen/vector subgen 0 5)
+ (gen/one-of
+ [(gen/return nil)
+ ;; (array-type-gen subgen)
+ (list-type-gen subgen)]))))
(defn map-type-gen [keygen valgen]
(gen/fmap #(cons 'map %) (gen/tuple keygen valgen)))
@@ -44,7 +45,7 @@
(gen/fmap #(cons '-> %) (gen/tuple argsgen resultgen)))
(defn record-type-gen [subgen]
- (gen/map gen/symbol subgen))
+ (gen/map gen/keyword subgen))
(defn compound-type-gen [subgen]
(gen/one-of [(optional-type-gen subgen)
@@ -54,7 +55,19 @@
(func-type-gen (array-type-gen subgen) subgen)
(record-type-gen subgen)]))
-(gen/sample (compound-type-gen atomic-type-gen))
+(def type-gen (gen/recursive-gen compound-type-gen atomic-type-gen))
+
+(defspec any-supertype-of-all 200
+ (for-all [type type-gen]
+ (sut/subtype? type 'any)))
+
+(defspec optional-supertype-of-raw-type 200
+ (for-all [type type-gen]
+ (sut/subtype? type `(optional ~type))))
+
+(defspec array-subtype-of-list-if-all-types-are-subtypes 200
+ (for-all [array-type (array-type-gen string-enum-gen)]
+ (sut/subtype? array-type '(list string))))
(deftest assert-type
(testing "happy paths"