[ruby/irb] Add tests for Locale#find and Locale#load

(https://github.com/ruby/irb/pull/570)

https://github.com/ruby/irb/commit/710d5b1af5
This commit is contained in:
Stan Lo 2023-04-26 17:39:14 +01:00 committed by git
parent fe0b23b42f
commit 3340a24634

View File

@ -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