From ae44478b30d890fe0fb04022f44d474dcdcc3f9d Mon Sep 17 00:00:00 2001 From: Lassi Pulkkinen Date: Thu, 31 Oct 2024 03:11:21 +0200 Subject: Initial commit (import old repo) --- encoding/json/+test/test_value.ha | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 encoding/json/+test/test_value.ha (limited to 'encoding/json/+test/test_value.ha') diff --git a/encoding/json/+test/test_value.ha b/encoding/json/+test/test_value.ha new file mode 100644 index 0000000..eca7dcf --- /dev/null +++ b/encoding/json/+test/test_value.ha @@ -0,0 +1,49 @@ +// License: MPL-2.0 +// (c) 2022 Drew DeVault + +@test fn object() void = { + let obj = newobject(); + defer finish(obj); + + set(&obj, "hello", "world"); + set(&obj, "foo", "bar"); + set(&obj, "the answer", 42.0); + + // XXX: Match overhaul? + assert(*(get(&obj, "hello") as *value) as str == "world"); + assert(*(get(&obj, "foo") as *value) as str == "bar"); + assert(*(get(&obj, "the answer") as *value) as f64 == 42.0); + assert(get(&obj, "nonexistent") is void); + + del(&obj, "hello"); + assert(get(&obj, "hello") is void); +}; + +@test fn iterator() void = { + let obj = newobject(); + defer finish(obj); + + set(&obj, "hello", "world"); + set(&obj, "foo", "bar"); + set(&obj, "the answer", 42.0); + + let it = iter(&obj); + assert(next(&it) is (const str, const *value)); + assert(next(&it) is (const str, const *value)); + assert(next(&it) is (const str, const *value)); + assert(next(&it) is void); +}; + +@test fn equal() void = { + let a = newobject(); + defer finish(a); + set(&a, "a", 42.0); + set(&a, "A", "hello"); + + let b = newobject(); + defer finish(b); + set(&b, "A", "hello"); + set(&b, "a", 42.0); + + assert(equal(a, b)); +}; -- cgit v1.2.3