summaryrefslogtreecommitdiff
path: root/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'testdata')
-rw-r--r--testdata/scad/features/child-tests.scad7
-rw-r--r--testdata/scad/misc/localfiles_dir/localfiles_module.scad3
-rw-r--r--testdata/scad/misc/variable-scope-sub.scad24
-rw-r--r--testdata/scad/misc/variable-scope-tests.scad53
4 files changed, 83 insertions, 4 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/localfiles_dir/localfiles_module.scad b/testdata/scad/misc/localfiles_dir/localfiles_module.scad
index b98a49b..2611e71 100644
--- a/testdata/scad/misc/localfiles_dir/localfiles_module.scad
+++ b/testdata/scad/misc/localfiles_dir/localfiles_module.scad
@@ -5,6 +5,5 @@ module localfiles_module()
translate([0,350,0]) rotate_extrude(file="localfile.dxf");
translate([250,0,0]) scale([200,200,50]) surface("localfile.dat");
- // This is not supported:
- // echo(dxf_dim(file="localfile.dxf", name="localfile"));
+ translate([0,-200,0]) sphere(r=dxf_dim(file="localfile.dxf", name="localfile")/2);
}
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);
contact: Jan Huwald // Impressum