diff options
author | Marius Kintel <marius@kintel.net> | 2013-04-24 13:17:25 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-04-26 21:45:03 (GMT) |
commit | 9b740b558dd627412e01a3521d5372d95e294af2 (patch) | |
tree | f34ebfa719303629e27d5fe84c177b5ac38adfbe /testdata | |
parent | 9a297ecee57549a4eb3919bde4f7b41a548724de (diff) |
Further refactoring of scope/context mechanisms. Mostly related to the new FileContext class. Not quite there yet, but almost
Diffstat (limited to 'testdata')
-rw-r--r-- | testdata/scad/features/child-tests.scad | 7 | ||||
-rw-r--r-- | testdata/scad/misc/variable-scope-sub.scad | 24 | ||||
-rw-r--r-- | testdata/scad/misc/variable-scope-tests.scad | 53 |
3 files changed, 82 insertions, 2 deletions
diff --git a/testdata/scad/features/child-tests.scad b/testdata/scad/features/child-tests.scad index e4e3572..cf983b4 100644 --- a/testdata/scad/features/child-tests.scad +++ b/testdata/scad/features/child-tests.scad @@ -1,7 +1,7 @@ $fn=16; -module parent() { - for (i=[0:2]) { +module parent(range=[0:2]) { + for (i=range) { translate([2.5*i,0,0]) child(i); } } @@ -32,3 +32,6 @@ module parent3() { } translate([5,3,0]) parent3() { cube(); sphere(); } + +// Leaking variables to child list is not allowed +translate([0,6,0]) parent(range=[0:1], testvar=10) { sphere(); cube(testvar, center=true);} diff --git a/testdata/scad/misc/variable-scope-sub.scad b/testdata/scad/misc/variable-scope-sub.scad new file mode 100644 index 0000000..fda9520 --- /dev/null +++ b/testdata/scad/misc/variable-scope-sub.scad @@ -0,0 +1,24 @@ +sub_global = 15; + +module submodule() { + echo($children); + echo(submodule_var); + submodule_var = 16; + module subsubmodule() { + echo($children); + subsubmodule_var = 17; + echo(subsubmodule_var); + child(0); + } + subsubmodule() {child(0); sphere();} +} + +module submodule2() { + echo(sub_global); + echo($children); +} + +module submain() { + echo(global_var); // Undefined global var + submodule() {submodule2() sphere(); cube();} +} diff --git a/testdata/scad/misc/variable-scope-tests.scad b/testdata/scad/misc/variable-scope-tests.scad new file mode 100644 index 0000000..8426fbb --- /dev/null +++ b/testdata/scad/misc/variable-scope-tests.scad @@ -0,0 +1,53 @@ +echo("special variable inheritance"); +module special_module(a) { + echo(a, $fn); + special_module2(a); +} + +module special_module2(b) { + echo(a); + echo(b, $fn); +} + +special_module(23, $fn=5); + +echo("inner variables shadows parameter"); +module inner_variables(a, b) { + b = 24; + echo(a, b); +} + +inner_variables(5, 6); + +echo("user-defined special variables as parameter"); +module user_defined_special($b) { + echo($b); + user_defined_special2(); +} + +module user_defined_special2() { + echo($b); +} + +user_defined_special(7); + +echo("assign only visible in children's scope"); +module assigning() { + echo(c); +} + +module assigning2(c) { + echo(c); +} + +assign(c=5) { + assigning(); + assigning2(c); +} + +echo("undeclared variable can still be passed and used"); +module undeclared_var() { + echo(d); +} + +undeclared_var(d=6); |