#!/usr/bin/env ruby # -*- coding: utf-8 -*- require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/test_helper' require 'sass/util/test' class EncodingTest < MiniTest::Test include Sass::Util::Test def test_encoding_error return skip "Can't be run on Ruby 1.8." if Sass::Util.ruby1_8? render("foo\nbar\nb\xFEaz".force_encoding("utf-8")) assert(false, "Expected exception") rescue Sass::SyntaxError => e assert_equal(3, e.sass_line) assert_equal('Invalid UTF-8 character "\xFE"', e.message) end def test_ascii_incompatible_encoding_error return skip "Can't be run on Ruby 1.8." if Sass::Util.ruby1_8? template = "foo\nbar\nb_z".encode("utf-16le") template[9] = "\xFE".force_encoding("utf-16le") render(template) assert(false, "Expected exception") rescue Sass::SyntaxError => e assert_equal(3, e.sass_line) assert_equal('Invalid UTF-16LE character "\xFE"', e.message) end def test_prefers_charset_to_ruby_encoding return skip "Can't be run on Ruby 1.8." if Sass::Util.ruby1_8? assert_renders_encoded(< :compressed)) fóó a: b SASS end def test_newline_normalization assert_equal("/* foo\nbar\nbaz\nbang\nqux */\n", render("/* foo\nbar\r\nbaz\fbang\rqux */", :syntax => :scss)) end def test_null_normalization return skip "Can't be run on Ruby 1.8." if Sass::Util.ruby1_8? assert_equal(< :scss)) #{"@charset \"UTF-8\";\n" unless Sass::Util.ruby1_8? }/* foo�bar�baz */ CSS end # Regression def test_multibyte_prop_name return skip "Can't be run on Ruby 1.8." if Sass::Util.ruby1_8? assert_equal(< :scss)) #bar { background: a 0%; } CSS #bar { //  background: \#{a} 0%; } SCSS end private def assert_renders_encoded(css, sass) result = render(sass) assert_equal css.encoding, result.encoding assert_equal css, result end def render(sass, options = {}) munge_filename options Sass::Engine.new(sass, options).render end end