FIX: Bug in schema module when testing a tuple against a non tuple shape.

This commit is contained in:
Jeremy Wall 2019-04-17 19:34:53 -05:00
parent 0e41a40ab3
commit 68e9c1c119
2 changed files with 16 additions and 1 deletions

View File

@ -86,7 +86,7 @@ let shaped = module {
float = simple_handler(mod.val, mod.shape),
bool = simple_handler(mod.val, mod.shape),
null = simple_handler(mod.val, mod.shape),
tuple = reduce(tuple_handler, {shape=mod.shape, ok=false}, mod.val).ok,
tuple = (mod.shape is "tuple") && reduce(tuple_handler, {shape=mod.shape, ok=false}, mod.val).ok,
list = select mod.shape == [], true, {
false = reduce(list_handler, {shape=mod.shape, ok=false}, mod.val).ok,
},

View File

@ -6,6 +6,16 @@ assert t.ok{
desc = "1 is an int",
};
assert t.not_ok{
test = schema.any{val=1, types=[1.0, {foo="bar"}]},
desc = "1 is not a float or a tuple with a foo string field",
};
assert t.ok{
test = schema.any{val={foo="bar"}, types=[1.0, {foo=""}]},
desc = "1 is not a float or a tuple with a foo string field",
};
assert t.not_ok{
test = schema.any{val=1, types=[1.0, ""]},
desc = "1 is not a float or string",
@ -120,3 +130,8 @@ assert t.ok{
test = schema.shaped{val={list=[1, "foo"]}, shape={list=[]}},
desc="inner list with valid types matches empty list shape",
};
assert t.not_ok{
test = schema.shaped{val={foo="bar"}, shaped=1.0},
desc = "a tuple is not a float",
};