diff --git a/.gitignore b/.gitignore index e075effc9eb14b66fe9e6ef1ee735ef3e038f999..30c91ca83dd1ca759f229f66a028965b78615e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ module.so propagated_variables linker_options dependencies +testsuite sass.c *.o plib/ diff --git a/Makefile.in b/Makefile.in index 305accdf8d0603c5326d006248b9babef2593f0e..d2a0ea9ec800d52245130a88a6b54548776cb10b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -19,7 +19,7 @@ sass.o : $(SRCDIR)/sass.c LOCAL_GENERATED_FILES=configure config.cache config.h config.log \ config.status config.warnings config.h.in~ make_variables modlist_segment \ propagated_variables remake sass.o module.so module.pmod Makefile \ - dependencies linker_options sass.c + dependencies linker_options sass.c testsuite localdevclean: $(DUMMY) -rm -f $(LOCAL_GENERATED_FILES) diff --git a/testsuite.in b/testsuite.in index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..d1340e24e4dfcee79a0b4920b64ca401beb6ade2 100644 --- a/testsuite.in +++ b/testsuite.in @@ -0,0 +1,150 @@ +START_MARKER + + test_true([[ programp(Tools.Sass.Compiler) ]]) + test_true([[ Tools.Sass.libsass_version() != "" ]]) + + test_do([[ + Tools.Sass.Compiler sassc = Tools.Sass.Compiler(); + sassc->set_options(([ "include_path" : "./", + "output_style" : Tools.Sass.STYLE_COMPRESSED ])); + add_constant("sassc", sassc); + add_constant("sassopt", sassc->set_options); + add_constant("scss_str", #" + $color: #0087cc; + + a { + color: $color + } + "); + ]]) + + dnl *** Should raise errors + + test_eval_error([[ sassopt(([ "include_path" : 1 ])) ]]) + test_eval_error([[ sassopt(([ "output_style" : 1024 ])) ]]) + test_eval_error([[ sassopt(([ "output_style" : "foo" ])) ]]) + test_eval_error([[ sassopt(([ "source_map_file" : 1 ])) ]]) + test_eval_error([[ sassopt(([ "source_map_embed" : "yes" ])) ]]) + test_eval_error([[ sassopt(([ "source_map_root" : 1 ])) ]]) + test_eval_error([[ sassopt(([ "omit_source_map_url" : "y" ])) ]]) + test_eval_error([[ sassopt(([ "source_comments" : "y" ])) ]]) + test_eval_error([[ sassopt(([ "unknown_opt" : "y" ])) ]]) + + dnl *** End: Should raise errors + + test_eq([[ sassc->include_path ]], "./") + + dnl *** Simple compile_string tests + + test_eq([[ sassc->output_style ]], Tools.Sass.STYLE_COMPRESSED) + test_eq([[ sassc->compile_string(scss_str) ]], "a{color:#0087cc}\n") + test_eq([[ sassc->output_style = Tools.Sass.STYLE_COMPACT, + sassc->compile_string(scss_str) ]], "a { color: #0087cc; }\n") + test_eq([[ sassc->output_style = Tools.Sass.STYLE_NESTED, + sassc->compile_string(scss_str) ]], "a {\n" + " color: #0087cc; }\n") + test_eq([[ sassc->output_style = Tools.Sass.STYLE_EXPANDED, + sassc->compile_string(scss_str) ]], "a {\n" + " color: #0087cc;\n" + "}\n") + + dnl *** End: Simple compile_string tests + + dnl *** Create some simple files and write them to disk, and compile them + dnl without writing the CSS and MAP to disk. + test_do([[ + string vars = #" + $color: #fff; + $font: Arial; + + @mixin fun() { + &::before { + color: $color; + } + } + "; + + string style = #" + // Comment + @import 'testvars'; + + html { + font-family: $font; + + body { + @include fun(); + } + } + "; + + Stdio.write_file("_testvars.scss", vars); + Stdio.write_file("teststyle.scss", style); + + mapping(string(8bit):string(8bit)) r = + sassc->compile_file("teststyle.scss"); + + add_constant("scss_comp_file", r); + ]]) + + dnl *** Expected result of the first compile_file test. + define(scss_expected_style_1, + "html {\n" + " font-family: Arial;\n" + "}\n" + "\n" + "html body::before {\n" + " color: #fff;\n" + "}\n") + + test_eq([[ scss_comp_file->map ]], 0) + test_eq([[ scss_comp_file->css ]], scss_expected_style_1) + + define(compile_to_disk, [[ test_do([[ + sassc->source_map_file = "teststyle.css.map"; + sassc->compile_file("teststyle.scss", "teststyle.css"); + + string s = Stdio.read_file("teststyle.css"); + mapping m = Standards.JSON.decode(Stdio.read_file("teststyle.css.map")); + + add_constant("scss_comp_file", s); + add_constant("scss_comp_map", m); + ]]) ]]) + + compile_to_disk() + + define(scss_expected_style_2, scss_expected_style_1 + "\n" + "/*# sourceMappingURL=teststyle.css.map */") + + test_eq([[ scss_comp_file ]], scss_expected_style_2) + test_eq([[ scss_comp_map->file ]], "teststyle.css") + test_equal([[ scss_comp_map->sources ]], ({ "teststyle.scss","_testvars.scss" })) + test_eq([[ scss_comp_map->mappings ]], + [[ "AAIM,AAAA,IAAI,CAAC;EACH,WAAW,ECHL,KAAK;CDQZ;;AAND,AAGE,IAHE," + "CAGF,IAAI,ACFH,QAAQ,CAAC;EACR,KAAK,EALD,IAAI;CAMT" ]]) + + + test_do([[ sassc->source_comments = true; ]]) + + compile_to_disk(); + + test_true([[ sscanf(scss_comp_file, "%*s/* line %*d, %*s.scss */") == 3 ]]) + + dnl *** Clean up + + test_do([[ + rm("_testvars.scss"); + rm("teststyle.scss"); + rm("teststyle.css"); + rm("teststyle.css.map"); + add_constant("scss_comp_file"); + add_constant("scss_comp_map"); + add_constant("scss_str"); + add_constant("sassopt"); + destruct(sassc); + add_constant("sassc"); + ]]) + + dnl *** End clean up + +END_MARKER