-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #953 from jasonjckn/assert
feat(assert): adds new assert-like functionality to check malli schema
- Loading branch information
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns malli.assert-test | ||
(:refer-clojure :exclude [assert]) | ||
(:require | ||
[clojure.test :refer [deftest is]] | ||
[malli.core :refer [assert]])) | ||
|
||
|
||
(set! *assert* true) | ||
|
||
(deftest assert-throws-test | ||
(is (thrown? #?(:clj Exception, :cljs js/Error) | ||
(assert :int "42" ))) | ||
(is (thrown? #?(:clj Exception, :cljs js/Error) | ||
(assert int? "42" ))) | ||
(is (thrown? #?(:clj Exception, :cljs js/Error) | ||
(assert string? 42))) | ||
(is (thrown? #?(:clj Exception, :cljs js/Error) | ||
(assert int? nil))) | ||
(is (thrown? #?(:clj Exception, :cljs js/Error) | ||
(assert [:map [:a int?]] {:a "42"}))) | ||
(is (thrown? #?(:clj Exception, :cljs js/Error) | ||
(assert ::invalid-schema 42)))) | ||
|
||
(deftest assert-checked-and-does-not-throw | ||
(is (= 42 (assert :int 42 ))) | ||
(is (= 42 (assert int? 42 ))) | ||
(is (= "42" (assert string? "42"))) | ||
(is (= nil (assert any? nil))) | ||
(is (= {:a 42} (assert [:map [:a int?]] {:a 42})))) |