-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #782 from timdiggins/respect-implicit-encoding-of-…
…thorfiles Respect implicit encoding of thorfiles
- Loading branch information
Showing
5 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "helper" | ||
require "thor/base" | ||
|
||
|
||
describe "file's encoding" do | ||
def load_thorfile(filename) | ||
Thor::Util.load_thorfile(File.expand_path("./fixtures/#{filename}", __dir__)) | ||
end | ||
|
||
it "respects explicit UTF-8" do | ||
load_thorfile("encoding_with_utf8.thor") | ||
expect(capture(:stdout) { Thor::Sandbox::EncodingWithUtf8.new.invoke(:encoding) }).to match(/ok/) | ||
end | ||
it "respects explicit non-UTF-8" do | ||
load_thorfile("encoding_other.thor") | ||
expect(capture(:stdout) { Thor::Sandbox::EncodingOther.new.invoke(:encoding) }).to match(/ok/) | ||
end | ||
it "has implicit UTF-8" do | ||
load_thorfile("encoding_implicit.thor") | ||
expect(capture(:stdout) { Thor::Sandbox::EncodingImplicit.new.invoke(:encoding) }).to match(/ok/) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class EncodingImplicit < Thor | ||
SOME_STRING = "Some λέξεις 一些词 🎉" | ||
|
||
desc "encoding", "tests that encoding is correct" | ||
|
||
def encoding | ||
puts "#{SOME_STRING.inspect}: #{SOME_STRING.encoding}:" | ||
if SOME_STRING.encoding.name == "UTF-8" | ||
puts "ok" | ||
else | ||
puts "expected #{SOME_STRING.encoding.name} to equal UTF-8" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# encoding: ISO-8859-7 | ||
# frozen_string_literal: true | ||
|
||
class EncodingOther < Thor | ||
SOME_STRING = "Some ëÝîåéò" | ||
|
||
desc "encoding", "tests that encoding is correct" | ||
|
||
def encoding | ||
puts "#{SOME_STRING.inspect}: #{SOME_STRING.encoding}:" | ||
if SOME_STRING.encoding.name == "ISO-8859-7" | ||
puts "ok" | ||
else | ||
puts "expected #{SOME_STRING.encoding.name} to equal ISO-8859-7" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# encoding: UTF-8 | ||
# frozen_string_literal: true | ||
|
||
class EncodingWithUtf8 < Thor | ||
SOME_STRING = "Some λέξεις 一些词 🎉" | ||
|
||
desc "encoding", "tests that encoding is correct" | ||
|
||
def encoding | ||
puts "#{SOME_STRING.inspect}: #{SOME_STRING.encoding}:" | ||
if SOME_STRING.encoding.name == "UTF-8" | ||
puts "ok" | ||
else | ||
puts "expected #{SOME_STRING.encoding.name} to equal UTF-8" | ||
end | ||
end | ||
end |