mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Added regressions and bug fixes for structs.scad
This commit is contained in:
parent
1a0b026da5
commit
a26bb92978
3 changed files with 65 additions and 4 deletions
|
@ -103,6 +103,8 @@ module struct_echo(struct,name="") {
|
||||||
// is_struct(struct)
|
// is_struct(struct)
|
||||||
// Description: Returns true if the input has the form of a structure, false otherwise.
|
// Description: Returns true if the input has the form of a structure, false otherwise.
|
||||||
function is_struct(struct, ind=0) =
|
function is_struct(struct, ind=0) =
|
||||||
struct == [] ||
|
is_list(struct) && (
|
||||||
let(dim = array_dim(struct))
|
struct == [] ||
|
||||||
len(dim)==2 && dim[1]==2;
|
let(dim = array_dim(struct))
|
||||||
|
len(dim)==2 && dim[1]==2
|
||||||
|
);
|
||||||
|
|
59
tests/test_structs.scad
Normal file
59
tests/test_structs.scad
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
include <BOSL2/std.scad>
|
||||||
|
include <BOSL2/structs.scad>
|
||||||
|
|
||||||
|
|
||||||
|
module test_struct_set() {
|
||||||
|
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]]);
|
||||||
|
}
|
||||||
|
test_struct_set();
|
||||||
|
|
||||||
|
|
||||||
|
module test_struct_remove() {
|
||||||
|
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]]);
|
||||||
|
}
|
||||||
|
test_struct_remove();
|
||||||
|
|
||||||
|
|
||||||
|
module test_struct_val() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
test_struct_val();
|
||||||
|
|
||||||
|
|
||||||
|
module test_struct_keys() {
|
||||||
|
assert(struct_keys([["Foo",3],["Bar",2],["Baz",1]]) == ["Foo","Bar","Baz"]);
|
||||||
|
assert(struct_keys([["Zee",1],["Why",2],["Exx",3]]) == ["Zee","Why","Exx"]);
|
||||||
|
}
|
||||||
|
test_struct_keys();
|
||||||
|
|
||||||
|
|
||||||
|
module test_struct_echo() {
|
||||||
|
// Can't yet test echo output
|
||||||
|
}
|
||||||
|
test_struct_echo();
|
||||||
|
|
||||||
|
|
||||||
|
module test_is_struct() {
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
test_is_struct();
|
||||||
|
|
||||||
|
|
||||||
|
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,20];
|
BOSL_VERSION = [2,0,21];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue