2020-07-22 00:05:21 +00:00
|
|
|
include <../std.scad>
|
|
|
|
include <../structs.scad>
|
2019-11-09 02:31:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
module test_struct_set() {
|
2020-05-30 02:04:34 +00:00
|
|
|
st = struct_set([], "Foo", 42);
|
|
|
|
assert(st == [["Foo",42]]);
|
|
|
|
st2 = struct_set(st, "Bar", 28);
|
|
|
|
assert(st2 == [["Foo",42],["Bar",28]]);
|
|
|
|
st3 = struct_set(st2, "Foo", 91);
|
|
|
|
assert(st3 == [["Foo",91],["Bar",28]]);
|
2019-11-09 02:31:37 +00:00
|
|
|
}
|
|
|
|
test_struct_set();
|
|
|
|
|
|
|
|
|
|
|
|
module test_struct_remove() {
|
2020-05-30 02:04:34 +00:00
|
|
|
st = [["Foo",91],["Bar",28],["Baz",9]];
|
|
|
|
assert(struct_remove(st, "Foo") == [["Bar",28],["Baz",9]]);
|
|
|
|
assert(struct_remove(st, "Bar") == [["Foo",91],["Baz",9]]);
|
|
|
|
assert(struct_remove(st, "Baz") == [["Foo",91],["Bar",28]]);
|
2019-11-09 02:31:37 +00:00
|
|
|
}
|
|
|
|
test_struct_remove();
|
|
|
|
|
|
|
|
|
|
|
|
module test_struct_val() {
|
2020-05-30 02:04:34 +00:00
|
|
|
st = [["Foo",91],["Bar",28],["Baz",9]];
|
|
|
|
assert(struct_val(st,"Foo") == 91);
|
|
|
|
assert(struct_val(st,"Bar") == 28);
|
|
|
|
assert(struct_val(st,"Baz") == 9);
|
2020-11-13 16:19:29 +00:00
|
|
|
assert(struct_val(st,"Baz",5) == 9);
|
|
|
|
assert(struct_val(st,"Qux") == undef);
|
|
|
|
assert(struct_val(st,"Qux",5) == 5);
|
2019-11-09 02:31:37 +00:00
|
|
|
}
|
|
|
|
test_struct_val();
|
|
|
|
|
|
|
|
|
|
|
|
module test_struct_keys() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(struct_keys([["Foo",3],["Bar",2],["Baz",1]]) == ["Foo","Bar","Baz"]);
|
|
|
|
assert(struct_keys([["Zee",1],["Why",2],["Exx",3]]) == ["Zee","Why","Exx"]);
|
2019-11-09 02:31:37 +00:00
|
|
|
}
|
|
|
|
test_struct_keys();
|
|
|
|
|
|
|
|
|
|
|
|
module test_struct_echo() {
|
2020-05-30 02:04:34 +00:00
|
|
|
// Can't yet test echo output
|
2019-11-09 02:31:37 +00:00
|
|
|
}
|
|
|
|
test_struct_echo();
|
|
|
|
|
|
|
|
|
|
|
|
module test_is_struct() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(is_struct([["Foo",1],["Bar",2],["Baz",3]]));
|
|
|
|
assert(!is_struct([["Foo"],["Bar"],["Baz"]]));
|
|
|
|
assert(!is_struct(["Foo","Bar","Baz"]));
|
|
|
|
assert(!is_struct([3,4,5]));
|
|
|
|
assert(!is_struct(3));
|
|
|
|
assert(!is_struct(true));
|
|
|
|
assert(!is_struct("foo"));
|
2019-11-09 02:31:37 +00:00
|
|
|
}
|
|
|
|
test_is_struct();
|
|
|
|
|
|
|
|
|
2020-05-30 02:04:34 +00:00
|
|
|
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|