From f872ce5c42de5bf17c684c5725e749c1fdb4c8b1 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Wed, 25 Aug 2021 16:29:30 -0400 Subject: [PATCH] Raise if we find an unknown operand Previously, we were assuming that all unknown operands were `n` --- lib/cldr/export/data/plurals/rules.rb | 4 +++- test/export/data/plurals_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cldr/export/data/plurals/rules.rb b/lib/cldr/export/data/plurals/rules.rb index 5f9b62ff..cfd26e09 100644 --- a/lib/cldr/export/data/plurals/rules.rb +++ b/lib/cldr/export/data/plurals/rules.rb @@ -185,9 +185,11 @@ def to_ruby # TODO: https://github.com/ruby-i18n/ruby-cldr/issues/131 op = "#{@type} = 0" enclose = true - else + when "n" fraction = true op = "n.to_f" + else + raise StandardError, "Unknown plural operand `#{@type}`" end if @mod op = "(" << op << ")" if enclose diff --git a/test/export/data/plurals_test.rb b/test/export/data/plurals_test.rb index 3dfd4daf..abcd73cd 100644 --- a/test/export/data/plurals_test.rb +++ b/test/export/data/plurals_test.rb @@ -106,6 +106,13 @@ def test_parses_and_priority assert_equal([:in, [[], [3..4]], "2", "f"], [rule[1][1].operator, rule[1][1].operand, rule[1][1].mod, rule[1][1].type]) end + def test_parse_fails_when_given_unknown_operand + exc = assert_raises do + Cldr::Export::Data::Plurals::Rule.parse("q = 0") + end + assert_equal("can not parse 'q = 0'", exc.message) + end + def test_compiles_empty assert_equal(nil, Cldr::Export::Data::Plurals::Rule.parse("").to_ruby) assert_equal(nil, Cldr::Export::Data::Plurals::Rule.parse(" ").to_ruby)