summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-04-26 17:39:14 +0100
committergit <svn-admin@ruby-lang.org>2023-04-26 16:39:19 +0000
commit3340a24634ea505c374b677a3cc9061f4428784e (patch)
tree6c406ff93cb66277546f85e685656272a8e8089c /test
parentfe0b23b42f6a2c774ad2b45851765625a151f834 (diff)
downloadruby-3340a24634ea505c374b677a3cc9061f4428784e.tar.gz
[ruby/irb] Add tests for Locale#find and Locale#load
(https://github.com/ruby/irb/pull/570) https://github.com/ruby/irb/commit/710d5b1af5
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_locale.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/irb/test_locale.rb b/test/irb/test_locale.rb
index 053cd234b9..37f39acf7d 100644
--- a/test/irb/test_locale.rb
+++ b/test/irb/test_locale.rb
@@ -79,5 +79,40 @@ module TestIRB
end
end
end
+
+ def test_load
+ # reset Locale's internal cache
+ IRB::Locale.class_variable_set(:@@loaded, [])
+ # Because error.rb files define the same class, loading them causes method redefinition warnings.
+ original_verbose = $VERBOSE
+ $VERBOSE = nil
+
+ jp_local = IRB::Locale.new("ja_JP.UTF-8")
+ jp_local.load("irb/error.rb")
+ msg = IRB::CantReturnToNormalMode.new.message
+ assert_equal("Normalモードに戻れません.", msg)
+
+ # reset Locale's internal cache
+ IRB::Locale.class_variable_set(:@@loaded, [])
+
+ en_local = IRB::Locale.new("en_US.UTF-8")
+ en_local.load("irb/error.rb")
+ msg = IRB::CantReturnToNormalMode.new.message
+ assert_equal("Can't return to normal mode.", msg)
+ ensure
+ # before turning warnings back on, load the error.rb file again to avoid warnings in other tests
+ IRB::Locale.new.load("irb/error.rb")
+ $VERBOSE = original_verbose
+ end
+
+ def test_find
+ jp_local = IRB::Locale.new("ja_JP.UTF-8")
+ path = jp_local.find("irb/error.rb").delete_prefix(Dir.pwd)
+ assert_equal("/lib/irb/lc/ja/error.rb", path)
+
+ en_local = IRB::Locale.new("en_US.UTF-8")
+ path = en_local.find("irb/error.rb").delete_prefix(Dir.pwd)
+ assert_equal("/lib/irb/lc/error.rb", path)
+ end
end
end