Skip to content

Commit

Permalink
Raise if we find an unknown operand
Browse files Browse the repository at this point in the history
Previously, we were assuming that all unknown operands were `n`
  • Loading branch information
movermeyer committed Apr 21, 2022
1 parent 24dd7b0 commit f872ce5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cldr/export/data/plurals/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/export/data/plurals_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f872ce5

Please sign in to comment.