Skip to content

Commit 3952bdf

Browse files
committed
Merge pull request #599 from mgreter/feature/precision-option
Add tests for precision option
2 parents 8952a13 + f7aa594 commit 3952bdf

20 files changed

+81
-12
lines changed

lib/sass_spec/engine_adapter.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ def version
4343
end
4444

4545

46-
def compile(sass_filename, style)
47-
require 'open3'
48-
stdout, stderr, status = Open3.capture3("#{@command} -t #{style} #{sass_filename}", :binmode => true)
46+
def compile(sass_filename, style, precision)
47+
require 'open3'
48+
cmd = "#{@command} --precision #{precision} -t #{style}"
49+
stdout, stderr, status = Open3.capture3("#{cmd} #{sass_filename}", :binmode => true)
4950
[stdout, stderr, status.exitstatus]
5051
end
5152
end
@@ -64,7 +65,7 @@ def version
6465
Sass::VERSION
6566
end
6667

67-
def compile(sass_filename, style)
68+
def compile(sass_filename, style, precision)
6869
require 'sass'
6970
# overloads STDERR
7071
stderr = StringIO.new
@@ -75,6 +76,7 @@ def compile(sass_filename, style)
7576
old_stderr, $stderr = $stderr, stderr
7677
begin
7778
Encoding.default_external = "UTF-8"
79+
Sass::Script::Value::Number.precision = precision
7880
css_output = Sass.compile_file(sass_filename.to_s, :style => style.to_sym)
7981
# strings come back as utf8 encoded
8082
# internaly we only work with bytes

lib/sass_spec/runner.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ def _get_cases
6666
!File.file?(expected_stdout_file_path.sub(/\.css$/, ".skip")) &&
6767
filename.include?(@options[:filter])
6868
clean = File.file?(clean_file_name)
69-
cases.push SassSpec::TestCase.new(input.realpath(),
69+
cases.push SassSpec::TestCase.new(
70+
input.realpath(),
7071
expected_stdout_file_path,
71-
expected_stderr_file_path,
72-
expected_status_file_path,
73-
output_style, clean,
72+
folder, output_style, clean,
7473
@options[:generate].include?(output_style),
7574
@options)
7675
end

lib/sass_spec/test_case.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
# This represents a specific test case.
22
class SassSpec::TestCase
3-
def initialize(input_scss, expected_css, error_file, status_file, style, clean, gen, options = {})
3+
def initialize(input_scss, expected_css, folder, style, clean, gen, options = {})
44
@input_path = input_scss
55
@expected_path = expected_css
6-
@error_path = error_file
7-
@status_path = status_file
6+
@error_path = File.join(folder, "error")
7+
@status_path = File.join(folder, "status")
8+
@options_path = File.join(folder, "options")
89
@output_style = style
910
@clean_test = clean
1011
@options = options
1112
@generate = gen
13+
@precision = 5
1214

1315
# Probe filesystem once and cache the results
1416
@should_fail = File.file?(@status_path)
1517
@verify_stderr = File.file?(@error_path)
18+
19+
# load options (only precision ATM)
20+
if (File.file?(@options_path))
21+
File.open(@options_path, "r") do |opt|
22+
opt.each_line do |line|
23+
if (line =~ /^precision\s*:\s*(\d+)\s*$/)
24+
@precision = $1.to_i
25+
end
26+
end
27+
end
28+
end
29+
1630
end
1731

1832
def name
1933
@input_path.dirname.to_s.sub(Dir.pwd + "/", "")
2034
end
2135

36+
def precision
37+
@precision
38+
end
39+
2240
def clean_test
2341
@clean_test
2442
end
@@ -64,7 +82,7 @@ def output
6482
return @output
6583
end
6684

67-
stdout, stderr, status = engine.compile(@input_path, @output_style)
85+
stdout, stderr, status = engine.compile(@input_path, @output_style, @precision)
6886

6987
if @clean_test
7088
clean_out = _clean_output(stdout)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test { foo: 0.4999 0; bar: 0.49999 0; baz: 0.5 1; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test{foo:0.4999 0;bar:0.49999 0;baz:0.5 1}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test {
2+
foo: 0.4999 0;
3+
bar: 0.49999 0;
4+
baz: 0.5 1;
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test {
2+
foo: 0.4999 0;
3+
bar: 0.49999 0;
4+
baz: 0.5 1; }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test {
2+
foo: 0.4999 round(0.4999);
3+
bar: 0.49999 round(0.49999);
4+
baz: 0.499999 round(0.499999);
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test { foo: 0.4999 0; bar: 0.49999 0; baz: 0.499999 0; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test{foo:0.4999 0;bar:0.49999 0;baz:0.499999 0}

0 commit comments

Comments
 (0)