diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 0ba0ca70..8d576141 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -25,6 +25,9 @@ Several bug fixes and minor improvements have been made, including: * Only displaying the text for the current line when reporting CSS parsing errors. +* Displaying the expected strings as strings rather than regular expressions + whenever possible. + ## [2.2.4](http://github.com/nex3/haml/commit/2.2.4) * Don't add `require 'rubygems'` to the top of init.rb when installed diff --git a/lib/sass/css.rb b/lib/sass/css.rb index b4b14b15..d1a4996e 100644 --- a/lib/sass/css.rb +++ b/lib/sass/css.rb @@ -205,7 +205,8 @@ module Sass after = "..." + after if pos >= 15 # Display basic regexps as plain old strings - expected = re.source == Regexp.escape(re.source) ? "\"#{re.source}\"" : re.inspect + string = re.source.gsub(/\\(.)/, '\1') + expected = re.source == Regexp.escape(string) ? string.inspect : re.inspect was = @template.rest[0...15].gsub(/\n.*/m, '') was += "..." if @template.rest.size >= 15 diff --git a/test/sass/css2sass_test.rb b/test/sass/css2sass_test.rb index ef8571bd..3b14b43a 100644 --- a/test/sass/css2sass_test.rb +++ b/test/sass/css2sass_test.rb @@ -230,12 +230,14 @@ SASS CSS end + # Error reporting + def test_error_reporting css2sass("foo") assert(false, "Expected exception") rescue Sass::SyntaxError => err assert_equal(1, err.sass_line) - assert_equal('Invalid CSS after "foo": expected /\{/, was ""', err.message) + assert_equal('Invalid CSS after "foo": expected "{", was ""', err.message) end def test_error_reporting_in_line @@ -243,7 +245,7 @@ CSS assert(false, "Expected exception") rescue Sass::SyntaxError => err assert_equal(2, err.sass_line) - assert_equal('Invalid CSS after "bar ": expected /\{/, was "}"', err.message) + assert_equal('Invalid CSS after "bar ": expected "{", was "}"', err.message) end def test_error_truncate_after @@ -251,7 +253,7 @@ CSS assert(false, "Expected exception") rescue Sass::SyntaxError => err assert_equal(1, err.sass_line) - assert_equal('Invalid CSS after "...aaaaaaaaaaaafoo": expected /\{/, was ""', err.message) + assert_equal('Invalid CSS after "...aaaaaaaaaaaafoo": expected "{", was ""', err.message) end def test_error_truncate_was @@ -259,7 +261,7 @@ CSS assert(false, "Expected exception") rescue Sass::SyntaxError => err assert_equal(1, err.sass_line) - assert_equal('Invalid CSS after "foo ": expected /\{/, was "}aaaaaaaaaaaaaa..."', err.message) + assert_equal('Invalid CSS after "foo ": expected "{", was "}aaaaaaaaaaaaaa..."', err.message) end private