From aca633e1ac929b24a72686c527cae3c1168a41eb Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 5 Mar 2024 10:57:55 +0200 Subject: [PATCH] Implement `Fallbacks#inspect` and `Fallbacks#empty?` --- lib/i18n/locale/fallbacks.rb | 8 ++++++++ test/locale/fallbacks_test.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/i18n/locale/fallbacks.rb b/lib/i18n/locale/fallbacks.rb index e30acc43..14744683 100644 --- a/lib/i18n/locale/fallbacks.rb +++ b/lib/i18n/locale/fallbacks.rb @@ -79,6 +79,14 @@ def map(*args, &block) end end + def empty? + @map.empty? && @defaults.empty? + end + + def inspect + "#<#{self.class.name} @map=#{@map.inspect} @defaults=#{@defaults.inspect}>" + end + protected def compute(tags, include_defaults = true, exclude = []) diff --git a/test/locale/fallbacks_test.rb b/test/locale/fallbacks_test.rb index 1500da62..c7218f38 100644 --- a/test/locale/fallbacks_test.rb +++ b/test/locale/fallbacks_test.rb @@ -170,4 +170,15 @@ def setup result = @fallbacks.map { |key, value| [key, value] } assert_equal([[:"de-AT", [:"de-DE"]]], result) end + + test "empty? is compatible with Hash#empty?" do + refute_predicate(@fallbacks, :empty?) + refute_predicate(Fallbacks.new(:'en-US'), :empty?) + refute_predicate(Fallbacks.new(:"de-AT" => :"de-DE"), :empty?) + assert_predicate(Fallbacks.new, :empty?) + end + + test "#inspect" do + assert_equal('#[:"de-DE"]} @defaults=[:"en-US", :en]>', @fallbacks.inspect) + end end