File tree Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ require "helper"
2
+ require "thor/base"
3
+
4
+
5
+ describe "file's encoding" do
6
+ def load_thorfile ( filename )
7
+ Thor ::Util . load_thorfile ( File . expand_path ( "./fixtures/#{ filename } " , __dir__ ) )
8
+ end
9
+
10
+ it "respects explicit UTF-8" do
11
+ load_thorfile ( "encoding_with_utf8.thor" )
12
+ expect ( capture ( :stdout ) { Thor ::Sandbox ::EncodingWithUtf8 . new . invoke ( :encoding ) } ) . to match ( /ok/ )
13
+ end
14
+ it "respects explicit non-UTF-8" do
15
+ load_thorfile ( "encoding_other.thor" )
16
+ expect ( capture ( :stdout ) { Thor ::Sandbox ::EncodingOther . new . invoke ( :encoding ) } ) . to match ( /ok/ )
17
+ end
18
+ it "has implicit UTF-8" do
19
+ load_thorfile ( "encoding_implicit.thor" )
20
+ expect ( capture ( :stdout ) { Thor ::Sandbox ::EncodingImplicit . new . invoke ( :encoding ) } ) . to match ( /ok/ )
21
+ end
22
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ class EncodingImplicit < Thor
4
+ SOME_STRING = "Some λέξεις 一些词 🎉"
5
+
6
+ desc "encoding" , "tests that encoding is correct"
7
+
8
+ def encoding
9
+ puts "#{ SOME_STRING . inspect } : #{ SOME_STRING . encoding } :"
10
+ if SOME_STRING . encoding . name == "UTF-8"
11
+ puts "ok"
12
+ else
13
+ puts "expected #{ SOME_STRING . encoding . name } to equal UTF-8"
14
+ end
15
+ end
16
+ end
Original file line number Diff line number Diff line change
1
+ # encoding: ISO-8859-7
2
+ # frozen_string_literal: true
3
+
4
+ class EncodingOther < Thor
5
+ SOME_STRING = "Some ëÝîåéò"
6
+
7
+ desc "encoding" , "tests that encoding is correct"
8
+
9
+ def encoding
10
+ puts "#{ SOME_STRING . inspect } : #{ SOME_STRING . encoding } :"
11
+ if SOME_STRING . encoding . name == "ISO-8859-7"
12
+ puts "ok"
13
+ else
14
+ puts "expected #{ SOME_STRING . encoding . name } to equal ISO-8859-7"
15
+ end
16
+ end
17
+ end
Original file line number Diff line number Diff line change
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ class EncodingWithUtf8 < Thor
5
+ SOME_STRING = "Some λέξεις 一些词 🎉"
6
+
7
+ desc "encoding" , "tests that encoding is correct"
8
+
9
+ def encoding
10
+ puts "#{ SOME_STRING . inspect } : #{ SOME_STRING . encoding } :"
11
+ if SOME_STRING . encoding . name == "UTF-8"
12
+ puts "ok"
13
+ else
14
+ puts "expected #{ SOME_STRING . encoding . name } to equal UTF-8"
15
+ end
16
+ end
17
+ end
You can’t perform that action at this time.
0 commit comments