Skip to content

Commit

Permalink
Fix errors when default external encoding is not UTF-8
Browse files Browse the repository at this point in the history
This fixes 6 test errors/failures when the default external encoding
was set to US-ASCII instead of UTF-8.
  • Loading branch information
jeremyevans authored and judofyr committed Aug 4, 2022
1 parent 0de713d commit e0adbac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/tilt_erbtemplate_test.rb
Expand Up @@ -56,7 +56,7 @@ class MockOutputVariableScope
end

test "backtrace file and line reporting without locals" do
data = File.read(__FILE__).split("\n__END__\n").last
data = File.read(__FILE__, :encoding=>'UTF-8').split("\n__END__\n").last
fail unless data[0] == ?<
template = Tilt::ERBTemplate.new('test.erb', 11) { data }
begin
Expand All @@ -72,7 +72,7 @@ class MockOutputVariableScope
end

test "backtrace file and line reporting with locals" do
data = File.read(__FILE__).split("\n__END__\n").last
data = File.read(__FILE__, :encoding=>'UTF-8').split("\n__END__\n").last
fail unless data[0] == ?<
template = Tilt::ERBTemplate.new('test.erb', 1) { data }
begin
Expand Down Expand Up @@ -158,7 +158,7 @@ class Scope
end

test "backtrace file and line reporting without locals" do
data = File.read(__FILE__).split("\n__END__\n").last
data = File.read(__FILE__, encoding: 'UTF-8').split("\n__END__\n").last
fail unless data[0] == ?<
template = Tilt::ERBTemplate.new('test.erb', 11) { data }
begin
Expand All @@ -174,7 +174,7 @@ class Scope
end

test "backtrace file and line reporting with locals" do
data = File.read(__FILE__).split("\n__END__\n").last
data = File.read(__FILE__, encoding: 'UTF-8').split("\n__END__\n").last
fail unless data[0] == ?<
template = Tilt::ERBTemplate.new('test.erb') { data }
begin
Expand Down
2 changes: 2 additions & 0 deletions test/tilt_template_test.rb
Expand Up @@ -306,6 +306,7 @@ def default_encoding
end

test "uses the template from the generated source code" do
Encoding.default_external = 'UTF-8'
tmpl = "ふが"
code = tmpl.inspect.encode('Shift_JIS')
inst = DynamicMockTemplate.new(:code => code) { '' }
Expand All @@ -315,6 +316,7 @@ def default_encoding
end

test "uses the magic comment from the generated source code" do
Encoding.default_external = 'UTF-8'
tmpl = "ふが"
code = ("# coding: Shift_JIS\n" + tmpl.inspect).encode('Shift_JIS')
# Set it to an incorrect encoding
Expand Down

0 comments on commit e0adbac

Please sign in to comment.