|
509 | 509 | (is (true? (m/validate
|
510 | 510 | (mu/update schema :b identity)
|
511 | 511 | {:a 1
|
512 |
| - :c "a string"})))))) |
| 512 | + :c "a string"})))) |
| 513 | + (testing "Multi schema can update its individual dispatch schemas" |
| 514 | + (is (mu/equals (-> (m/schema [:multi {:dispatch :type} |
| 515 | + [:sized [:map |
| 516 | + [:type keyword?] |
| 517 | + [:size int?]]] |
| 518 | + [:human [:map |
| 519 | + [:type keyword?] |
| 520 | + [:name string?] |
| 521 | + [:address [:map [:country keyword?]]]]]]) |
| 522 | + (mu/update :sized mu/select-keys [:size]) |
| 523 | + (mu/update :human mu/select-keys [:name :address])) |
| 524 | + [:multi {:dispatch :type} |
| 525 | + [:sized [:map |
| 526 | + [:size int?]]] |
| 527 | + [:human [:map |
| 528 | + [:name string?] |
| 529 | + [:address [:map [:country keyword?]]]]]]))))) |
513 | 530 |
|
514 | 531 | (deftest assoc-in-test
|
515 | 532 | (is (mu/equals (mu/assoc-in (m/schema [:vector int?]) [0] string?) [:vector string?]))
|
|
523 | 540 | (is (mu/equals (mu/assoc-in (m/schema [:map]) [:a :b :c :d] int?)
|
524 | 541 | [:map [:a [:map [:b [:map [:c [:map [:d int?]]]]]]]]))
|
525 | 542 | (is (mu/equals (mu/assoc-in (m/schema [:ref {:registry {::a int?, ::b string?}} ::a]) [0] ::b) [:ref {:registry {::a int?, ::b string?}} ::b]))
|
526 |
| - (is (mu/equals (mu/assoc-in (m/schema [:schema int?]) [0] string?) [:schema string?]))) |
| 543 | + (is (mu/equals (mu/assoc-in (m/schema [:schema int?]) [0] string?) [:schema string?])) |
| 544 | + |
| 545 | + (testing "Multi schema can use assoc-in to introduce new dispatch schemas" |
| 546 | + (is (mu/equals (-> (m/schema [:multi {:dispatch :type} |
| 547 | + [:sized [:map |
| 548 | + [:type keyword?] |
| 549 | + [:size int?]]] |
| 550 | + [:human [:map |
| 551 | + [:type keyword?] |
| 552 | + [:name string?] |
| 553 | + [:address [:map [:country keyword?]]]]]]) |
| 554 | + (mu/assoc-in [:robot] [:map |
| 555 | + [:type keyword?] |
| 556 | + [:serial-number string?] |
| 557 | + [:charging-station [:map [:id string?]]]])) |
| 558 | + [:multi {:dispatch :type} |
| 559 | + [:sized [:map |
| 560 | + [:type keyword?] |
| 561 | + [:size int?]]] |
| 562 | + [:human [:map |
| 563 | + [:type keyword?] |
| 564 | + [:name string?] |
| 565 | + [:address [:map [:country keyword?]]]]] |
| 566 | + [:robot [:map |
| 567 | + [:type keyword?] |
| 568 | + [:serial-number string?] |
| 569 | + [:charging-station [:map [:id string?]]]]]]))) |
| 570 | + (testing "Multi schema can use assoc-in to extend existing schemas" |
| 571 | + (is (mu/equals (-> (m/schema [:multi {:dispatch :type} |
| 572 | + [:sized [:map |
| 573 | + [:type keyword?] |
| 574 | + [:size int?]]] |
| 575 | + [:human [:map |
| 576 | + [:type keyword?] |
| 577 | + [:name string?] |
| 578 | + [:address [:map [:country keyword?]]]]]]) |
| 579 | + (mu/assoc-in [:sized :unit] string?) |
| 580 | + (mu/assoc-in [:human :address :state] string?)) |
| 581 | + [:multi {:dispatch :type} |
| 582 | + [:sized [:map |
| 583 | + [:type keyword?] |
| 584 | + [:size int?] |
| 585 | + [:unit string?]]] |
| 586 | + [:human [:map |
| 587 | + [:type keyword?] |
| 588 | + [:name string?] |
| 589 | + [:address [:map |
| 590 | + [:country keyword?] |
| 591 | + [:state string?]]]]]])))) |
527 | 592 |
|
528 | 593 | (deftest update-in-test
|
529 | 594 | (is (mu/equals (mu/update-in (m/schema [:vector int?]) [0] (constantly string?)) [:vector string?]))
|
|
0 commit comments