summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-04-24 14:03:55 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-04-25 14:41:06 +0900
commit9ccf0a066d2f482df96709a865a3d302926399a4 (patch)
tree04c40f820db79cf71243eedca4a1bb0e1f12da25
parented887cbb4c3f9505745bb1110da56690a113afca (diff)
downloadruby-9ccf0a066d2f482df96709a865a3d302926399a4.tar.gz
[ruby/irb] Add tests for Locale class
(https://github.com/ruby/irb/pull/566) https://github.com/ruby/irb/commit/df32e024be
-rw-r--r--test/irb/test_locale.rb83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/irb/test_locale.rb b/test/irb/test_locale.rb
new file mode 100644
index 0000000000..89c43699cb
--- /dev/null
+++ b/test/irb/test_locale.rb
@@ -0,0 +1,83 @@
+require "irb"
+require "stringio"
+
+require_relative "helper"
+
+module TestIRB
+ class LocaleTestCase < TestCase
+ def test_initialize_with_en
+ locale = IRB::Locale.new("en_US.UTF-8")
+
+ assert_equal("en", locale.lang)
+ assert_equal("US", locale.territory)
+ assert_equal("UTF-8", locale.encoding.name)
+ assert_equal(nil, locale.modifier)
+ end
+
+ def test_initialize_with_ja
+ locale = IRB::Locale.new("ja_JP.UTF-8")
+
+ assert_equal("ja", locale.lang)
+ assert_equal("JP", locale.territory)
+ assert_equal("UTF-8", locale.encoding.name)
+ assert_equal(nil, locale.modifier)
+ end
+
+ def test_initialize_with_legacy_ja_encoding_ujis
+ original_stderr = $stderr
+ $stderr = StringIO.new
+
+ locale = IRB::Locale.new("ja_JP.ujis")
+
+ assert_equal("ja", locale.lang)
+ assert_equal("JP", locale.territory)
+ assert_equal("UTF-8", locale.encoding.name)
+ assert_equal(nil, locale.modifier)
+
+ assert_include $stderr.string, "ja_JP.ujis is obsolete. use ja_JP.EUC-JP"
+ ensure
+ $stderr = original_stderr
+ end
+
+ def test_initialize_with_legacy_ja_encoding_euc
+ original_stderr = $stderr
+ $stderr = StringIO.new
+
+ locale = IRB::Locale.new("ja_JP.euc")
+
+ assert_equal("ja", locale.lang)
+ assert_equal("JP", locale.territory)
+ assert_equal("UTF-8", locale.encoding.name)
+ assert_equal(nil, locale.modifier)
+
+ assert_include $stderr.string, "ja_JP.euc is obsolete. use ja_JP.EUC-JP"
+ ensure
+ $stderr = original_stderr
+ end
+
+ %w(IRB_LANG LC_MESSAGES LC_ALL LANG).each do |env_var|
+ define_method "test_initialize_with_#{env_var.downcase}" do
+ original_values = {
+ "IRB_LANG" => ENV["IRB_LANG"],
+ "LC_MESSAGES" => ENV["LC_MESSAGES"],
+ "LC_ALL" => ENV["LC_ALL"],
+ "LANG" => ENV["LANG"],
+ }
+
+ ENV["IRB_LANG"] = ENV["LC_MESSAGES"] = ENV["LC_ALL"] = ENV["LANG"] = nil
+ ENV[env_var] = "zh_TW.UTF-8"
+
+ locale = IRB::Locale.new
+
+ assert_equal("zh", locale.lang)
+ assert_equal("TW", locale.territory)
+ assert_equal("UTF-8", locale.encoding.name)
+ assert_equal(nil, locale.modifier)
+ ensure
+ original_values.each do |key, value|
+ ENV[key] = value
+ end
+ end
+ end
+ end
+end