hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

value.ha (895B)


      1 // License: MPL-2.0
      2 // (c) 2022 Drew DeVault <sir@cmpwn.com>
      3 
      4 @test fn object() void = {
      5 	let obj = newobject();
      6 	defer finish(obj);
      7 
      8 	set(&obj, "hello", "world");
      9 	set(&obj, "foo", "bar");
     10 	set(&obj, "the answer", 42.0);
     11 
     12 	// XXX: Match overhaul?
     13 	assert(*(get(&obj, "hello") as *value) as str == "world");
     14 	assert(*(get(&obj, "foo") as *value) as str == "bar");
     15 	assert(*(get(&obj, "the answer") as *value) as f64 == 42.0);
     16 	assert(get(&obj, "nonexistent") is void);
     17 
     18 	del(&obj, "hello");
     19 	assert(get(&obj, "hello") is void);
     20 };
     21 
     22 @test fn iterator() void = {
     23 	let obj = newobject();
     24 	defer finish(obj);
     25 
     26 	set(&obj, "hello", "world");
     27 	set(&obj, "foo", "bar");
     28 	set(&obj, "the answer", 42.0);
     29 
     30 	let it = iter(&obj);
     31 	assert(next(&it) is (const str, const *value));
     32 	assert(next(&it) is (const str, const *value));
     33 	assert(next(&it) is (const str, const *value));
     34 	assert(next(&it) is void);
     35 };