cldr-plurals 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +2 -6
- data/Rakefile +56 -3
- data/cldr-plurals.gemspec +0 -2
- data/lib/cldr-plurals/compiler/tokenizer.rb +13 -13
- data/lib/cldr-plurals/javascript_emitter.rb +2 -2
- data/lib/cldr-plurals/ruby_emitter.rb +2 -2
- data/lib/cldr-plurals/version.rb +1 -1
- data/spec/javascript_sample_spec.js +13252 -0
- data/spec/ruby_sample_spec.rb +13 -11
- data/spec/samples.rb +59 -0
- data/spec/samples.yml +350 -140
- data/spec/spec_helper.rb +2 -50
- metadata +8 -9
- data/History.txt +0 -16
- data/spec/javascript_sample_spec.rb +0 -48
data/spec/spec_helper.rb
CHANGED
@@ -1,57 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'rspec'
|
4
|
-
require 'pry-
|
4
|
+
require 'pry-byebug'
|
5
5
|
require 'cldr-plurals'
|
6
|
+
require './spec/samples'
|
6
7
|
|
7
8
|
RSpec.configure do |config|
|
8
|
-
config.mock_with :rr
|
9
|
-
end
|
10
|
-
|
11
|
-
ADDITIONAL_SAMPLES = {
|
12
|
-
"ar" => { other: %w(3.1 3.2 3.3) } # improve test coverage for Arabic
|
13
|
-
}
|
14
|
-
|
15
|
-
def each_rule
|
16
|
-
samples.each_pair do |locales, rules|
|
17
|
-
rules.each do |rule|
|
18
|
-
next if rule[:text].empty? # skip other rule test, as it's a fallback
|
19
|
-
tokens = CldrPlurals::Compiler::Tokenizer.tokenize(rule[:text])
|
20
|
-
rule_ast = CldrPlurals::Compiler::Parser.new(tokens).parse
|
21
|
-
yield locales, rule_ast, rule[:samples]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def each_rule_list
|
28
|
-
samples.each_pair do |locales, rules|
|
29
|
-
rule_list = CldrPlurals::Compiler::RuleList.new(locales)
|
30
|
-
samples = {}
|
31
|
-
|
32
|
-
rules.each do |rule|
|
33
|
-
samples[rule[:name]] = rule[:samples]
|
34
|
-
rule_list.add_rule(rule[:name], rule[:text]) unless rule[:text].empty?
|
35
|
-
end
|
36
|
-
|
37
|
-
samples_per_name = samples.each_with_object({}) do |(name, samples), ret|
|
38
|
-
ret[name] = samples.flat_map do |sample_info|
|
39
|
-
sample_info[:samples]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
(ADDITIONAL_SAMPLES[locales] || {}).each do |name, more_samples|
|
44
|
-
samples_per_name[name].concat(more_samples)
|
45
|
-
end
|
46
|
-
|
47
|
-
yield rule_list, samples_per_name
|
48
|
-
end
|
49
|
-
end
|
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
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cldr-plurals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Tokenizes and parses CLDR plural rules and provides a mechanism for emitting
|
14
14
|
them as source code
|
@@ -19,7 +19,6 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- Gemfile
|
22
|
-
- History.txt
|
23
22
|
- LICENSE.txt
|
24
23
|
- README.md
|
25
24
|
- Rakefile
|
@@ -33,14 +32,15 @@ files:
|
|
33
32
|
- lib/cldr-plurals/javascript_emitter.rb
|
34
33
|
- lib/cldr-plurals/ruby_emitter.rb
|
35
34
|
- lib/cldr-plurals/version.rb
|
36
|
-
- spec/javascript_sample_spec.
|
35
|
+
- spec/javascript_sample_spec.js
|
37
36
|
- spec/ruby_sample_spec.rb
|
37
|
+
- spec/samples.rb
|
38
38
|
- spec/samples.yml
|
39
39
|
- spec/spec_helper.rb
|
40
40
|
homepage: http://github.com/camertron
|
41
41
|
licenses: []
|
42
42
|
metadata: {}
|
43
|
-
post_install_message:
|
43
|
+
post_install_message:
|
44
44
|
rdoc_options: []
|
45
45
|
require_paths:
|
46
46
|
- lib
|
@@ -55,9 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
|
-
|
59
|
-
|
60
|
-
signing_key:
|
58
|
+
rubygems_version: 3.1.4
|
59
|
+
signing_key:
|
61
60
|
specification_version: 4
|
62
61
|
summary: Tokenizes and parses CLDR plural rules and provides a mechanism for emitting
|
63
62
|
them as source code
|
data/History.txt
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'v8'
|
4
|
-
require 'yaml'
|
5
|
-
require 'spec_helper'
|
6
|
-
require 'cldr-plurals/javascript_runtime'
|
7
|
-
|
8
|
-
include CldrPlurals
|
9
|
-
include CldrPlurals::Compiler
|
10
|
-
|
11
|
-
describe 'ruby rules' do
|
12
|
-
each_rule do |locales, rule, samples|
|
13
|
-
context = V8::Context.new
|
14
|
-
js_code = JavascriptEmitter.emit_rule_standalone(rule)
|
15
|
-
rule_obj = context.eval(js_code)
|
16
|
-
runtime = context.eval(JavascriptRuntime.source)
|
17
|
-
|
18
|
-
samples.each do |sample_info|
|
19
|
-
context "#{sample_info[:type]} samples" do
|
20
|
-
sample_info[:samples].each do |sample|
|
21
|
-
it sample do
|
22
|
-
args = runtime.buildArgsFor(sample)
|
23
|
-
expect(rule_obj.call(*args)).to eq(true)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'ruby rule lists' do
|
32
|
-
each_rule_list do |rule_list, samples_per_name|
|
33
|
-
context rule_list.locale do
|
34
|
-
context = V8::Context.new
|
35
|
-
js_code = rule_list.to_code(:javascript)
|
36
|
-
rule_proc = context.eval(js_code)
|
37
|
-
runtime = context.eval(JavascriptRuntime.source)
|
38
|
-
|
39
|
-
samples_per_name.each_pair do |name, samples|
|
40
|
-
samples.each do |sample|
|
41
|
-
it "#{name} #{sample}" do
|
42
|
-
expect(rule_proc.call(sample, runtime)).to eq(name.to_s)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|