3636 {'name' : 'mirror' , 'class' : 'mirror' , 'kwargs' : {}, 'expected' : '\n \n mirror(v = [0, 0, 1]);' , 'args' : {'v' : [0 , 0 , 1 ]}, },
3737 {'name' : 'resize' , 'class' : 'resize' , 'kwargs' : {'newsize' : [5 , 5 , 5 ], 'auto' : [True , True , False ]}, 'expected' : '\n \n resize(auto = [true, true, false], newsize = [5, 5, 5]);' , 'args' : {}, },
3838 {'name' : 'multmatrix' , 'class' : 'multmatrix' , 'kwargs' : {}, 'expected' : '\n \n multmatrix(m = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]);' , 'args' : {'m' : [[1 , 0 , 0 , 0 ], [0 , 1 , 0 , 0 ], [0 , 0 , 1 , 0 ], [0 , 0 , 0 , 1 ]]}, },
39- {'name' : 'color' , 'class' : 'color' , 'kwargs' : {}, 'expected' : '\n \n color(c = [1, 0, 0]);' , 'args' : {'c' : [1 , 0 , 0 ]}, },
4039 {'name' : 'minkowski' , 'class' : 'minkowski' , 'kwargs' : {}, 'expected' : '\n \n minkowski();' , 'args' : {}, },
4140 {'name' : 'offset' , 'class' : 'offset' , 'kwargs' : {'r' : 1 }, 'expected' : '\n \n offset(r = 1);' , 'args' : {}, },
4241 {'name' : 'offset_segments' , 'class' : 'offset' , 'kwargs' : {'r' : 1 , 'segments' : 12 }, 'expected' : '\n \n offset($fn = 12, r = 1);' , 'args' : {}, },
@@ -114,7 +113,7 @@ def test_infix_intersection(self):
114113
115114 def test_parse_scad_callables (self ):
116115 test_str = """
117- module hex (width=10, height=10,
116+ module hex (width=10, height=10,
118117 flats= true, center=false){}
119118 function righty (angle=90) = 1;
120119 function lefty(avar) = 2;
@@ -215,11 +214,11 @@ def test_import_scad(self):
215214 self .assertTrue (hasattr (examples .scad_to_include , 'steps' ))
216215
217216 # TODO: we should test that:
218- # A) scad files in the designated OpenSCAD library directories
219- # (path-dependent, see: solid.objects._openscad_library_paths())
217+ # A) scad files in the designated OpenSCAD library directories
218+ # (path-dependent, see: solid.objects._openscad_library_paths())
220219 # are imported correctly. Not sure how to do this without writing
221220 # temp files to those directories. Seems like overkill for the moment
222-
221+
223222 def test_imported_scad_arguments (self ):
224223 include_file = self .expand_scad_path ("examples/scad_to_include.scad" )
225224 mod = import_scad (include_file )
@@ -229,7 +228,7 @@ def test_imported_scad_arguments(self):
229228 abs_path = points ._get_include_path (include_file )
230229 expected = f'use <{ abs_path } >\n \n \n polygon(points = scad_points());'
231230 self .assertEqual (expected , actual )
232-
231+
233232 def test_use_reserved_words (self ):
234233 scad_str = '''module reserved_word_arg(or=3){\n \t cube(or);\n }\n module or(arg=3){\n \t cube(arg);\n }\n '''
235234
@@ -297,6 +296,25 @@ def test_root(self):
297296 actual = scad_render (root (a ))
298297 self .assertEqual (expected , actual )
299298
299+ def test_color (self ):
300+ all_args = [
301+ {'c' : [1 , 0 , 0 ]},
302+ {'c' : [1 , 0 , 0 ], 'alpha' : 0.5 },
303+ {'c' : "#66F" },
304+ {'c' : "Teal" , 'alpha' : 0.5 },
305+ ]
306+
307+ expecteds = [
308+ '\n \n color(alpha = 1.0000000000, c = [1, 0, 0]);' ,
309+ '\n \n color(alpha = 0.5000000000, c = [1, 0, 0]);' ,
310+ '\n \n color(alpha = 1.0000000000, c = "#66F");' ,
311+ '\n \n color(alpha = 0.5000000000, c = "Teal");' ,
312+ ]
313+ for args , expected in zip (all_args , expecteds ):
314+ col = color (** args )
315+ actual = scad_render (col )
316+ self .assertEqual (expected , actual )
317+
300318 def test_explicit_hole (self ):
301319 a = cube (10 , center = True ) + hole ()(cylinder (2 , 20 , center = True ))
302320 expected = '\n \n difference(){\n \t union() {\n \t \t cube(center = true, size = 10);\n \t }\n \t /* Holes Below*/\n \t union(){\n \t \t cylinder(center = true, h = 20, r = 2);\n \t } /* End Holes */ \n }'
0 commit comments