-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distributive schemas #1086
Merged
Merged
Distributive schemas #1086
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fc595e3
prototype
frenchy64 7c676d6
orn or
frenchy64 445f90d
and
frenchy64 215ab13
-and
frenchy64 9825891
wip
frenchy64 4c748b1
wip
frenchy64 d5d0ffa
doc
frenchy64 81c15db
installer
frenchy64 30ba149
Merge branch 'master' into distributive
frenchy64 c8f8f45
proxy support
frenchy64 dd45607
simplify to just multi, add problematic registry test
frenchy64 f95197c
wip
frenchy64 c3e79ed
tests
frenchy64 0c928f0
doc
frenchy64 2e752c0
doc
frenchy64 04c3608
parse test
frenchy64 9a26480
gen
frenchy64 f44e93c
Merge branch 'master' into distributive
ikitommi 6f7c723
style
ikitommi be2c2be
-children returns always vector of 3
ikitommi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 @@ | ||
#!/bin/bash | ||
|
||
set -xe | ||
|
||
clojure -M:jar && clojure -M:install |
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,165 @@ | ||
(ns malli.distributive-test | ||
(:require [clojure.test :refer [are deftest is testing]] | ||
[malli.core :as m] | ||
[malli.impl.util :as miu] | ||
[malli.generator :as mg] | ||
[malli.registry :as mr] | ||
[malli.transform :as mt] | ||
[malli.util :as mu])) | ||
|
||
(def options {:registry (merge (mu/schemas) (m/default-schemas))}) | ||
|
||
(defn dist [s] | ||
(m/form (m/deref s options))) | ||
|
||
(defn valid? [?schema value] (m/validate ?schema value options)) | ||
|
||
(deftest distributive-multi-test | ||
(is (= (dist | ||
[:merge | ||
[:map [:x :int]] | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:map [:x :int] [:y [:= 1]]]] | ||
[2 [:map [:x :int] [:y [:= 2]]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:map [:x :int]] | ||
[:schema | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:map [:x :int] [:y [:= 1]]]] | ||
[2 [:map [:x :int] [:y [:= 2]]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:map [:x :int]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]] [:x :int]]] | ||
[2 [:map [:y [:= 2]] [:x :int]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:map [:x :int]] | ||
[:map [:z :int]]]) | ||
(dist | ||
[:merge | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:map [:x :int]]] | ||
[:map [:z :int]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]] [:x :int] [:z :int]]] | ||
[2 [:map [:y [:= 2]] [:x :int] [:z :int]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:map [:x :int]] | ||
[:map [:z :int]] | ||
[:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]]]] | ||
[4 [:map [:y [:= 4]]]]]]) | ||
(dist | ||
[:merge | ||
[:merge | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:map [:x :int]]] | ||
[:map [:z :int]]] | ||
[:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]]]] | ||
[4 [:map [:y [:= 4]]]]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]] [:x :int] [:z :int]]] | ||
[4 [:map [:y [:= 4]] [:x :int] [:z :int]]]]] | ||
[2 [:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]] [:x :int] [:z :int]]] | ||
[4 [:map [:y [:= 4]] [:x :int] [:z :int]]]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:map [:x :int]] | ||
[:map [:z :int]] | ||
[:multi {:dispatch :a} | ||
[3 [:map [:a [:= 3]]]] | ||
[4 [:map [:a [:= 4]]]]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:multi {:dispatch :a} | ||
[3 [:map [:y [:= 1]] [:x :int] [:z :int] [:a [:= 3]]]] | ||
[4 [:map [:y [:= 1]] [:x :int] [:z :int] [:a [:= 4]]]]]] | ||
[2 [:multi {:dispatch :a} | ||
[3 [:map [:y [:= 2]] [:x :int] [:z :int] [:a [:= 3]]]] | ||
[4 [:map [:y [:= 2]] [:x :int] [:z :int] [:a [:= 4]]]]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]]]] | ||
[4 [:map [:y [:= 4]]]]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]]]] | ||
[4 [:map [:y [:= 4]]]]]] | ||
[2 [:multi {:dispatch :y} | ||
[3 [:map [:y [:= 3]]]] | ||
[4 [:map [:y [:= 4]]]]]]])) | ||
(is (= (dist | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:multi {:dispatch :z} | ||
[3 [:map [:z [:= 3]]]] | ||
[4 [:map [:z [:= 4]]]]]]) | ||
[:multi {:dispatch :y} | ||
[1 [:multi {:dispatch :z} | ||
[3 [:map [:y [:= 1]] [:z [:= 3]]]] | ||
[4 [:map [:y [:= 1]] [:z [:= 4]]]]]] | ||
[2 [:multi {:dispatch :z} | ||
[3 [:map [:y [:= 2]] [:z [:= 3]]]] | ||
[4 [:map [:y [:= 2]] [:z [:= 4]]]]]]]))) | ||
|
||
(deftest parse-distributive-multi-test | ||
(is (= [1 [3 {:y 1, :z 3}]] | ||
(m/parse | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:multi {:dispatch :z} | ||
[3 [:map [:z [:= 3]]]] | ||
[4 [:map [:z [:= 4]]]]]] | ||
{:y 1 :z 3} | ||
options)))) | ||
|
||
(deftest gen-distributive-multi-test | ||
(is (= [{:y 1, :z 3} {:y 2, :z 4} {:y 2, :z 3} {:y 2, :z 3} {:y 1, :z 4} | ||
{:y 1, :z 3} {:y 1, :z 3} {:y 1, :z 3} {:y 1, :z 3} {:y 2, :z 4}] | ||
(mg/sample | ||
[:merge | ||
[:multi {:dispatch :y} | ||
[1 [:map [:y [:= 1]]]] | ||
[2 [:map [:y [:= 2]]]]] | ||
[:multi {:dispatch :z} | ||
[3 [:map [:z [:= 3]]]] | ||
[4 [:map [:z [:= 4]]]]]] | ||
(assoc options :seed 0))))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO.