Skip to content

Commit

Permalink
Add to_ruby support for c and e operands
Browse files Browse the repository at this point in the history
We don't actually support "compact decimal" format numbers.
To do so would require refactoring the way we compute the f, t, v, and w values.

Since `c`/`e` are always 0 for non-"compact decimal" format numbers, we just hardcode it to 0 for now.
  • Loading branch information
movermeyer committed Apr 21, 2022
1 parent f872ce5 commit 53127de
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/export/data/plurals_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def test_compiles_n_list_range2
assert_equal("((n.to_f % 100) != 100 || (((n.to_f % 100) % 1).zero? && (!(10..19).include?(n.to_f % 100) || !(90..99).include?(n.to_f % 100))))", Cldr::Export::Data::Plurals::Rule.parse("n % 100 != 10..19,90..99,100").to_ruby)
end

def test_compiles_e_operand_as_always_0
assert_equal("((e = 0) == 0 || !(0..5).include?(e = 0))", Cldr::Export::Data::Plurals::Rule.parse("e = 0 or e != 0..5").to_ruby)
end

def test_eval_n_in
n = 3.3
assert_equal(false, eval(Cldr::Export::Data::Plurals::Rule.parse("n mod 100 in 3..6").to_ruby, binding)) # rubocop:disable Security/Eval
Expand Down Expand Up @@ -255,4 +259,17 @@ def test_n_mod
assert_equal(:other, fn.call("0.220"))
assert_equal(:other, fn.call("41.0"))
end

def test_e_operand
# one: i = 0,1 @integer 0, 1 @decimal 0.0~1.5
# many: e = 0 and i != 0 and i % 1000000 = 0 and v = 0 or e != 0..5 @integer 1000000, 1c6, 2c6, 3c6, 4c6, 5c6, 6c6, … @decimal 1.0000001c6, 1.1c6, 2.0000001c6, 2.1c6, 3.0000001c6, 3.1c6, …
# other: @integer 2~17, 100, 1000, 10000, 100000, 1c3, 2c3, 3c3, 4c3, 5c3, 6c3, … @decimal 2.0~3.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 1.0001c3, 1.1c3, 2.0001c3, 2.1c3, 3.0001c3, 3.1c3, …
fn = eval(cldr_rules.rule(:fr).to_ruby)
assert_equal(:one, fn.call(0))
assert_equal(:one, fn.call(1))
assert_equal(:many, fn.call(1000000))
assert_equal(:many, fn.call(2000000))
assert_equal(:other, fn.call(1000001))
assert_equal(:other, fn.call(1000000.0))
end
end

0 comments on commit 53127de

Please sign in to comment.