From 3340a24634ea505c374b677a3cc9061f4428784e Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 26 Apr 2023 17:39:14 +0100 Subject: [ruby/irb] Add tests for Locale#find and Locale#load (https://github.com/ruby/irb/pull/570) https://github.com/ruby/irb/commit/710d5b1af5 --- test/irb/test_locale.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test') 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 -- cgit v1.2.1