2018-08-27 10:25:00 -04:00
|
|
|
require_relative '../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-08-27 10:25:00 -04:00
|
|
|
describe 'The -K command line option' do
|
|
|
|
before :each do
|
|
|
|
@test_string = "print [__ENCODING__&.name, Encoding.default_external&.name, Encoding.default_internal&.name].inspect"
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-08-27 10:25:00 -04:00
|
|
|
describe 'sets __ENCODING__ and Encoding.default_external' do
|
2019-06-27 15:02:36 -04:00
|
|
|
it "to Encoding::BINARY with -Ka" do
|
2018-08-27 10:25:00 -04:00
|
|
|
ruby_exe(@test_string, options: '-Ka').should ==
|
2019-06-27 15:02:36 -04:00
|
|
|
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
2018-08-27 10:25:00 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-06-27 15:02:36 -04:00
|
|
|
it "to Encoding::BINARY with -KA" do
|
2018-08-27 10:25:00 -04:00
|
|
|
ruby_exe(@test_string, options: '-KA').should ==
|
2019-06-27 15:02:36 -04:00
|
|
|
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
2018-08-27 10:25:00 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-06-27 15:02:36 -04:00
|
|
|
it "to Encoding::BINARY with -Kn" do
|
2018-08-27 10:25:00 -04:00
|
|
|
ruby_exe(@test_string, options: '-Kn').should ==
|
2019-06-27 15:02:36 -04:00
|
|
|
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
2018-08-27 10:25:00 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-06-27 15:02:36 -04:00
|
|
|
it "to Encoding::BINARY with -KN" do
|
2018-08-27 10:25:00 -04:00
|
|
|
ruby_exe(@test_string, options: '-KN').should ==
|
2019-06-27 15:02:36 -04:00
|
|
|
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
2018-08-27 10:25:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "to Encoding::EUC_JP with -Ke" do
|
|
|
|
ruby_exe(@test_string, options: '-Ke').should ==
|
|
|
|
[Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
it "to Encoding::EUC_JP with -KE" do
|
|
|
|
ruby_exe(@test_string, options: '-KE').should ==
|
|
|
|
[Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
it "to Encoding::UTF_8 with -Ku" do
|
|
|
|
ruby_exe(@test_string, options: '-Ku').should ==
|
|
|
|
[Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
it "to Encoding::UTF_8 with -KU" do
|
|
|
|
ruby_exe(@test_string, options: '-KU').should ==
|
|
|
|
[Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
it "to Encoding::Windows_31J with -Ks" do
|
|
|
|
ruby_exe(@test_string, options: '-Ks').should ==
|
|
|
|
[Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-08-27 10:25:00 -04:00
|
|
|
it "to Encoding::Windows_31J with -KS" do
|
|
|
|
ruby_exe(@test_string, options: '-KS').should ==
|
|
|
|
[Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-08-27 12:22:21 -04:00
|
|
|
it "ignores unknown codes" do
|
|
|
|
locale = Encoding.find('locale')
|
|
|
|
ruby_exe(@test_string, options: '-KZ').should ==
|
|
|
|
[Encoding::UTF_8.name, locale.name, nil].inspect
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|