FIX: Any should not do partial matches for the candidate shapes.

This commit is contained in:
Jeremy Wall 2019-04-17 21:02:09 -05:00
parent 05771c7221
commit 643b597e35
2 changed files with 8 additions and 1 deletions

View File

@ -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.
// 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.
//
// This module does not do partial matches for the shapes.
let any = module {
// The source value to check.
val=NULL,
@ -35,7 +37,7 @@ let any = module {
let schema = mod.pkg();
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);

View File

@ -135,3 +135,8 @@ assert t.not_ok{
test = schema.shaped{val={foo="bar"}, shaped=1.0},
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.",
};