From 68e9c1c11982bcd15a689e1052e2231b492d2874 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 17 Apr 2019 19:34:53 -0500 Subject: [PATCH] FIX: Bug in schema module when testing a tuple against a non tuple shape. --- std/schema.ucg | 2 +- std/tests/schema_test.ucg | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/std/schema.ucg b/std/schema.ucg index 886ecc4..d65d6c5 100644 --- a/std/schema.ucg +++ b/std/schema.ucg @@ -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, }, diff --git a/std/tests/schema_test.ucg b/std/tests/schema_test.ucg index 0b3e9ff..d83ad55 100644 --- a/std/tests/schema_test.ucg +++ b/std/tests/schema_test.ucg @@ -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", +};