cldr-plurals 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,17 +7,19 @@ require 'cldr-plurals/ruby_runtime'
7
7
  include CldrPlurals
8
8
  include CldrPlurals::Compiler
9
9
 
10
- describe 'ruby rules' do
11
- each_rule do |locales, rule, samples|
12
- ruby_code = RubyEmitter.emit_rule_standalone(rule)
13
- rule_proc = eval(ruby_code)
10
+ describe 'ruby rules;' do
11
+ Samples.each_rule do |locales, rule, samples|
12
+ context "locales: #{locales}, rule: #{rule.name};" do
13
+ ruby_code = RubyEmitter.emit_rule_standalone(rule)
14
+ rule_proc = eval(ruby_code)
14
15
 
15
- samples.each do |sample_info|
16
- context "#{sample_info[:type]} samples" do
17
- sample_info[:samples].each do |sample|
18
- it sample do
19
- args = RubyRuntime.build_args_for(sample)
20
- expect(rule_proc.call(*args)).to eq(true)
16
+ samples.each do |sample_info|
17
+ context "#{sample_info[:type]} samples" do
18
+ sample_info[:samples].each do |sample|
19
+ it sample do
20
+ args = RubyRuntime.build_args_for(sample)
21
+ expect(rule_proc.call(*args)).to eq(true)
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -26,7 +28,7 @@ describe 'ruby rules' do
26
28
  end
27
29
 
28
30
  describe 'ruby rule lists' do
29
- each_rule_list do |rule_list, samples_per_name|
31
+ Samples.each_rule_list do |rule_list, samples_per_name|
30
32
  context rule_list.locale do
31
33
  ruby_code = rule_list.to_code(:ruby)
32
34
  rule_proc = eval(ruby_code)
@@ -0,0 +1,59 @@
1
+ require 'yaml'
2
+
3
+ class Samples
4
+ ADDITIONAL_SAMPLES = {
5
+ "ar" => { other: %w(3.1 3.2 3.3) } # improve test coverage for Arabic
6
+ }
7
+
8
+ class << self
9
+ def each_rule
10
+ return to_enum(__method__) unless block_given?
11
+
12
+ samples.each_pair do |locales, rules|
13
+ rules.each do |rule|
14
+ next if rule[:text].empty? # skip other rule test, as it's a fallback
15
+ tokens = CldrPlurals::Compiler::Tokenizer.tokenize(rule[:text])
16
+ rule_ast = CldrPlurals::Compiler::Parser.new(tokens).parse
17
+ rule_ast.name = rule[:name]
18
+ yield locales, rule_ast, rule[:samples]
19
+ end
20
+ end
21
+ end
22
+
23
+ def each_rule_list
24
+ return to_enum(__method__) unless block_given?
25
+
26
+ samples.each_pair do |locales, rules|
27
+ rule_list = CldrPlurals::Compiler::RuleList.new(locales)
28
+ samples = {}
29
+
30
+ rules.each do |rule|
31
+ samples[rule[:name]] = rule[:samples]
32
+ rule_list.add_rule(rule[:name], rule[:text]) unless rule[:text].empty?
33
+ end
34
+
35
+ samples_per_name = samples.each_with_object({}) do |(name, samples), ret|
36
+ ret[name] = samples.flat_map do |sample_info|
37
+ sample_info[:samples]
38
+ end
39
+ end
40
+
41
+ (ADDITIONAL_SAMPLES[locales] || {}).each do |name, more_samples|
42
+ samples_per_name[name].concat(more_samples)
43
+ end
44
+
45
+ yield rule_list, samples_per_name
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def samples
52
+ YAML.load_file(samples_file)
53
+ end
54
+
55
+ def samples_file
56
+ File.join(File.expand_path(File.dirname(__FILE__)), 'samples.yml')
57
+ end
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  ---
2
- bm/bo/dz/id/ig/ii/in/ja/jbo/jv/jw/kde/kea/km/ko/lkt/lo/ms/my/nqo/root/sah/ses/sg/th/to/vi/wo/yo/zh:
2
+ bm/bo/dz/id/ig/ii/in/ja/jbo/jv/jw/kde/kea/km/ko/lkt/lo/ms/my/nqo/osa/root/sah/ses/sg/su/th/to/vi/wo/yo/yue/zh:
3
3
  - :text: ''
4
4
  :name: :other
5
5
  :samples:
@@ -50,7 +50,7 @@ bm/bo/dz/id/ig/ii/in/ja/jbo/jv/jw/kde/kea/km/ko/lkt/lo/ms/my/nqo/root/sah/ses/sg
50
50
  - '10000.0'
51
51
  - '100000.0'
52
52
  - '1000000.0'
53
- am/as/bn/fa/gu/hi/kn/mr/zu:
53
+ am/as/bn/doi/fa/gu/hi/kn/pcm/zu:
54
54
  - :text: i = 0 or n = 1
55
55
  :name: :one
56
56
  :samples:
@@ -126,7 +126,7 @@ am/as/bn/fa/gu/hi/kn/mr/zu:
126
126
  - '10000.0'
127
127
  - '100000.0'
128
128
  - '1000000.0'
129
- ff/fr/hy/kab:
129
+ ff/hy/kab:
130
130
  - :text: i = 0,1
131
131
  :name: :one
132
132
  :samples:
@@ -202,7 +202,83 @@ ff/fr/hy/kab:
202
202
  - '10000.0'
203
203
  - '100000.0'
204
204
  - '1000000.0'
205
- ast/ca/de/en/et/fi/fy/gl/it/ji/nl/sv/sw/ur/yi:
205
+ pt:
206
+ - :text: i = 0..1
207
+ :name: :one
208
+ :samples:
209
+ - :type: "@integer"
210
+ :samples:
211
+ - '0'
212
+ - '1'
213
+ - :type: "@decimal"
214
+ :samples:
215
+ - '0.0'
216
+ - '0.1'
217
+ - '0.2'
218
+ - '0.3'
219
+ - '0.4'
220
+ - '0.5'
221
+ - '0.6'
222
+ - '0.7'
223
+ - '0.8'
224
+ - '0.9'
225
+ - '1.0'
226
+ - '1.1'
227
+ - '1.2'
228
+ - '1.3'
229
+ - '1.4'
230
+ - '1.5'
231
+ - :text: ''
232
+ :name: :other
233
+ :samples:
234
+ - :type: "@integer"
235
+ :samples:
236
+ - '2'
237
+ - '3'
238
+ - '4'
239
+ - '5'
240
+ - '6'
241
+ - '7'
242
+ - '8'
243
+ - '9'
244
+ - '10'
245
+ - '11'
246
+ - '12'
247
+ - '13'
248
+ - '14'
249
+ - '15'
250
+ - '16'
251
+ - '17'
252
+ - '100'
253
+ - '1000'
254
+ - '10000'
255
+ - '100000'
256
+ - '1000000'
257
+ - :type: "@decimal"
258
+ :samples:
259
+ - '2.0'
260
+ - '2.1'
261
+ - '2.2'
262
+ - '2.3'
263
+ - '2.4'
264
+ - '2.5'
265
+ - '2.6'
266
+ - '2.7'
267
+ - '2.8'
268
+ - '2.9'
269
+ - '3.0'
270
+ - '3.1'
271
+ - '3.2'
272
+ - '3.3'
273
+ - '3.4'
274
+ - '3.5'
275
+ - '10.0'
276
+ - '100.0'
277
+ - '1000.0'
278
+ - '10000.0'
279
+ - '100000.0'
280
+ - '1000000.0'
281
+ ast/ca/de/en/et/fi/fy/gl/ia/io/it/ji/lij/nl/pt_PT/sc/scn/sv/sw/ur/yi:
206
282
  - :text: i = 1 and v = 0
207
283
  :name: :one
208
284
  :samples:
@@ -331,7 +407,7 @@ si:
331
407
  - '10000.0'
332
408
  - '100000.0'
333
409
  - '1000000.0'
334
- ak/bh/guw/ln/mg/nso/pa/ti/wa:
410
+ ak/bho/guw/ln/mg/nso/pa/ti/wa:
335
411
  - :text: n = 0..1
336
412
  :name: :one
337
413
  :samples:
@@ -488,75 +564,7 @@ tzm:
488
564
  - '10000.0'
489
565
  - '100000.0'
490
566
  - '1000000.0'
491
- pt:
492
- - :text: n = 0..2 and n != 2
493
- :name: :one
494
- :samples:
495
- - :type: "@integer"
496
- :samples:
497
- - '0'
498
- - '1'
499
- - :type: "@decimal"
500
- :samples:
501
- - '0.0'
502
- - '1.0'
503
- - '0.00'
504
- - '1.00'
505
- - '0.000'
506
- - '1.000'
507
- - '0.0000'
508
- - '1.0000'
509
- - :text: ''
510
- :name: :other
511
- :samples:
512
- - :type: "@integer"
513
- :samples:
514
- - '2'
515
- - '3'
516
- - '4'
517
- - '5'
518
- - '6'
519
- - '7'
520
- - '8'
521
- - '9'
522
- - '10'
523
- - '11'
524
- - '12'
525
- - '13'
526
- - '14'
527
- - '15'
528
- - '16'
529
- - '17'
530
- - '100'
531
- - '1000'
532
- - '10000'
533
- - '100000'
534
- - '1000000'
535
- - :type: "@decimal"
536
- :samples:
537
- - '0.1'
538
- - '0.2'
539
- - '0.3'
540
- - '0.4'
541
- - '0.5'
542
- - '0.6'
543
- - '0.7'
544
- - '0.8'
545
- - '0.9'
546
- - '1.1'
547
- - '1.2'
548
- - '1.3'
549
- - '1.4'
550
- - '1.5'
551
- - '1.6'
552
- - '1.7'
553
- - '10.0'
554
- - '100.0'
555
- - '1000.0'
556
- - '10000.0'
557
- - '100000.0'
558
- - '1000000.0'
559
- ? af/asa/az/bem/bez/bg/brx/ce/cgg/chr/ckb/dv/ee/el/eo/es/eu/fo/fur/gsw/ha/haw/hu/jgo/jmc/ka/kaj/kcg/kk/kkj/kl/ks/ksb/ku/ky/lb/lg/mas/mgo/ml/mn/nah/nb/nd/ne/nn/nnh/no/nr/ny/nyn/om/or/os/pap/ps/rm/rof/rwk/saq/sdh/seh/sn/so/sq/ss/ssy/st/syr/ta/te/teo/tig/tk/tn/tr/ts/ug/uz/ve/vo/vun/wae/xh/xog
567
+ ? af/an/asa/az/bem/bez/bg/brx/ce/cgg/chr/ckb/dv/ee/el/eo/es/eu/fo/fur/gsw/ha/haw/hu/jgo/jmc/ka/kaj/kcg/kk/kkj/kl/ks/ksb/ku/ky/lb/lg/mas/mgo/ml/mn/mr/nah/nb/nd/ne/nn/nnh/no/nr/ny/nyn/om/or/os/pap/ps/rm/rof/rwk/saq/sd/sdh/seh/sn/so/sq/ss/ssy/st/syr/ta/te/teo/tig/tk/tn/tr/ts/ug/uz/ve/vo/vun/wae/xh/xog
560
568
  : - :text: n = 1
561
569
  :name: :one
562
570
  :samples:
@@ -619,63 +627,6 @@ pt:
619
627
  - '10000.0'
620
628
  - '100000.0'
621
629
  - '1000000.0'
622
- pt_PT:
623
- - :text: n = 1 and v = 0
624
- :name: :one
625
- :samples:
626
- - :type: "@integer"
627
- :samples:
628
- - '1'
629
- - :text: ''
630
- :name: :other
631
- :samples:
632
- - :type: "@integer"
633
- :samples:
634
- - '0'
635
- - '2'
636
- - '3'
637
- - '4'
638
- - '5'
639
- - '6'
640
- - '7'
641
- - '8'
642
- - '9'
643
- - '10'
644
- - '11'
645
- - '12'
646
- - '13'
647
- - '14'
648
- - '15'
649
- - '16'
650
- - '100'
651
- - '1000'
652
- - '10000'
653
- - '100000'
654
- - '1000000'
655
- - :type: "@decimal"
656
- :samples:
657
- - '0.0'
658
- - '0.1'
659
- - '0.2'
660
- - '0.3'
661
- - '0.4'
662
- - '0.5'
663
- - '0.6'
664
- - '0.7'
665
- - '0.8'
666
- - '0.9'
667
- - '1.0'
668
- - '1.1'
669
- - '1.2'
670
- - '1.3'
671
- - '1.4'
672
- - '1.5'
673
- - '10.0'
674
- - '100.0'
675
- - '1000.0'
676
- - '10000.0'
677
- - '100000.0'
678
- - '1000000.0'
679
630
  da:
680
631
  - :text: n = 1 or t != 0 and i = 0,1
681
632
  :name: :one
@@ -831,19 +782,19 @@ is:
831
782
  - '100000.0'
832
783
  - '1000000.0'
833
784
  mk:
834
- - :text: v = 0 and i % 10 = 1 or f % 10 = 1
785
+ - :text: v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11
835
786
  :name: :one
836
787
  :samples:
837
788
  - :type: "@integer"
838
789
  :samples:
839
790
  - '1'
840
- - '11'
841
791
  - '21'
842
792
  - '31'
843
793
  - '41'
844
794
  - '51'
845
795
  - '61'
846
796
  - '71'
797
+ - '81'
847
798
  - '101'
848
799
  - '1001'
849
800
  - :type: "@decimal"
@@ -874,12 +825,12 @@ mk:
874
825
  - '8'
875
826
  - '9'
876
827
  - '10'
828
+ - '11'
877
829
  - '12'
878
830
  - '13'
879
831
  - '14'
880
832
  - '15'
881
833
  - '16'
882
- - '17'
883
834
  - '100'
884
835
  - '1000'
885
836
  - '10000'
@@ -909,7 +860,7 @@ mk:
909
860
  - '10000.0'
910
861
  - '100000.0'
911
862
  - '1000000.0'
912
- fil/tl:
863
+ ceb/fil/tl:
913
864
  - :text: v = 0 and i = 1,2,3 or v = 0 and i % 10 != 4,6,9 or v != 0 and f % 10 !=
914
865
  4,6,9
915
866
  :name: :one
@@ -1267,7 +1218,7 @@ ksh:
1267
1218
  - '10000.0'
1268
1219
  - '100000.0'
1269
1220
  - '1000000.0'
1270
- iu/kw/naq/se/sma/smi/smj/smn/sms:
1221
+ iu/naq/sat/se/sma/smi/smj/smn/sms:
1271
1222
  - :text: n = 1
1272
1223
  :name: :one
1273
1224
  :samples:
@@ -1457,7 +1408,7 @@ mo/ro:
1457
1408
  - :type: "@integer"
1458
1409
  :samples:
1459
1410
  - '1'
1460
- - :text: v != 0 or n = 0 or n != 1 and n % 100 = 1..19
1411
+ - :text: v != 0 or n = 0 or n % 100 = 2..19
1461
1412
  :name: :few
1462
1413
  :samples:
1463
1414
  - :type: "@integer"
@@ -1478,8 +1429,8 @@ mo/ro:
1478
1429
  - '14'
1479
1430
  - '15'
1480
1431
  - '16'
1481
- - '101'
1482
- - '1001'
1432
+ - '102'
1433
+ - '1002'
1483
1434
  - :type: "@decimal"
1484
1435
  :samples:
1485
1436
  - '0.0'
@@ -1654,6 +1605,113 @@ bs/hr/sh/sr:
1654
1605
  - '10000.0'
1655
1606
  - '100000.0'
1656
1607
  - '1000000.0'
