twitter_cldr 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/History.txt +4 -0
- data/README.md +17 -6
- data/lib/twitter_cldr/resources/postal_codes_importer.rb +12 -1
- data/lib/twitter_cldr/resources/regexp_ast_generator.rb +41 -0
- data/lib/twitter_cldr/resources.rb +1 -0
- data/lib/twitter_cldr/shared/postal_code_generator.rb +50 -0
- data/lib/twitter_cldr/shared/postal_codes.rb +48 -9
- data/lib/twitter_cldr/shared.rb +15 -14
- data/lib/twitter_cldr/utils/regexp_ast.rb +115 -0
- data/lib/twitter_cldr/utils/regexp_sampler.rb +149 -0
- data/lib/twitter_cldr/utils.rb +5 -3
- data/lib/twitter_cldr/version.rb +1 -1
- data/resources/shared/postal_codes.yml +1442 -159
- data/spec/bidi/bidi_spec.rb +1 -1
- data/spec/collation/collation_spec.rb +1 -1
- data/spec/collation/collator_spec.rb +31 -31
- data/spec/collation/implicit_collation_elements_spec.rb +6 -6
- data/spec/collation/sort_key_builder_spec.rb +28 -26
- data/spec/collation/tailoring_spec.rb +1 -1
- data/spec/collation/trie_builder_spec.rb +16 -16
- data/spec/collation/trie_dumps_spec.rb +2 -2
- data/spec/collation/trie_loader_spec.rb +8 -8
- data/spec/collation/trie_spec.rb +61 -61
- data/spec/collation/trie_with_fallback_spec.rb +5 -5
- data/spec/core_ext_spec.rb +1 -1
- data/spec/data_readers/additional_date_format_selector_spec.rb +38 -38
- data/spec/data_readers/date_time_data_reader_spec.rb +2 -2
- data/spec/data_readers/number_data_reader_spec.rb +1 -1
- data/spec/formatters/calendars/datetime_formatter_spec.rb +218 -218
- data/spec/formatters/list_formatter_spec.rb +8 -8
- data/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb +14 -14
- data/spec/formatters/numbers/abbreviated/long_decimal_formatter_spec.rb +4 -4
- data/spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb +4 -4
- data/spec/formatters/numbers/currency_formatter_spec.rb +11 -11
- data/spec/formatters/numbers/decimal_formatter_spec.rb +3 -3
- data/spec/formatters/numbers/helpers/fraction_spec.rb +3 -3
- data/spec/formatters/numbers/helpers/integer_spec.rb +16 -16
- data/spec/formatters/numbers/number_formatter_spec.rb +21 -21
- data/spec/formatters/numbers/percent_formatter_spec.rb +3 -3
- data/spec/formatters/numbers/rbnf/rbnf_spec.rb +2 -2
- data/spec/formatters/plurals/plural_formatter_spec.rb +41 -41
- data/spec/formatters/plurals/rules_spec.rb +13 -13
- data/spec/localized/localized_array_spec.rb +12 -12
- data/spec/localized/localized_date_spec.rb +33 -33
- data/spec/localized/localized_datetime_spec.rb +11 -11
- data/spec/localized/localized_hash_spec.rb +4 -4
- data/spec/localized/localized_number_spec.rb +36 -36
- data/spec/localized/localized_object_spec.rb +8 -8
- data/spec/localized/localized_string_spec.rb +53 -53
- data/spec/localized/localized_symbol_spec.rb +9 -9
- data/spec/localized/localized_time_spec.rb +10 -10
- data/spec/localized/localized_timespan_spec.rb +8 -8
- data/spec/normalization_spec.rb +6 -6
- data/spec/parsers/number_parser_spec.rb +36 -36
- data/spec/parsers/parser_spec.rb +5 -5
- data/spec/parsers/segmentation_parser_spec.rb +19 -19
- data/spec/parsers/symbol_table_spec.rb +4 -4
- data/spec/parsers/unicode_regex/character_class_spec.rb +19 -19
- data/spec/parsers/unicode_regex/character_range_spec.rb +1 -1
- data/spec/parsers/unicode_regex/character_set_spec.rb +8 -8
- data/spec/parsers/unicode_regex/literal_spec.rb +5 -5
- data/spec/parsers/unicode_regex/unicode_string_spec.rb +2 -2
- data/spec/parsers/unicode_regex_parser_spec.rb +28 -28
- data/spec/resources/loader_spec.rb +32 -32
- data/spec/shared/break_iterator_spec.rb +13 -13
- data/spec/shared/calendar_spec.rb +59 -59
- data/spec/shared/casefolder_spec.rb +5 -5
- data/spec/shared/code_point_spec.rb +46 -46
- data/spec/shared/currencies_spec.rb +7 -7
- data/spec/shared/language_codes_spec.rb +34 -34
- data/spec/shared/languages_spec.rb +30 -30
- data/spec/shared/numbering_system_spec.rb +7 -7
- data/spec/shared/numbers_spec.rb +4 -4
- data/spec/shared/phone_codes_spec.rb +7 -7
- data/spec/shared/postal_code_generator_spec.rb +76 -0
- data/spec/shared/postal_codes_spec.rb +35 -29
- data/spec/shared/territories_spec.rb +40 -40
- data/spec/shared/unicode_regex_spec.rb +71 -71
- data/spec/spec_helper.rb +2 -2
- data/spec/tokenizers/calendars/date_tokenizer_spec.rb +1 -1
- data/spec/tokenizers/calendars/timespan_tokenizer_spec.rb +6 -6
- data/spec/tokenizers/composite_token_spec.rb +3 -3
- data/spec/tokenizers/token_spec.rb +3 -3
- data/spec/twitter_cldr_spec.rb +72 -72
- data/spec/utils/code_points_spec.rb +10 -10
- data/spec/utils/interpolation_spec.rb +32 -32
- data/spec/utils/range_set_spec.rb +36 -36
- data/spec/utils/regexp_ast_spec.rb +44 -0
- data/spec/utils/regexp_sampler_spec.rb +182 -0
- data/spec/utils/yaml/yaml_spec.rb +23 -23
- data/spec/utils_spec.rb +19 -19
- metadata +263 -258
@@ -81,7 +81,7 @@ describe TwitterCldr::Utils do
|
|
81
81
|
'foobar'.localize.to_yaml(opt)
|
82
82
|
|
83
83
|
# dump should not change the option hash
|
84
|
-
opt.
|
84
|
+
expect(opt).to eq({ :syck_compatible => true })
|
85
85
|
|
86
86
|
[
|
87
87
|
[
|
@@ -113,7 +113,7 @@ describe TwitterCldr::Utils do
|
|
113
113
|
"--- \n- \"\\xc2\\x86\"\n- \"a\\xe2\\x80\\xa8b\\xe2\\x80\\xa9c\"\n- \" abc\\n\\\n xyz\"\n",
|
114
114
|
],
|
115
115
|
].each do |opt, yaml|
|
116
|
-
["\xc2\x86", "a\xe2\x80\xa8b\xe2\x80\xa9c", " abc\nxyz"].localize.to_yaml(opt).
|
116
|
+
expect(["\xc2\x86", "a\xe2\x80\xa8b\xe2\x80\xa9c", " abc\nxyz"].localize.to_yaml(opt)).to eq(yaml)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -136,14 +136,14 @@ describe TwitterCldr::Utils do
|
|
136
136
|
"--- \nb: 2\na: 1\nc: 3\n",
|
137
137
|
],
|
138
138
|
].each do |hash_order, yaml|
|
139
|
-
TwitterCldr::Utils::YAML.dump({ 'a' => 1, 'c' => 3, 'b' => 2 }, :hash_order => hash_order).
|
139
|
+
expect(TwitterCldr::Utils::YAML.dump({ 'a' => 1, 'c' => 3, 'b' => 2 }, :hash_order => hash_order)).to eq(yaml)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
143
|
if RUBY_VERSION >= "1.9"
|
144
144
|
it "should preserve hash order" do
|
145
145
|
h = { 'a' => 1, 'c' => 3, 'b' => 2 }
|
146
|
-
TwitterCldr::Utils::YAML.dump(h, :preserve_order => true).
|
146
|
+
expect(TwitterCldr::Utils::YAML.dump(h, :preserve_order => true)).to eq("--- \na: 1\nc: 3\nb: 2\n")
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -161,7 +161,7 @@ describe TwitterCldr::Utils do
|
|
161
161
|
["\r\xe2\x80\xa8\r\n", "--- \"\\n\\L\\n\"\n"],
|
162
162
|
["\r\xe2\x80\xa9\r\n", "--- \"\\n\\P\\n\"\n"],
|
163
163
|
].each do |src, yaml|
|
164
|
-
src.localize.to_yaml(:minimum_block_length => 16).
|
164
|
+
expect(src.localize.to_yaml(:minimum_block_length => 16)).to eq(yaml)
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -170,7 +170,7 @@ describe TwitterCldr::Utils do
|
|
170
170
|
[Struct.new('Hoge', :foo).new(123), "--- !ruby/struct:Hoge \n foo: 123\n", ],
|
171
171
|
[Struct.new(:foo).new(123), "--- !ruby/struct: \n foo: 123\n", ],
|
172
172
|
].each do |src, yaml|
|
173
|
-
TwitterCldr::Utils::YAML.dump(src).
|
173
|
+
expect(TwitterCldr::Utils::YAML.dump(src)).to eq(yaml)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -178,7 +178,7 @@ describe TwitterCldr::Utils do
|
|
178
178
|
("\x00".."\x7f").each do |c|
|
179
179
|
y = c.localize.to_yaml
|
180
180
|
r = YAML.load(y)
|
181
|
-
(c == "\r" ? "\n" : c).
|
181
|
+
expect(c == "\r" ? "\n" : c).to eq(r) # "\r" is normalized as "\n"
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
@@ -215,7 +215,7 @@ describe TwitterCldr::Utils do
|
|
215
215
|
)
|
216
216
|
|
217
217
|
r = YAML.load(y)
|
218
|
-
(c == "\xc2\x85" ? "\n" : c).
|
218
|
+
expect(c == "\xc2\x85" ? "\n" : c).to eq(r) # "\N" is normalized as "\n"
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
@@ -287,9 +287,9 @@ describe TwitterCldr::Utils do
|
|
287
287
|
r = YAML.load(y)
|
288
288
|
|
289
289
|
if (RUBY_VERSION >= "2.0.0" || RUBY_PLATFORM == "java") && c.is_a?(String) && c.downcase == "null"
|
290
|
-
src.
|
290
|
+
expect(src).to eq(c + ext)
|
291
291
|
else
|
292
|
-
src.
|
292
|
+
expect(src).to eq(r)
|
293
293
|
end
|
294
294
|
end
|
295
295
|
end
|
@@ -309,7 +309,7 @@ describe TwitterCldr::Utils do
|
|
309
309
|
:escape_as_utf8 => true
|
310
310
|
)
|
311
311
|
r = YAML.load(y)
|
312
|
-
src.
|
312
|
+
expect(src).to eq(r)
|
313
313
|
end
|
314
314
|
end
|
315
315
|
end
|
@@ -320,22 +320,22 @@ describe TwitterCldr::Utils do
|
|
320
320
|
it "tests successful roundtrip_symbols" do
|
321
321
|
symbol1 = :"Batman: The Dark Knight - Why So Serious?!"
|
322
322
|
result_symbol1 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol1))
|
323
|
-
symbol1.
|
323
|
+
expect(symbol1).to eq(result_symbol1)
|
324
324
|
|
325
325
|
symbol2 = :"Batman: The Dark Knight - \"Why So Serious?!\""
|
326
326
|
result_symbol2 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol2))
|
327
|
-
symbol2.
|
327
|
+
expect(symbol2).to eq(result_symbol2)
|
328
328
|
end
|
329
329
|
|
330
330
|
it "tests successful roundtrip of natural symbols" do
|
331
331
|
symbol1 = :"Batman: The Dark Knight - Why So Serious?!"
|
332
332
|
result_symbol1 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol1, :use_natural_symbols => true))
|
333
|
-
symbol1.
|
333
|
+
expect(symbol1).to eq(result_symbol1)
|
334
334
|
|
335
335
|
symbol2 = :batman
|
336
|
-
TwitterCldr::Utils::YAML.dump(symbol2, :use_natural_symbols => true).
|
336
|
+
expect(TwitterCldr::Utils::YAML.dump(symbol2, :use_natural_symbols => true)).to include(":batman")
|
337
337
|
result_symbol2 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol2, :use_natural_symbols => true))
|
338
|
-
symbol2.
|
338
|
+
expect(symbol2).to eq(result_symbol2)
|
339
339
|
end
|
340
340
|
|
341
341
|
it "tests successful roundtrip of mixed types" do
|
@@ -388,7 +388,7 @@ describe TwitterCldr::Utils do
|
|
388
388
|
end
|
389
389
|
y = TwitterCldr::Utils::YAML.dump(src, :syck_compatible => true)
|
390
390
|
r = YAML.load(y)
|
391
|
-
src.
|
391
|
+
expect(src).to eq(r)
|
392
392
|
end
|
393
393
|
end
|
394
394
|
|
@@ -417,7 +417,7 @@ describe TwitterCldr::Utils do
|
|
417
417
|
].each do |src|
|
418
418
|
y = TwitterCldr::Utils::YAML.dump(src, :syck_compatible => true)
|
419
419
|
r = YAML.load(y)
|
420
|
-
src.
|
420
|
+
expect(src).to eq(r)
|
421
421
|
end
|
422
422
|
end
|
423
423
|
|
@@ -425,7 +425,7 @@ describe TwitterCldr::Utils do
|
|
425
425
|
if RUBY_PLATFORM != "java"
|
426
426
|
a = []
|
427
427
|
a << a
|
428
|
-
|
428
|
+
expect { TwitterCldr::Utils::YAML.dump(a) }.to raise_error(ArgumentError)
|
429
429
|
end
|
430
430
|
end
|
431
431
|
|
@@ -433,11 +433,11 @@ describe TwitterCldr::Utils do
|
|
433
433
|
unless RUBY_VERSION < '1.9.0'
|
434
434
|
y = nil
|
435
435
|
|
436
|
-
|
437
|
-
y.
|
436
|
+
expect { y = TwitterCldr::Utils::YAML.dump('日本語'.force_encoding('ASCII-8BIT')) }.not_to raise_error
|
437
|
+
expect(y).to eq("--- !binary |\n 5pel5pys6Kqe\n\n")
|
438
438
|
|
439
|
-
|
440
|
-
y.
|
439
|
+
expect { y = TwitterCldr::Utils::YAML.dump('日本語'.encode('EUC-JP').force_encoding('UTF-8')) }.not_to raise_error
|
440
|
+
expect(y).to eq("--- !binary |\n xvzL3Ljs\n\n")
|
441
441
|
end
|
442
442
|
end
|
443
443
|
|
data/spec/utils_spec.rb
CHANGED
@@ -12,89 +12,89 @@ describe TwitterCldr::Utils do
|
|
12
12
|
let(:symbolized_hash) { { :foo => { :bar => { :baz => 'woot' }, :ar => [1, 2] }, 42 => { :baz => 'wat' } } }
|
13
13
|
|
14
14
|
it 'symbolizes string keys of a hash' do
|
15
|
-
TwitterCldr::Utils.deep_symbolize_keys(hash).
|
15
|
+
expect(TwitterCldr::Utils.deep_symbolize_keys(hash)).to eq(symbolized_hash)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'deeply symbolizes elements of an array' do
|
19
|
-
TwitterCldr::Utils.deep_symbolize_keys([1, hash, 'foo', :bar]).
|
19
|
+
expect(TwitterCldr::Utils.deep_symbolize_keys([1, hash, 'foo', :bar])).to eq([1, symbolized_hash, 'foo', :bar])
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'deeply symbolizes elements of an array nested in a hash' do
|
23
|
-
TwitterCldr::Utils.deep_symbolize_keys({ 'foo' => [1, hash] }).
|
23
|
+
expect(TwitterCldr::Utils.deep_symbolize_keys({ 'foo' => [1, hash] })).to eq({ :foo => [1, symbolized_hash] })
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'leaves arguments of other types alone' do
|
27
|
-
['foo', :bar, 42].each { |arg| TwitterCldr::Utils.deep_symbolize_keys(arg).
|
27
|
+
['foo', :bar, 42].each { |arg| expect(TwitterCldr::Utils.deep_symbolize_keys(arg)).to eq(arg) }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "#deep_merge! and #deep_merge_hash" do
|
32
32
|
it "combines two non-nested hashes with different keys" do
|
33
33
|
first = { :foo => "bar" }
|
34
|
-
TwitterCldr::Utils.deep_merge_hash(first, { :bar => "baz" }).
|
35
|
-
TwitterCldr::Utils.deep_merge!(first, { :bar => "baz" }).
|
34
|
+
expect(TwitterCldr::Utils.deep_merge_hash(first, { :bar => "baz" })).to eq({ :foo => "bar", :bar => "baz" })
|
35
|
+
expect(TwitterCldr::Utils.deep_merge!(first, { :bar => "baz" })).to eq({ :foo => "bar", :bar => "baz" })
|
36
36
|
end
|
37
37
|
|
38
38
|
it "combines two non-nested hashes with the same keys" do
|
39
39
|
first = { :foo => "bar" }
|
40
|
-
TwitterCldr::Utils.deep_merge_hash(first, { :foo => "baz" }).
|
41
|
-
TwitterCldr::Utils.deep_merge!(first, { :foo => "baz" }).
|
40
|
+
expect(TwitterCldr::Utils.deep_merge_hash(first, { :foo => "baz" })).to eq({ :foo => "baz" })
|
41
|
+
expect(TwitterCldr::Utils.deep_merge!(first, { :foo => "baz" })).to eq({ :foo => "baz" })
|
42
42
|
end
|
43
43
|
|
44
44
|
it "combines two nested hashes" do
|
45
45
|
first = { :foo => "bar", :second => { :bar => "baz", :twitter => "rocks" } }
|
46
46
|
second = { :foo => "baz", :third => { :whassup => "cool" }, :second => { :twitter => "rules" } }
|
47
47
|
result = { :foo => "baz", :second => { :bar => "baz", :twitter => "rules" }, :third => { :whassup => "cool" } }
|
48
|
-
TwitterCldr::Utils.deep_merge_hash(first, second).
|
48
|
+
expect(TwitterCldr::Utils.deep_merge_hash(first, second)).to eq(result)
|
49
49
|
TwitterCldr::Utils.deep_merge!(first, second)
|
50
|
-
first.
|
50
|
+
expect(first).to eq(result)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "replaces arrays with simple types" do
|
54
54
|
first = [1, 2, 3]
|
55
|
-
TwitterCldr::Utils.deep_merge!(first, [4, 5, 6]).
|
55
|
+
expect(TwitterCldr::Utils.deep_merge!(first, [4, 5, 6])).to eq([4, 5, 6])
|
56
56
|
end
|
57
57
|
|
58
58
|
it "merges a nested hash with a few simple array replacements" do
|
59
59
|
first = { :foo => "bar", :second => { :bar => "baz", :twitter => [1, 2, 3] } }
|
60
60
|
second = { :foo => [18], :third => { :whassup => "cool" }, :second => { :twitter => [4, 5, 6] } }
|
61
61
|
TwitterCldr::Utils.deep_merge!(first, second)
|
62
|
-
first.
|
62
|
+
expect(first).to eq({ :foo => [18], :second => { :bar => "baz", :twitter => [4, 5, 6] }, :third => { :whassup => "cool" } })
|
63
63
|
end
|
64
64
|
|
65
65
|
it "merges hashes within arrays" do
|
66
66
|
first = [1, { :foo => "bar" }, { :bar => "baz" }, 8]
|
67
67
|
second = [2, { :foo => "bar2" }, { :bar => "baz2", :twitter => "rules" }, 8, 9]
|
68
68
|
TwitterCldr::Utils.deep_merge!(first, second)
|
69
|
-
first.
|
69
|
+
expect(first).to eq([2, { :foo => "bar2" }, { :bar => "baz2", :twitter => "rules" }, 8, 9])
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "#compute_cache_key" do
|
74
74
|
it "returns a ruby hash of all the pieces concatenated with pipe characters" do
|
75
|
-
TwitterCldr::Utils.compute_cache_key("space", "the", "final", "frontier").
|
75
|
+
expect(TwitterCldr::Utils.compute_cache_key("space", "the", "final", "frontier")).to eq("space|the|final|frontier".hash)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "returns zero if no arguments are passed" do
|
79
|
-
TwitterCldr::Utils.compute_cache_key.
|
79
|
+
expect(TwitterCldr::Utils.compute_cache_key).to eq(0)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
describe '#traverse_hash' do
|
84
84
|
it 'returns value from the hash at the given path' do
|
85
|
-
TwitterCldr::Utils.traverse_hash({ :foo => { :bar => 2, 'baz' => { 4 => 42 } } }, [:foo, 'baz', 4]).
|
85
|
+
expect(TwitterCldr::Utils.traverse_hash({ :foo => { :bar => 2, 'baz' => { 4 => 42 } } }, [:foo, 'baz', 4])).to eq(42)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'returns nil if the value is missing' do
|
89
|
-
TwitterCldr::Utils.traverse_hash({ :foo => { :bar => 2 } }, [:foo, :baz]).
|
89
|
+
expect(TwitterCldr::Utils.traverse_hash({ :foo => { :bar => 2 } }, [:foo, :baz])).to be_nil
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'returns nil path is empty' do
|
93
|
-
TwitterCldr::Utils.traverse_hash({ :foo => 42 }, []).
|
93
|
+
expect(TwitterCldr::Utils.traverse_hash({ :foo => 42 }, [])).to be_nil
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'returns nil if not a Hash is passed' do
|
97
|
-
TwitterCldr::Utils.traverse_hash(42, [:foo, :bar]).
|
97
|
+
expect(TwitterCldr::Utils.traverse_hash(42, [:foo, :bar])).to be_nil
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|