mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FIX: Any should not do partial matches for the candidate shapes.
This commit is contained in:
parent
05771c7221
commit
643b597e35
@ -26,6 +26,8 @@ let must = func (m, msg) => select m, fail msg, {
|
|||||||
// Any does a boolean match against a set of allowed shapes for a type.
|
// Any does a boolean match against a set of allowed shapes for a type.
|
||||||
// This module uses the shape module below so the same rules for checking
|
// This module uses the shape module below so the same rules for checking
|
||||||
// the types against the source value apply for each example in the list.
|
// the types against the source value apply for each example in the list.
|
||||||
|
//
|
||||||
|
// This module does not do partial matches for the shapes.
|
||||||
let any = module {
|
let any = module {
|
||||||
// The source value to check.
|
// The source value to check.
|
||||||
val=NULL,
|
val=NULL,
|
||||||
@ -35,7 +37,7 @@ let any = module {
|
|||||||
let schema = mod.pkg();
|
let schema = mod.pkg();
|
||||||
|
|
||||||
let reducer = func (acc, t) => acc{
|
let reducer = func (acc, t) => acc{
|
||||||
ok = acc.ok || (schema.shaped{val=acc.val, shape=t}),
|
ok = acc.ok || (schema.shaped{val=acc.val, shape=t, partial=false}),
|
||||||
};
|
};
|
||||||
let any = func (val, types) => reduce(reducer, {ok=false, val=val}, types);
|
let any = func (val, types) => reduce(reducer, {ok=false, val=val}, types);
|
||||||
|
|
||||||
|
@ -135,3 +135,8 @@ assert t.not_ok{
|
|||||||
test = schema.shaped{val={foo="bar"}, shaped=1.0},
|
test = schema.shaped{val={foo="bar"}, shaped=1.0},
|
||||||
desc = "a tuple is not a float",
|
desc = "a tuple is not a float",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assert t.not_ok{
|
||||||
|
test = schema.any{val={foo="bar", quux="baz"}, types=[1.0, {foo="bar", qux="baz"}]},
|
||||||
|
desc = "any doesn't match against missing fields for tuples.",
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user