1608
+ fr:
1609
+ - :text: i = 0,1
1610
+ :name: :one
1611
+ :samples:
1612
+ - :type: "@integer"
1613
+ :samples:
1614
+ - '0'
1615
+ - '1'
1616
+ - :type: "@decimal"
1617
+ :samples:
1618
+ - '0.0'
1619
+ - '0.1'
1620
+ - '0.2'
1621
+ - '0.3'
1622
+ - '0.4'
1623
+ - '0.5'
1624
+ - '0.6'
1625
+ - '0.7'
1626
+ - '0.8'
1627
+ - '0.9'
1628
+ - '1.0'
1629
+ - '1.1'
1630
+ - '1.2'
1631
+ - '1.3'
1632
+ - '1.4'
1633
+ - '1.5'
1634
+ - :text: e = 0 and i != 0 and i % 1000000 = 0 and v = 0 or e != 0..5
1635
+ :name: :many
1636
+ :samples:
1637
+ - :type: "@integer"
1638
+ :samples:
1639
+ - '1000000'
1640
+ - 1e6
1641
+ - 2e6
1642
+ - 3e6
1643
+ - 4e6
1644
+ - 5e6
1645
+ - 6e6
1646
+ - :type: "@decimal"
1647
+ :samples:
1648
+ - 1.0000001e6
1649
+ - 1.1e6
1650
+ - 2.0000001e6
1651
+ - 2.1e6
1652
+ - 3.0000001e6
1653
+ - 3.1e6
1654
+ - :text: ''
1655
+ :name: :other
1656
+ :samples:
1657
+ - :type: "@integer"
1658
+ :samples:
1659
+ - '2'
1660
+ - '3'
1661
+ - '4'
1662
+ - '5'
1663
+ - '6'
1664
+ - '7'
1665
+ - '8'
1666
+ - '9'
1667
+ - '10'
1668
+ - '11'
1669
+ - '12'
1670
+ - '13'
1671
+ - '14'
1672
+ - '15'
1673
+ - '16'
1674
+ - '17'
1675
+ - '100'
1676
+ - '1000'
1677
+ - '10000'
1678
+ - '100000'
1679
+ - 1e3
1680
+ - 2e3
1681
+ - 3e3
1682
+ - 4e3
1683
+ - 5e3
1684
+ - 6e3
1685
+ - :type: "@decimal"
1686
+ :samples:
1687
+ - '2.0'
1688
+ - '2.1'
1689
+ - '2.2'
1690
+ - '2.3'
1691
+ - '2.4'
1692
+ - '2.5'
1693
+ - '2.6'
1694
+ - '2.7'
1695
+ - '2.8'
1696
+ - '2.9'
1697
+ - '3.0'
1698
+ - '3.1'
1699
+ - '3.2'
1700
+ - '3.3'
1701
+ - '3.4'
1702
+ - '3.5'
1703
+ - '10.0'
1704
+ - '100.0'
1705
+ - '1000.0'
1706
+ - '10000.0'
1707
+ - '100000.0'
1708
+ - '1000000.0'
1709
+ - 1.0001e3
1710
+ - 1.1e3
1711
+ - 2.0001e3
1712
+ - 2.1e3
1713
+ - 3.0001e3
1714
+ - 3.1e3
1657
1715
  gd:
1658
1716
  - :text: n = 1,11
1659
1717
  :name: :one
@@ -2828,6 +2886,7 @@ br:
2828
2886
  - '1000000.0'
2829
2887
  - '1000000.00'
2830
2888
  - '1000000.000'
2889
+ - '1000000.0000'
2831
2890
  - :text: ''
2832
2891
  :name: :other
2833
2892
  :samples:
@@ -3103,7 +3162,158 @@ gv:
3103
3162
  - '23'
3104
3163
  - '103'
3105
3164
  - '1003'
