/
validation_test.clj
executable file
·659 lines (543 loc) · 29.3 KB
/
validation_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
(ns clj-schema.validation-test
(:use clojure.test
clj-schema.schema
clj-schema.validation
clj-schema.test-schemas)
(:import clojure.lang.Keyword))
(defn first-name-bob? [x]
(-> x :name :first (= "Bob")))
(defmacro ^:private test-case
[schema m errors]
;; No autogensyms, cus it this way the reporting is readable.
`(let [~'schema ~schema
~'errors ~errors
~'m ~m]
(is (= ~'errors (validation-errors (if (schema? ~'schema)
~'schema
(map-schema :strict ~'schema))
~'m)))))
(deftest test-validation-errors
(testing "Degenerate cases"
(test-case nil {} #{})
(test-case [] {} #{})
(test-case nil nil #{})
(test-case [] nil #{}))
(test-case family-schema [[:a] 2 [:b] 4] #{"Constraint failed: '[:or nil? map?]'"})
(testing "One simple-schema per path"
(test-case [[:a] number?]
{:a 1}
#{})
(test-case [[:b] Integer]
{}
#{"Map did not contain expected path [:b]."})
(test-case [[:bb] Integer]
{:bb "bb"}
#{"Expected value \"bb\", at path [:bb], to be an instance of class java.lang.Integer, but was java.lang.String"})
(test-case [[:b :c] Integer]
{:b "a"}
#{"Path [:b] was not specified in the schema."
"Map did not contain expected path [:b :c]."})
(test-case [[:b :c] Integer]
{:b {:c :a}}
#{"Expected value :a, at path [:b :c], to be an instance of class java.lang.Integer, but was clojure.lang.Keyword"}))
(testing "Multiple predicates per path - lists all failures, not just first"
(test-case [[:a] [number? pos?]]
{:a 1}
#{})
(test-case [[:b] [String Keyword]]
{}
#{"Map did not contain expected path [:b]."})
(test-case [[:b] [String Keyword]]
{:b 1.1}
#{"Expected value 1.1, at path [:b], to be an instance of class java.lang.String, but was java.lang.Double"
"Expected value 1.1, at path [:b], to be an instance of class clojure.lang.Keyword, but was java.lang.Double"})
(test-case [[:b :c] [number? pos?]]
{:b "a"}
#{"Path [:b] was not specified in the schema."
"Map did not contain expected path [:b :c]."})
(test-case [[:b :c] [String Keyword]]
{:b {:c 1.1}}
#{"Expected value 1.1, at path [:b :c], to be an instance of class java.lang.String, but was java.lang.Double"
"Expected value 1.1, at path [:b :c], to be an instance of class clojure.lang.Keyword, but was java.lang.Double"}))
;; "Handles combo of missing paths and erroneous values"
(test-case [[:b :c] [number? pos?]
[:b :d] identity
[:x :y] [neg? number?]
[:z :z :top] keyword?]
{:b {:c "a" :d :foo}
:x {:y 99}}
#{"Value \"a\", at path [:b :c], did not match predicate 'number?'."
"Value \"a\", at path [:b :c], did not match predicate 'pos?'."
"Map did not contain expected path [:z :z :top]."
"Value 99, at path [:x :y], did not match predicate 'neg?'." })
(test-case [[:a] (sequence-of person-schema)]
{:a [{:name {:first "Roberto"} :height 11} {:name {:first "Roberto"} :height "11"}]}
#{"Expected value \"11\", at path [:a 1 :height], to be an instance of class java.lang.Number, but was java.lang.String"})
;; "if the schema path isn't present, and using a schema the seq, we get a not present error"
(test-case [[:a] (sequence-of person-schema)]
{:not-a [{:name {:first "Roberto"} :height 34} {:name {:first "Roberto"} :height "34"}]}
#{"Map did not contain expected path [:a]."
"Path [:not-a] was not specified in the schema."})
;;;; if an optional schema path isn't present - no error messages
(test-case [(optional-path [:a]) (sequence-of person-schema)]
{:not-a [{:name {:first "Roberto"} :height 91} {:name {:first "Roberto"} :height "91"}]}
#{"Path [:not-a] was not specified in the schema."})
;;;; `optional-path` has no effect if the schema path is present
(test-case [(optional-path [:a]) (sequence-of person-schema)]
{:a [{:name {:first "Roberto"} :height 70} {:name {:first "Roberto"} :height "70"}]}
#{"Expected value \"70\", at path [:a 1 :height], to be an instance of class java.lang.Number, but was java.lang.String"})
;;;; you can mix types of simple-schemas: preds with schemas
(test-case [[:a] (sequence-of [first-name-bob? person-schema])]
{:a [{:name {:first "Roberto"} :height 44} {:name {:first "Chris"} :height "4a"}]}
#{"Value {:name {:first \"Roberto\"}, :height 44}, at path [:a 0], did not match predicate 'clj-schema.validation-test/first-name-bob?'."
"Expected value \"4a\", at path [:a 1 :height], to be an instance of class java.lang.Number, but was java.lang.String"
"Value {:name {:first \"Chris\"}, :height \"4a\"}, at path [:a 1], did not match predicate 'clj-schema.validation-test/first-name-bob?'."})
;;;; ... multiple strict schemas together makes little sense - one schema will think extra keys were not specified by it, though they were by the other schema
(test-case [[:a] (sequence-of [name-schema person-schema])]
{:a [{:name {:first :Roberto} :height 69} {:name {:first "Roberto"} :height "69"}]}
#{"Path [:a 0 :height] was not specified in the schema."
"Path [:a 1 :height] was not specified in the schema."
"Expected value \"69\", at path [:a 1 :height], to be an instance of class java.lang.Number, but was java.lang.String"
"Expected value :Roberto, at path [:a 0 :name :first], to be an instance of class java.lang.String, but was clojure.lang.Keyword"})
;;;; schema on right of schema, can be made an or, and can work with both preds and schemas mixed
(test-case [[:a] [:or nil? person-schema]]
{:a nil}
#{})
;;;; you can have just one thing in the ':or' - but please don't it is weird
(test-case [[:a] (sequence-of [:or person-schema])]
{:a [{:name {:first "Roberto"} :height "76"}]}
#{"Expected value \"76\", at path [:a 0 :height], to be an instance of class java.lang.Number, but was java.lang.String"})
;;;; when both :or options fail - see errors for both 'nil?' and 'person-schema'
(test-case [[:a] [:or nil? person-schema]]
{:a {:name {:first "Roberto"} :height "66"}}
#{"Expected value \"66\", at path [:a :height], to be an instance of class java.lang.Number, but was java.lang.String" "Value {:name {:first \"Roberto\"}, :height \"66\"}, at path [:a], did not match predicate 'nil?'."})
;;;; or collects all failures in the sequence being checked
(test-case [[:a] (sequence-of [:or nil? person-schema])]
{:a [{:name {:first "Roberto"} :height "88"} {:name {:first "Roberto"} :height 88}]}
#{"Expected value \"88\", at path [:a 0 :height], to be an instance of class java.lang.Number, but was java.lang.String" "Value {:name {:first \"Roberto\"}, :height \"88\"}, at path [:a 0], did not match predicate 'nil?'."})
;;;; nested schemas - no errors
(test-case [[:a :family] family-schema]
{:a {:family {:mom {:name {:first "Theresa"}
:height 42}
:dad {:name {:first "Stanley"}
:height 53}}}}
#{})
;;;; nested schemas - with errors
(test-case [[:a :family] family-schema]
{:a {:family {:mom {:name {:first :Theresa}
:height 42}
:dad {:name {:first "Stanley"}
:height :53}}}}
#{"Expected value :Theresa, at path [:a :family :mom :name :first], to be an instance of class java.lang.String, but was clojure.lang.Keyword"
"Expected value :53, at path [:a :family :dad :height], to be an instance of class java.lang.Number, but was clojure.lang.Keyword"})
;;;; strict schemas fail if there are more keys than specified
(test-case [[:a :family] family-schema]
{:a {:family {:mom {:name {:first "Theresa"
:last "Greepostalla"}
:height 42
:favorite-book "Twilight"}
:child "David"
:dad {:name {:first "Stanley"
:middle "Roberto-Gustav"}
:height 53
:favorite-sport "Fishing"}}
:house "Large"}
:b {:car "Honda Accord"}}
#{"Path [:b :car] was not specified in the schema."
"Path [:a :family :mom :favorite-book] was not specified in the schema."
"Path [:a :family :dad :name :middle] was not specified in the schema."
"Path [:a :family :child] was not specified in the schema."
"Path [:a :house] was not specified in the schema."
"Path [:a :family :mom :name :last] was not specified in the schema."
"Path [:a :family :dad :favorite-sport] was not specified in the schema."})
;;;; nested loose schemas don't cause extra path errors for their paths, even if inside a surrounding strict schema
(test-case [[:a :family] mom-strict-dad-loose-family-schema]
{:a {:family {:mom {:name {:first "Theresa"
:last "Greepostalla"}
:height 42
:favorite-book "Twilight"}
:child "David"
:dad {:name {:first "Stanley"
:middle "Roberto-Gustav"}
:height 53
:favorite-sport "Fishing"}} ;; Dad's loose so this extra key causes no problems
:house "Large"}
:b {:car "Honda Accord"}}
#{"Path [:b :car] was not specified in the schema."
"Path [:a :family :mom :favorite-book] was not specified in the schema."
"Path [:a :family :child] was not specified in the schema."
"Path [:a :house] was not specified in the schema."
"Path [:a :family :mom :name :last] was not specified in the schema."})
;;;; stops looking for extra paths at validated path ends
(test-case [[:a :family] map?]
{:a {:family {:mom {:name {:first "Theresa"
:last "Greepostalla"}
:height 42
:favorite-book "Twilight"}
:child "David"
:dad {:name {:first "Stanley"
:middle "Roberto-Gustav"}
:height 53
:favorite-sport "Fishing"}} ;; Dad's loose so this extra key causes no problems
:house "Large"}
:b {:car "Honda Accord"}}
#{"Path [:b :car] was not specified in the schema."
"Path [:a :house] was not specified in the schema."})
;;;; marked as 'sequence-of' but only one value - causes an error
(test-case [[:a] (sequence-of person-schema)]
{:a {:name {:first "Roberto"} :height "76"}}
#{"At parent path [:a], constraint failed: '[:or nil? sequential?]'"})
;;;; using 'sequence-of' with an 'Number' class - means there is a seq of numbers
(test-case [[:a] (sequence-of Number)]
{:a 1}
#{"At parent path [:a], constraint failed: '[:or nil? sequential?]'"})
;;;; nil is an acceptable value for a 'sequence-of' schema
(test-case [[:a] (sequence-of integer?)]
{:a nil}
#{})
;;;; sequence-of can be used from within other nested simple-schemas -- [:a] is single item
(test-case [[:a] [:or Number (sequence-of Number)]]
{:a 4}
#{})
;;;; ... <continued from above> -- [:a] is sequential
(test-case [[:a] [:or Number (sequence-of Number)]]
{:a [4 5 6 7]}
#{})
;;;; marked as 'set-of' but only one value - causes an error
(test-case [[:a] (set-of person-schema)]
{:a {:name {:first "Roberto"} :height "76"}}
#{"At parent path [:a], constraint failed: '[:or nil? set?]'"})
;;;; using 'set-of' with an 'Number' predicate - means there is a set of numbers
(test-case [[:a] (set-of Number)]
{:a 1}
#{"At parent path [:a], constraint failed: '[:or nil? set?]'"})
;;;; nil is an acceptable value for a 'set-of' schema
(test-case [[:a] (set-of integer?)]
{:a nil}
#{})
;;;; set-of can be used from within other nested simple-schemas -- #{:a} is single item
(test-case [[:a] [:or Number (set-of Number)]]
{:a 4}
#{})
;;;; ... <continued from above> -- [:a] is sequential
(test-case [[:a] [:or Number (set-of Number)]]
{:a #{4 5 6 7}}
#{})
;;;; nested loose schemas don't count toward strict schema's keys
(test-case [[:a] loose-height-schema]
{:a {:height 72 :extra-key-doesnt-cuase-error "foo"}
:b "oops"}
#{"Path [:b] was not specified in the schema."})
;;;; can use Classes as a schema
(test-case [[:a] String]
{:a "Roberto"}
#{})
(test-case [[:a] String]
{:a :Roberto}
#{"Expected value :Roberto, at path [:a], to be an instance of class java.lang.String, but was clojure.lang.Keyword"})
;; instance-of? satisfies the predicate -- Long is an instance of Number
(test-case [[:a] Number]
{:a (long 999)}
#{})
;;;; Wildcard paths
;; no problems if all paths match the wildcards in the path
(test-case [[(wild Keyword) (wild string?) 99] String]
{:a {"b" {99 "letter b"}}
:xavier {"yellow" {99 "zebra"}}}
#{})
;; validates the value at the given path, like normal
(test-case [[:a (wild keyword?) (wild string?)] String]
{:a {:x {"b" :b "c" "letter c"}}}
#{"Expected value :b, at path [:a :x \"b\"], to be an instance of class java.lang.String, but was clojure.lang.Keyword"})
;; if a path exists that doesn't match the wildcard, it is considered an extraneous path
(test-case [[:a] (map-schema :strict [[(wild Keyword)] String])]
{:a {"b" "foo" "c" "bar"}}
#{"Path [:a \"c\"] was not specified in the schema."
"Path [:a \"b\"] was not specified in the schema."})
;; can use Class objects as wildcard part of wildcard path
(test-case [[:a (wild String)] String]
{:a {"b" :b "c" "letter c"}}
#{"Expected value :b, at path [:a \"b\"], to be an instance of class java.lang.String, but was clojure.lang.Keyword"})
;; can use 'and statements' in simple-schemas
(test-case [[:a (wild [String #{"baz" "qux"}])] String]
{:a {"baz" :b "c" "letter c"}}
#{"Path [:a \"c\"] was not specified in the schema."
"Expected value :b, at path [:a \"baz\"], to be an instance of class java.lang.String, but was clojure.lang.Keyword"})
;; if no keys of the leaf-map match the wildcard, that is OK
(test-case [[:a (wild string?)] String]
{:a {999 :boom}}
#{"Path [:a 999] was not specified in the schema."})
;; Wildcard paths match empty maps
(test-case [[:a (wild string?)] String]
{:a {}}
#{})
;; don't get missing path errors for nested schemas within wildcard paths - regression test Jun 15, 2012
(test-case [[:carted (wild String)] product-schema]
{:carted {"Sneetch" {:quantity 5 :price 100}}}
#{})
;; doesn't confuse paths with string keys as wildcard paths - regression test Jun 15, 2012
(test-case [["Sneetch" :unit-price-cents] String]
{"Sneetch" {:unit-price-cents "a"}}
#{})
;; won't confuse them in nested paths either
(test-case [["Sneetch" :unit-price-cents] (map-schema :strict [[:a] string?])]
{"Sneetch" {:unit-price-cents {:a "a"}}}
#{})
;; when top level keys in the map is wildcarded
(test-case [[(wild (comp keyword #(re-matches #"key\d+" %) name))] String]
{:key0 "val0" :key1 "val1" :key2 "val2"}
#{})
;; when top level keys in the map is wildcarded, but there are top
;; level keys which dont match the wildcard
(test-case [[(wild (comp keyword #(re-matches #"key\d+" %) name))] String]
{:key0 "val0" :key1 "val1" :key2 "val2" :top-level "another"}
#{"Path [:top-level] was not specified in the schema."})
;; present concrete paths at the same level as the wildcard path,
;; wont be considered as an extraneous path
(test-case [[:top-level] String
[(wild (comp keyword #(re-matches #"key\d+" %) name))] String]
{:key0 "val0" :key1 "val1" :key2 "val2" :top-level "another"}
#{})
;; paths that are longer than the map accepts are handled without throwing exceptions
(test-case [[:a (wild string?)] String]
{:a 1}
#{"Path [:a] was not specified in the schema."})
;; can't have empty maps at wilcard paths, they don't count
(test-case [[:a :b] (map-schema :strict [[(wild String)] Number])]
{:a {}}
#{"Map did not contain expected path [:a :b]."})
;; ... <continued>
(test-case [[:a :b] (map-schema :strict [[:banana-count] Number
[(wild String)] Number])]
{:a {}}
#{"Map did not contain expected path [:a :b]."})
;;;; optional paths interactions with wild card paths
;; no missing path error even when it finds none that match the wildcard
(test-case [(optional-path [:a (wild string?)]) String]
{}
#{})
;; no missing path error, even when the value isn't map as was expected
(test-case [(optional-path [:a (wild string?)]) String]
{:a 1}
#{"Path [:a] was not specified in the schema."})
;; notices extraneous paths that have separately included subpaths
;; in same schema - regression test July 20, 2012
(test-case [[:name] String
[:data] map? ;; this guy = 'separately included subpath'
[:data :a] String]
{:name "Roberto"
:data {:a "cool"
:b "dude"}}
#{"Path [:data :b] was not specified in the schema."})
;; [Issue #1] - Can AND a sequential with a single item schema
(test-case [[:a] [empty? (sequence-of String)]]
{:a []}
#{})
;; [Issue #1] - continued...
(test-case [[:a] [empty? (sequence-of String)]]
{:a ["Roberto"]}
#{"Value [\"Roberto\"], at path [:a], did not match predicate 'empty?'."}))
(deftest test-schemas-can-check-constraints-against-entire-map
(let [errors (validation-errors schema-with-constraints {:a "string"
:b 99
:extra 47})]
(is (= #{"Constraint failed: '(fn [m] (even? (count (keys m))))'" "Constraint failed: '(comp even? count distinct vals)'"}
errors)))
(is (= #{} (validation-errors schema-with-constraints {:a "string"
:b 99}))))
(deftest test-loose-schema-validations
(are [schema m errors] (= errors (validation-errors (map-schema :loose schema) m))
;; extra paths on wild card paths are ok if the schema is loose
[[:a (wild string?)] String]
{:a {999 :boom}}
#{}
))
(deftest test-valid?
(testing "valid iff there'd be no error messages"
(are [schema m result] (= (valid? (map-schema :strict schema) m) result)
[[:a] number?]
{:a 1}
true
[[:b] number?]
{}
false)))
;; TODO ALex July 30, 2012 -- move into internal ns all about wildcard paths
(deftest test-wildcard-path->concrete-paths
(are [m wildcard-path concrete-paths] (= (set concrete-paths)
(set (#'clj-schema.validation/wildcard-path->concrete-paths m
wildcard-path)))
;; base cases
{}
[]
[[]]
{:a 1}
[:a]
[[:a]]
;; expands concrete path into itself
{:a {:any-keyword {:c {:any-keyword 'SOMETHING}}}}
[:a :any-keyword :c :any-keyword]
[[:a :any-keyword :c :any-keyword]]
;; shortest wildcard works -- important test don't remove
{:a 1}
[(wild keyword?)]
[[:a]]
;; expands wildcard path into all possible paths based on the supplied map 'm'
{:a {:b {:c "foo"}
:x {:c "bar"}}}
[:a (wild keyword?) :c]
[[:a :b :c]
[:a :x :c]]
;; if a map doesn't have enough nesting to satisfy a wildcard path, then
;; there are no concrete paths generated
{:a 1}
[:a (wild :b)]
[]
))
;; same here
(deftest test-covered-by-wildcard-path?
(are [path wildcard-path covered?] (= covered? (#'clj-schema.validation/covered-by-wildcard-path? path wildcard-path))
;; base case
[]
[]
true
;; ..
[:a]
[(wild keyword?)]
true
;; ..
[:a :b]
[(wild keyword?)]
false
;; ..
[:a :b]
[:a :b]
true
[:a]
[:a :b]
false
[:a :b]
[:a]
false
[:a "S"]
[(wild keyword?) (wild String)]
true))
(def-map-schema foo-schema
[[:a] String])
(deftest test-validate-and-handle
(is (= "SUCCESS: {:a \"one\"}"
(validate-and-handle {:a "one"}
foo-schema
(fn [m] (str "SUCCESS: " m))
(fn [m errors] (str "FAIL: " m errors)))))
(is (= "FAIL: {:b 2}(\"Map did not contain expected path [:a].\" \"Path [:b] was not specified in the schema.\")"
(validate-and-handle {:b 2}
foo-schema
(fn [m] (str "SUCCESS: " m))
(fn [m errors] (str "FAIL: " m errors))))))
(deftest test-seq-validation-errors
(is (= #{}
(validation-errors (seq-schema :all String) ["a" "b" "c"])))
(is (= #{"Expected value :a, at path [0], to be an instance of class java.lang.String, but was clojure.lang.Keyword"
"Expected value :b, at path [1], to be an instance of class java.lang.String, but was clojure.lang.Keyword"
"Expected value :c, at path [2], to be an instance of class java.lang.String, but was clojure.lang.Keyword"}
(validation-errors (seq-schema :all String) [:a :b :c]))))
(deftest test-set-validation-errors
(is (= #{}
(validation-errors (set-schema String) #{"a" "b" "c"})))
(is (= #{"Expected value :a, at path [:*], to be an instance of class java.lang.String, but was clojure.lang.Keyword"
"Expected value :b, at path [:*], to be an instance of class java.lang.String, but was clojure.lang.Keyword"
"Expected value :c, at path [:*], to be an instance of class java.lang.String, but was clojure.lang.Keyword"}
(validation-errors (set-schema String) #{:a :b :c}))))
(deftest test-simple-schemas
(is (= #{}
(validation-errors String "neat")))
(is (= #{"Expected value 44 to be an instance of class java.lang.String, but was java.lang.Long"}
(validation-errors String 44)))
(is (= #{}
(validation-errors #"neat" "neato")))
(is (= #{"Value \"neat\" did not match predicate '(fn [s] (re-find #\"^neato$\" s))'."}
(validation-errors #"^neato$" "neat")))
(is (= #{}
(validation-errors [:or String Number] "neat")
(validation-errors [:or String Number] 55)))
(is (= #{"Expected value :keyword to be an instance of class java.lang.Number, but was clojure.lang.Keyword" "Expected value :keyword to be an instance of class java.lang.String, but was clojure.lang.Keyword"}
(validation-errors [:or String Number] :keyword)))
(is (= #{"Expected value :keyword to be an instance of class java.lang.Number, but was clojure.lang.Keyword" "Expected value :keyword to be an instance of class java.lang.String, but was clojure.lang.Keyword"}
(validation-errors [:or Number String] :keyword)))
(is (= #{}
(validation-errors [Number Long] (long 55))))
(is (= #{"Expected value :keyword to be an instance of class java.lang.Number, but was clojure.lang.Keyword"
"Expected value :keyword to be an instance of class java.lang.Long, but was clojure.lang.Keyword"}
(validation-errors [Number Long] :keyword)))
(is (= #{}
(validation-errors string? "string")))
(is (= #{"Value 99 did not match predicate 'string?'."}
(validation-errors string? 99)))
(is (= #{}
(validation-errors 1 1)))
(is (= #{"Value 99 did not match predicate '(fn [x] (= 1 x))'."}
(validation-errors 1 99)))
(is (= #{}
(validation-errors :a :a)))
(is (= #{"Value {:a true} did not match predicate '(fn [x] (= :a x))'."}
(validation-errors :a {:a true}))))
(deftest test->string-schema
(is (= #{} (validation-errors (->string-schema [Long neg?]) "-55")))
(is (= #{} (validation-errors (->string-schema pos?) "55")))
(is (= #{} (validation-errors (->string-schema (set-of Long)) "#{55, 44, -33}")))
(is (= #{"After applying :pre-validation-transform of #'clojure.core/read-string to original of \"[:a, 44, -33]\", expected value :a, at path [0], to be an instance of class java.lang.Long, but was clojure.lang.Keyword"}
(validation-errors (->string-schema (sequence-of Long)) "[:a, 44, -33]")))
(is (= #{"After applying :pre-validation-transform of #'clojure.core/read-string to original of \"55\", value 55 did not match predicate 'neg?'."}
(validation-errors (->string-schema neg?) "55")))
(is (= #{"Value 55 could not be transformed before validation using '#'clojure.core/read-string'."}
(validation-errors (->string-schema [Long pos?]) 55))))
(deftest test-after-transform
(is (= #{} (validation-errors (after-transform #'deref (sequence-of Long)) (atom [1 2 3])))))
(deftest test-seq-layouts
(is (= #{}
(validation-errors checkers-board-schema [[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]])))
(is (= #{"Constraint failed: '(fn [xs] (= (count seq-layout) (count xs)))'"}
(validation-errors checkers-board-schema [[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]])))
(is (= #{"Value 77777, at path [3 5], did not match predicate '#{1}'."}
(validation-errors checkers-board-schema [[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 77777 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]]))))
(deftest edge-cases-in-schema-construction
(is (= #{}
(validation-errors non-empty-map {:a 1})))
(is (= #{}
(validation-errors unsorted-non-empty-map {:a 1})))
(is (= #{"Constraint failed: '(complement empty?)'"}
(validation-errors unsorted-non-empty-map {})))
(is (= #{"Constraint failed: '(fn [m] (not (sorted? m)))'"}
(validation-errors unsorted-non-empty-map (sorted-map :a 1))))
(is (= #{}
(validation-errors red-list (list :red :red))))
(is (= #{"Constraint failed: '(fn [xs] (even? (count xs)))'"}
(validation-errors red-list (list :red :red :red))))
(is (= #{"Constraint failed: 'list?'"}
(validation-errors red-list (vector :red :red))))
(is (= #{}
(validation-errors red-set (sorted-set :red :RED))))
(is (= #{"Constraint failed: '(fn [xs] (even? (count xs)))'"}
(validation-errors red-set (sorted-set :red :RED :Red))))
(is (= #{"Constraint failed: 'sorted?'"}
(validation-errors red-set (hash-set :red :RED)))))