3106
- ar:
3165
+ kw:
3166
+ - :text: n = 0
3167
+ :name: :zero
3168
+ :samples:
3169
+ - :type: "@integer"
3170
+ :samples:
3171
+ - '0'
3172
+ - :type: "@decimal"
3173
+ :samples:
3174
+ - '0.0'
3175
+ - '0.00'
3176
+ - '0.000'
3177
+ - '0.0000'
3178
+ - :text: n = 1
3179
+ :name: :one
3180
+ :samples:
3181
+ - :type: "@integer"
3182
+ :samples:
3183
+ - '1'
3184
+ - :type: "@decimal"
3185
+ :samples:
3186
+ - '1.0'
3187
+ - '1.00'
3188
+ - '1.000'
3189
+ - '1.0000'
3190
+ - :text: n % 100 = 2,22,42,62,82 or n % 1000 = 0 and n % 100000 = 1000..20000,40000,60000,80000
3191
+ or n != 0 and n % 1000000 = 100000
3192
+ :name: :two
3193
+ :samples:
3194
+ - :type: "@integer"
3195
+ :samples:
3196
+ - '2'
3197
+ - '22'
3198
+ - '42'
3199
+ - '62'
3200
+ - '82'
3201
+ - '102'
3202
+ - '122'
3203
+ - '142'
3204
+ - '1000'
3205
+ - '10000'
3206
+ - '100000'
3207
+ - :type: "@decimal"
3208
+ :samples:
3209
+ - '2.0'
3210
+ - '22.0'
3211
+ - '42.0'
3212
+ - '62.0'
3213
+ - '82.0'
3214
+ - '102.0'
3215
+ - '122.0'
3216
+ - '142.0'
3217
+ - '1000.0'
3218
+ - '10000.0'
3219
+ - '100000.0'
3220
+ - :text: n % 100 = 3,23,43,63,83
3221
+ :name: :few
3222
+ :samples:
3223
+ - :type: "@integer"
3224
+ :samples:
3225
+ - '3'
3226
+ - '23'
3227
+ - '43'
3228
+ - '63'
3229
+ - '83'
3230
+ - '103'
3231
+ - '123'
3232
+ - '143'
3233
+ - '1003'
3234
+ - :type: "@decimal"
3235
+ :samples:
3236
+ - '3.0'
3237
+ - '23.0'
3238
+ - '43.0'
3239
+ - '63.0'
3240
+ - '83.0'
3241
+ - '103.0'
3242
+ - '123.0'
3243
+ - '143.0'
3244
+ - '1003.0'
3245
+ - :text: n != 1 and n % 100 = 1,21,41,61,81
3246
+ :name: :many
3247
+ :samples:
3248
+ - :type: "@integer"
3249
+ :samples:
3250
+ - '21'
3251
+ - '41'
3252
+ - '61'
3253
+ - '81'
3254
+ - '101'
3255
+ - '121'
3256
+ - '141'
3257
+ - '161'
3258
+ - '1001'
3259
+ - :type: "@decimal"
3260
+ :samples:
3261
+ - '21.0'
3262
+ - '41.0'
3263
+ - '61.0'
3264
+ - '81.0'
3265
+ - '101.0'
3266
+ - '121.0'
3267
+ - '141.0'
3268
+ - '161.0'
3269
+ - '1001.0'
3270
+ - :text: ''
3271
+ :name: :other
3272
+ :samples:
3273
+ - :type: "@integer"
3274
+ :samples:
3275
+ - '4'
3276
+ - '5'
3277
+ - '6'
3278
+ - '7'
3279
+ - '8'
3280
+ - '9'
3281
+ - '10'
3282
+ - '11'
3283
+ - '12'
3284
+ - '13'
3285
+ - '14'
3286
+ - '15'
3287
+ - '16'
3288
+ - '17'
3289
+ - '18'
3290
+ - '19'
3291
+ - '100'
3292
+ - '1004'
3293
+ - '1000000'
3294
+ - :type: "@decimal"
3295
+ :samples:
3296
+ - '0.1'
3297
+ - '0.2'
3298
+ - '0.3'
3299
+ - '0.4'
3300
+ - '0.5'
3301
+ - '0.6'
3302
+ - '0.7'
3303
+ - '0.8'
3304
+ - '0.9'
3305
+ - '1.1'
3306
+ - '1.2'
3307
+ - '1.3'
3308
+ - '1.4'
3309
+ - '1.5'
3310
+ - '1.6'
3311
+ - '1.7'
3312
+ - '10.0'
3313
+ - '100.0'
3314
+ - '1000.1'
3315
+ - '1000000.0'
3316
+ ar/ars:
3107
3317
  - :text: n = 0
3108
3318
  :name: :zero
3109
3319
  :samples: