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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/History.txt +4 -0
  4. data/README.md +17 -6
  5. data/lib/twitter_cldr/resources/postal_codes_importer.rb +12 -1
  6. data/lib/twitter_cldr/resources/regexp_ast_generator.rb +41 -0
  7. data/lib/twitter_cldr/resources.rb +1 -0
  8. data/lib/twitter_cldr/shared/postal_code_generator.rb +50 -0
  9. data/lib/twitter_cldr/shared/postal_codes.rb +48 -9
  10. data/lib/twitter_cldr/shared.rb +15 -14
  11. data/lib/twitter_cldr/utils/regexp_ast.rb +115 -0
  12. data/lib/twitter_cldr/utils/regexp_sampler.rb +149 -0
  13. data/lib/twitter_cldr/utils.rb +5 -3
  14. data/lib/twitter_cldr/version.rb +1 -1
  15. data/resources/shared/postal_codes.yml +1442 -159
  16. data/spec/bidi/bidi_spec.rb +1 -1
  17. data/spec/collation/collation_spec.rb +1 -1
  18. data/spec/collation/collator_spec.rb +31 -31
  19. data/spec/collation/implicit_collation_elements_spec.rb +6 -6
  20. data/spec/collation/sort_key_builder_spec.rb +28 -26
  21. data/spec/collation/tailoring_spec.rb +1 -1
  22. data/spec/collation/trie_builder_spec.rb +16 -16
  23. data/spec/collation/trie_dumps_spec.rb +2 -2
  24. data/spec/collation/trie_loader_spec.rb +8 -8
  25. data/spec/collation/trie_spec.rb +61 -61
  26. data/spec/collation/trie_with_fallback_spec.rb +5 -5
  27. data/spec/core_ext_spec.rb +1 -1
  28. data/spec/data_readers/additional_date_format_selector_spec.rb +38 -38
  29. data/spec/data_readers/date_time_data_reader_spec.rb +2 -2
  30. data/spec/data_readers/number_data_reader_spec.rb +1 -1
  31. data/spec/formatters/calendars/datetime_formatter_spec.rb +218 -218
  32. data/spec/formatters/list_formatter_spec.rb +8 -8
  33. data/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb +14 -14
  34. data/spec/formatters/numbers/abbreviated/long_decimal_formatter_spec.rb +4 -4
  35. data/spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb +4 -4
  36. data/spec/formatters/numbers/currency_formatter_spec.rb +11 -11
  37. data/spec/formatters/numbers/decimal_formatter_spec.rb +3 -3
  38. data/spec/formatters/numbers/helpers/fraction_spec.rb +3 -3
  39. data/spec/formatters/numbers/helpers/integer_spec.rb +16 -16
  40. data/spec/formatters/numbers/number_formatter_spec.rb +21 -21
  41. data/spec/formatters/numbers/percent_formatter_spec.rb +3 -3
  42. data/spec/formatters/numbers/rbnf/rbnf_spec.rb +2 -2
  43. data/spec/formatters/plurals/plural_formatter_spec.rb +41 -41
  44. data/spec/formatters/plurals/rules_spec.rb +13 -13
  45. data/spec/localized/localized_array_spec.rb +12 -12
  46. data/spec/localized/localized_date_spec.rb +33 -33
  47. data/spec/localized/localized_datetime_spec.rb +11 -11
  48. data/spec/localized/localized_hash_spec.rb +4 -4
  49. data/spec/localized/localized_number_spec.rb +36 -36
  50. data/spec/localized/localized_object_spec.rb +8 -8
  51. data/spec/localized/localized_string_spec.rb +53 -53
  52. data/spec/localized/localized_symbol_spec.rb +9 -9
  53. data/spec/localized/localized_time_spec.rb +10 -10
  54. data/spec/localized/localized_timespan_spec.rb +8 -8
  55. data/spec/normalization_spec.rb +6 -6
  56. data/spec/parsers/number_parser_spec.rb +36 -36
  57. data/spec/parsers/parser_spec.rb +5 -5
  58. data/spec/parsers/segmentation_parser_spec.rb +19 -19
  59. data/spec/parsers/symbol_table_spec.rb +4 -4
  60. data/spec/parsers/unicode_regex/character_class_spec.rb +19 -19
  61. data/spec/parsers/unicode_regex/character_range_spec.rb +1 -1
  62. data/spec/parsers/unicode_regex/character_set_spec.rb +8 -8
  63. data/spec/parsers/unicode_regex/literal_spec.rb +5 -5
  64. data/spec/parsers/unicode_regex/unicode_string_spec.rb +2 -2
  65. data/spec/parsers/unicode_regex_parser_spec.rb +28 -28
  66. data/spec/resources/loader_spec.rb +32 -32
  67. data/spec/shared/break_iterator_spec.rb +13 -13
  68. data/spec/shared/calendar_spec.rb +59 -59
  69. data/spec/shared/casefolder_spec.rb +5 -5
  70. data/spec/shared/code_point_spec.rb +46 -46
  71. data/spec/shared/currencies_spec.rb +7 -7
  72. data/spec/shared/language_codes_spec.rb +34 -34
  73. data/spec/shared/languages_spec.rb +30 -30
  74. data/spec/shared/numbering_system_spec.rb +7 -7
  75. data/spec/shared/numbers_spec.rb +4 -4
  76. data/spec/shared/phone_codes_spec.rb +7 -7
  77. data/spec/shared/postal_code_generator_spec.rb +76 -0
  78. data/spec/shared/postal_codes_spec.rb +35 -29
  79. data/spec/shared/territories_spec.rb +40 -40
  80. data/spec/shared/unicode_regex_spec.rb +71 -71
  81. data/spec/spec_helper.rb +2 -2
  82. data/spec/tokenizers/calendars/date_tokenizer_spec.rb +1 -1
  83. data/spec/tokenizers/calendars/timespan_tokenizer_spec.rb +6 -6
  84. data/spec/tokenizers/composite_token_spec.rb +3 -3
  85. data/spec/tokenizers/token_spec.rb +3 -3
  86. data/spec/twitter_cldr_spec.rb +72 -72
  87. data/spec/utils/code_points_spec.rb +10 -10
  88. data/spec/utils/interpolation_spec.rb +32 -32
  89. data/spec/utils/range_set_spec.rb +36 -36
  90. data/spec/utils/regexp_ast_spec.rb +44 -0
  91. data/spec/utils/regexp_sampler_spec.rb +182 -0
  92. data/spec/utils/yaml/yaml_spec.rb +23 -23
  93. data/spec/utils_spec.rb +19 -19
  94. metadata +263 -258
@@ -28,37 +28,37 @@ describe Trie do
28
28
 
29
29
  describe '#initialize' do
30
30
  it 'initializes an empty trie by default' do
31
- Trie.new.should be_empty
31
+ expect(Trie.new).to be_empty
32
32
  end
33
33
 
34
34
  it 'initializes with a root node' do
35
35
  trie = Trie.new(Trie::Node.new(nil, 1 => Trie::Node.new(nil, { 2 => Trie::Node.new('12')}), 2 => Trie::Node.new('2')))
36
36
 
37
- trie.to_hash.should == {
37
+ expect(trie.to_hash).to eq({
38
38
  1 => [nil, { 2 => ['12', {}] }],
39
39
  2 => ['2', {}]
40
- }
40
+ })
41
41
  end
42
42
  end
43
43
 
44
44
  describe '#lock and #locked?' do
45
45
  it 'trie is unlocked by default' do
46
- trie.should_not be_locked
46
+ expect(trie).not_to be_locked
47
47
  end
48
48
 
49
49
  it '#lock locks the trie' do
50
50
  trie.lock
51
- trie.should be_locked
51
+ expect(trie).to be_locked
52
52
  end
53
53
 
54
54
  it '#lock returns the trie' do
55
- trie.lock.should == trie
55
+ expect(trie.lock).to eq(trie)
56
56
  end
57
57
  end
58
58
 
59
59
  describe '#starters' do
60
60
  it 'returns all unique first elements of the keys in the trie' do
61
- trie.starters.should =~ [1, 2, 3, 4]
61
+ expect(trie.starters).to match_array([1, 2, 3, 4])
62
62
  end
63
63
  end
64
64
 
@@ -67,64 +67,64 @@ describe Trie do
67
67
  res = {}
68
68
  trie.each_starting_with(1) { |k, v| res[k] = v }
69
69
 
70
- res.should == { [1] => '1', [1, 4] => '14', [1, 5] => '15', [1, 4, 8] => '148' }
70
+ expect(res).to eq({ [1] => '1', [1, 4] => '14', [1, 5] => '15', [1, 4, 8] => '148' })
71
71
  end
72
72
 
73
73
  it 'works when argument is not a starter' do
74
74
  res = {}
75
75
  trie.each_starting_with(42) { |k, v| res[k] = v }
76
76
 
77
- res.should == {}
77
+ expect(res).to eq({})
78
78
  end
79
79
  end
80
80
 
81
81
  describe '#get' do
82
82
  it 'returns nil for non existing keys' do
83
- [[6], [3], [1, 4, 3], [2, 7, 5, 6, 9]].each { |key| trie.get(key).should be_nil }
83
+ [[6], [3], [1, 4, 3], [2, 7, 5, 6, 9]].each { |key| expect(trie.get(key)).to be_nil }
84
84
  end
85
85
 
86
86
  it 'returns value for each existing key' do
87
- values.each { |key, value| trie.get(key).should == value }
87
+ values.each { |key, value| expect(trie.get(key)).to eq(value) }
88
88
  end
89
89
  end
90
90
 
91
91
  describe '#add' do
92
92
  it 'does not override values' do
93
- trie.get([1, 4]).should == '14'
93
+ expect(trie.get([1, 4])).to eq('14')
94
94
 
95
95
  trie.add([1, 4], '14-new')
96
- trie.get([1, 4]).should == '14'
96
+ expect(trie.get([1, 4])).to eq('14')
97
97
  end
98
98
 
99
99
  it 'adds new values' do
100
- trie.get([1, 9]).should be_nil
100
+ expect(trie.get([1, 9])).to be_nil
101
101
 
102
102
  trie.add([1, 9], '19')
103
- trie.get([1, 9]).should == '19'
103
+ expect(trie.get([1, 9])).to eq('19')
104
104
  end
105
105
 
106
106
  it 'raises RuntimeError if called on a locked trie' do
107
- lambda { trie.lock.add([1, 3], 'value') }.should raise_error(RuntimeError)
107
+ expect { trie.lock.add([1, 3], 'value') }.to raise_error(RuntimeError)
108
108
  end
109
109
  end
110
110
 
111
111
  describe '#set' do
112
112
  it 'overrides values' do
113
- trie.get([1, 4]).should == '14'
113
+ expect(trie.get([1, 4])).to eq('14')
114
114
 
115
115
  trie.set([1, 4], '14-new')
116
- trie.get([1, 4]).should == '14-new'
116
+ expect(trie.get([1, 4])).to eq('14-new')
117
117
  end
118
118
 
119
119
  it 'adds new values' do
120
- trie.get([1, 9]).should be_nil
120
+ expect(trie.get([1, 9])).to be_nil
121
121
 
122
122
  trie.set([1, 9], '19')
123
- trie.get([1, 9]).should == '19'
123
+ expect(trie.get([1, 9])).to eq('19')
124
124
  end
125
125
 
126
126
  it 'raises RuntimeError if called on a locked trie' do
127
- lambda { trie.lock.set([1, 3], 'value') }.should raise_error(RuntimeError)
127
+ expect { trie.lock.set([1, 3], 'value') }.to raise_error(RuntimeError)
128
128
  end
129
129
  end
130
130
 
@@ -140,12 +140,12 @@ describe Trie do
140
140
 
141
141
  describe 'first two elements of the returned array (value and prefix size)' do
142
142
  it 'are nil and 0 if the prefix was not found' do
143
- trie.find_prefix([42]).first(2).should == [nil, 0]
143
+ expect(trie.find_prefix([42]).first(2)).to eq([nil, 0])
144
144
  end
145
145
 
146
146
  it 'are the stored value and the key size if the whole key was found' do
147
147
  values.each do |key, value|
148
- trie.find_prefix(key).first(2).should == [value, key.size]
148
+ expect(trie.find_prefix(key).first(2)).to eq([value, key.size])
149
149
  end
150
150
  end
151
151
 
@@ -158,12 +158,12 @@ describe Trie do
158
158
  }
159
159
 
160
160
  tests.each do |key, result|
161
- trie.find_prefix(key).first(2).should == result
161
+ expect(trie.find_prefix(key).first(2)).to eq(result)
162
162
  end
163
163
  end
164
164
 
165
165
  def test_find_prefix(trie, key, value, size = key.size)
166
- trie.find_prefix(key).first(2).should == [value, size]
166
+ expect(trie.find_prefix(key).first(2)).to eq([value, size])
167
167
  end
168
168
  end
169
169
 
@@ -175,23 +175,23 @@ describe Trie do
175
175
  it 'is always a locked trie' do
176
176
  [trie, trie.lock].each do |some_trie|
177
177
  [non_existing_key, key_with_suffixes, key_without_suffixes].each do |key|
178
- some_trie.find_prefix(key).last.should be_locked
178
+ expect(some_trie.find_prefix(key).last).to be_locked
179
179
  end
180
180
  end
181
181
  end
182
182
 
183
183
  it 'is a locked empty subtrie if the prefix that was found does not have any suffixes' do
184
- trie.find_prefix(key_without_suffixes).last.to_hash.should be_empty
184
+ expect(trie.find_prefix(key_without_suffixes).last.to_hash).to be_empty
185
185
  end
186
186
 
187
187
  it 'is a subtrie of possible suffixes for the prefix that was found' do
188
- trie.find_prefix(key_with_suffixes).last.to_hash.should == { 7 => [nil, { 5 => ["275", {}] }] }
188
+ expect(trie.find_prefix(key_with_suffixes).last.to_hash).to eq({ 7 => [nil, { 5 => ["275", {}] }] })
189
189
  end
190
190
 
191
191
  it 'is a hash representing the whole trie if the prefix was not found' do
192
- trie.get(non_existing_key).should be_nil
192
+ expect(trie.get(non_existing_key)).to be_nil
193
193
 
194
- trie.find_prefix(non_existing_key).last.to_hash.should == root_subtrie
194
+ expect(trie.find_prefix(non_existing_key).last.to_hash).to eq(root_subtrie)
195
195
  end
196
196
 
197
197
  end
@@ -199,26 +199,26 @@ describe Trie do
199
199
  context 'argument does not match any value, but is a prefix of a longer key' do
200
200
  context 'argument has a shorter key as a prefix' do
201
201
  it 'returns value for the key, its size and suffixes subtrie' do
202
- trie.get([2]).should_not be_nil
203
- trie.get([2, 7, 5]).should_not be_nil
202
+ expect(trie.get([2])).not_to be_nil
203
+ expect(trie.get([2, 7, 5])).not_to be_nil
204
204
 
205
205
  result = trie.find_prefix([2, 7])
206
206
 
207
- result.first(2).should == ['2', 1]
208
- result.last.to_hash.should == { 7 => [nil, { 5 => ["275", {}] }] }
207
+ expect(result.first(2)).to eq(['2', 1])
208
+ expect(result.last.to_hash).to eq({ 7 => [nil, { 5 => ["275", {}] }] })
209
209
  end
210
210
  end
211
211
 
212
212
  context 'argument does not have a shorter key as a prefix' do
213
213
  it 'returns nil, 0 and suffixes subtrie for the root node' do
214
- trie.get([3]).should be_nil
215
- trie.get([3, 9]).should be_nil
216
- trie.get([3, 9, 2]).should_not be_nil
214
+ expect(trie.get([3])).to be_nil
215
+ expect(trie.get([3, 9])).to be_nil
216
+ expect(trie.get([3, 9, 2])).not_to be_nil
217
217
 
218
218
  result = trie.find_prefix([3, 9])
219
219
 
220
- result.first(2).should == [nil, 0]
221
- result.last.to_hash.should == root_subtrie
220
+ expect(result.first(2)).to eq([nil, 0])
221
+ expect(result.last.to_hash).to eq(root_subtrie)
222
222
  end
223
223
  end
224
224
  end
@@ -231,11 +231,11 @@ describe Trie do
231
231
  trie.add([13, 37], 1337)
232
232
  trie.add([42], 42)
233
233
 
234
- Marshal.load(Marshal.dump(trie)).to_hash.should == { 42 => [42, {}], 13 => [nil, { 37 => [1337, {}] }] }
234
+ expect(Marshal.load(Marshal.dump(trie)).to_hash).to eq({ 42 => [42, {}], 13 => [nil, { 37 => [1337, {}] }] })
235
235
  end
236
236
 
237
237
  it 'does not dump locked state' do
238
- Marshal.load(Marshal.dump(Trie.new.lock)).should_not be_locked
238
+ expect(Marshal.load(Marshal.dump(Trie.new.lock))).not_to be_locked
239
239
  end
240
240
  end
241
241
 
@@ -288,36 +288,36 @@ describe Trie do
288
288
 
289
289
  describe '#initialize' do
290
290
  it 'initializes node with nil value and empty children hash by default' do
291
- node.value.should be_nil
292
- node.should_not have_children
291
+ expect(node.value).to be_nil
292
+ expect(node).not_to have_children
293
293
  end
294
294
 
295
295
  it 'initializes node with provided value and children hash' do
296
- root_node.value.should == 'node-0'
297
- root_node.should have_children
296
+ expect(root_node.value).to eq('node-0')
297
+ expect(root_node).to have_children
298
298
  end
299
299
  end
300
300
 
301
301
  describe '#child and #set_child' do
302
302
  it '#child returns nil if a child with a given key does not exist' do
303
- node.child(42).should be_nil
303
+ expect(node.child(42)).to be_nil
304
304
  end
305
305
 
306
306
  it '#set_child saves a child by key and #child returns the child by key' do
307
307
  node.set_child(42, child)
308
- node.child(42).should == child
308
+ expect(node.child(42)).to eq(child)
309
309
  end
310
310
 
311
311
  it '#set_child overrides a child by key' do
312
312
  node.set_child(42, child)
313
313
  node.set_child(42, another_child)
314
314
 
315
- node.child(42).should_not == child
316
- node.child(42).should == another_child
315
+ expect(node.child(42)).not_to eq(child)
316
+ expect(node.child(42)).to eq(another_child)
317
317
  end
318
318
 
319
319
  it '#set_child returns the child that was saved' do
320
- node.set_child(42, child).should == child
320
+ expect(node.set_child(42, child)).to eq(child)
321
321
  end
322
322
  end
323
323
 
@@ -328,7 +328,7 @@ describe Trie do
328
328
  res = {}
329
329
  node.each_key_and_child { |key, child| res[key] = child }
330
330
 
331
- res.should == { 42 => child, 13 => another_child }
331
+ expect(res).to eq({ 42 => child, 13 => another_child })
332
332
  end
333
333
  end
334
334
 
@@ -337,47 +337,47 @@ describe Trie do
337
337
  node.set_child(42, child)
338
338
  node.set_child(13, another_child)
339
339
 
340
- node.keys.should =~ [13, 42]
340
+ expect(node.keys).to match_array([13, 42])
341
341
  end
342
342
  end
343
343
 
344
344
  describe '#has_children?' do
345
345
  it 'returns false if the node has no children' do
346
- node.should_not have_children
346
+ expect(node).not_to have_children
347
347
  end
348
348
 
349
349
  it 'returns true if the node has children' do
350
350
  node.set_child(42, child)
351
- node.should have_children
351
+ expect(node).to have_children
352
352
  end
353
353
  end
354
354
 
355
355
  describe '#to_trie' do
356
356
  it 'returns a trie' do
357
- node.to_trie.should be_instance_of(Trie)
357
+ expect(node.to_trie).to be_instance_of(Trie)
358
358
  end
359
359
 
360
360
  it 'returns a locked trie' do
361
- node.to_trie.should be_locked
361
+ expect(node.to_trie).to be_locked
362
362
  end
363
363
 
364
364
  it 'current node is a root of a new trie' do
365
- root_node.to_trie.to_hash.should == subtrie_hash
365
+ expect(root_node.to_trie.to_hash).to eq(subtrie_hash)
366
366
  end
367
367
 
368
368
  it 'sets new trie root value to nil' do
369
- root_node.value.should_not be_nil
370
- root_node.to_trie.instance_variable_get(:@root).value.should be_nil
369
+ expect(root_node.value).not_to be_nil
370
+ expect(root_node.to_trie.instance_variable_get(:@root).value).to be_nil
371
371
  end
372
372
  end
373
373
 
374
374
  describe '#subtrie_hash' do
375
375
  it 'returns an empty hash if the node has no children' do
376
- node.subtrie_hash.should == {}
376
+ expect(node.subtrie_hash).to eq({})
377
377
  end
378
378
 
379
379
  it 'returns a nested hash of children values' do
380
- root_node.subtrie_hash.should == subtrie_hash
380
+ expect(root_node.subtrie_hash).to eq(subtrie_hash)
381
381
  end
382
382
  end
383
383
 
@@ -17,30 +17,30 @@ describe TrieWithFallback do
17
17
  describe '#get' do
18
18
  it 'returns result if the key is present' do
19
19
  dont_allow(fallback).get
20
- trie.get([1, 2, 3]).should == 'value'
20
+ expect(trie.get([1, 2, 3])).to eq('value')
21
21
  end
22
22
 
23
23
  it 'resorts to the fallback if the key is not present' do
24
24
  mock(fallback).get([3, 2, 1]) { 'fallback-value' }
25
- trie.get([3, 2, 1]).should == 'fallback-value'
25
+ expect(trie.get([3, 2, 1])).to eq('fallback-value')
26
26
  end
27
27
  end
28
28
 
29
29
  describe '#find_prefix' do
30
30
  it 'returns result if the key is present' do
31
31
  dont_allow(fallback).find_prefix
32
- trie.find_prefix([1, 2, 3, 4]).first(2).should == ['value', 3]
32
+ expect(trie.find_prefix([1, 2, 3, 4]).first(2)).to eq(['value', 3])
33
33
  end
34
34
 
35
35
  it 'resorts to the fallback if the key is not present' do
36
36
  mock(fallback).find_prefix([3, 2, 1]) { 'fallback-result' }
37
- trie.find_prefix([3, 2, 1]).should == 'fallback-result'
37
+ expect(trie.find_prefix([3, 2, 1])).to eq('fallback-result')
38
38
  end
39
39
  end
40
40
 
41
41
  describe 'marshaling' do
42
42
  it 'does not dump fallback' do
43
- Marshal.load(Marshal.dump(TrieWithFallback.new(Trie.new))).fallback.should be_nil
43
+ expect(Marshal.load(Marshal.dump(TrieWithFallback.new(Trie.new))).fallback).to be_nil
44
44
  end
45
45
  end
46
46
 
@@ -11,7 +11,7 @@ describe 'Core classes localization' do
11
11
  describe klass do
12
12
  it 'has public instance method #localize' do
13
13
  # convert methods names to symbols (they're strings in 1.8)
14
- klass.public_instance_methods.map(&:to_sym).should include(:localize)
14
+ expect(klass.public_instance_methods.map(&:to_sym)).to include(:localize)
15
15
  end
16
16
  end
17
17
  end
@@ -18,13 +18,13 @@ describe AdditionalDateFormatSelector do
18
18
  it "calculates the score based on relative offset from actual position" do
19
19
  goal_entities = selector.send(:separate, "MMMyyd")
20
20
  entities = selector.send(:separate, "d")
21
- selector.send(:position_score, entities, goal_entities).should == 2
21
+ expect(selector.send(:position_score, entities, goal_entities)).to eq(2)
22
22
  end
23
23
 
24
24
  it "calculates a zero score if all entites are in the same positions" do
25
25
  goal_entities = selector.send(:separate, "MMMyyd")
26
26
  entities = selector.send(:separate, "MMMyyd")
27
- selector.send(:position_score, entities, goal_entities).should == 0
27
+ expect(selector.send(:position_score, entities, goal_entities)).to eq(0)
28
28
  end
29
29
  end
30
30
 
@@ -32,13 +32,13 @@ describe AdditionalDateFormatSelector do
32
32
  it "calculates a higher score if an entity doesn't exist" do
33
33
  goal_entities = selector.send(:separate, "MMMEd")
34
34
  entities = selector.send(:separate, "d")
35
- selector.send(:exist_score, entities, goal_entities).should == 2
35
+ expect(selector.send(:exist_score, entities, goal_entities)).to eq(2)
36
36
  end
37
37
 
38
38
  it "calculates a zero score if all entities exist" do
39
39
  goal_entities = selector.send(:separate, "MMMyyd")
40
40
  entities = selector.send(:separate, "dMMMyy")
41
- selector.send(:exist_score, entities, goal_entities).should == 0
41
+ expect(selector.send(:exist_score, entities, goal_entities)).to eq(0)
42
42
  end
43
43
  end
44
44
 
@@ -46,13 +46,13 @@ describe AdditionalDateFormatSelector do
46
46
  it "calculates the score based on the difference in the length of each matching entity" do
47
47
  goal_entities = selector.send(:separate, "MMMyyd")
48
48
  entities = selector.send(:separate, "ddMMy")
49
- selector.send(:count_score, entities, goal_entities).should == 3
49
+ expect(selector.send(:count_score, entities, goal_entities)).to eq(3)
50
50
  end
51
51
 
52
52
  it "calculates a zero score if all entities are the same length" do
53
53
  goal_entities = selector.send(:separate, "MMMyyd")
54
54
  entities = selector.send(:separate, "d")
55
- selector.send(:count_score, entities, goal_entities).should == 0
55
+ expect(selector.send(:count_score, entities, goal_entities)).to eq(0)
56
56
  end
57
57
  end
58
58
 
@@ -60,72 +60,72 @@ describe AdditionalDateFormatSelector do
60
60
  it "calculates a cumulative score from position and count" do
61
61
  goal_entities = selector.send(:separate, "MMMyydGG")
62
62
  entities = selector.send(:separate, "ddMMGGyy")
63
- selector.send(:exist_score, entities, goal_entities).should == 0
64
- selector.send(:count_score, entities, goal_entities).should == 2
65
- selector.send(:position_score, entities, goal_entities).should == 3
66
- selector.send(:score, entities, goal_entities).should == 5
63
+ expect(selector.send(:exist_score, entities, goal_entities)).to eq(0)
64
+ expect(selector.send(:count_score, entities, goal_entities)).to eq(2)
65
+ expect(selector.send(:position_score, entities, goal_entities)).to eq(3)
66
+ expect(selector.send(:score, entities, goal_entities)).to eq(5)
67
67
  end
68
68
 
69
69
  it "calculates a cumulative score from position, count, and existence (existence weighted by 2)" do
70
70
  goal_entities = selector.send(:separate, "MMMyydGG")
71
71
  entities = selector.send(:separate, "ddMMyy")
72
- selector.send(:exist_score, entities, goal_entities).should == 1
73
- selector.send(:count_score, entities, goal_entities).should == 2
74
- selector.send(:position_score, entities, goal_entities).should == 1
72
+ expect(selector.send(:exist_score, entities, goal_entities)).to eq(1)
73
+ expect(selector.send(:count_score, entities, goal_entities)).to eq(2)
74
+ expect(selector.send(:position_score, entities, goal_entities)).to eq(1)
75
75
  # (exist_score * 2) + count_score + position_score
76
- selector.send(:score, entities, goal_entities).should == 5
76
+ expect(selector.send(:score, entities, goal_entities)).to eq(5)
77
77
  end
78
78
  end
79
79
 
80
80
  describe "#rank" do
81
81
  it "returns a score for each available format" do
82
82
  ranked_formats = selector.send(:rank, "MMMd")
83
- ranked_formats["MMMd"].should == 0
84
- ranked_formats["yMEd"].should == 4
85
- ranked_formats["y"].should == 4
86
- ranked_formats["EHms"].should == 4
87
- ranked_formats["MMM"].should == 2
83
+ expect(ranked_formats["MMMd"]).to eq(0)
84
+ expect(ranked_formats["yMEd"]).to eq(4)
85
+ expect(ranked_formats["y"]).to eq(4)
86
+ expect(ranked_formats["EHms"]).to eq(4)
87
+ expect(ranked_formats["MMM"]).to eq(2)
88
88
  end
89
89
  end
90
90
 
91
91
  describe "#find_closest" do
92
92
  it "returns an exact match if it exists" do
93
- selector.find_closest("h").should == selector.pattern_hash[:h]
94
- selector.find_closest("MMMd").should == selector.pattern_hash[:MMMd]
95
- selector.find_closest("Hms").should == selector.pattern_hash[:Hms]
96
- selector.find_closest("yQQQQ").should == selector.pattern_hash[:yQQQQ]
93
+ expect(selector.find_closest("h")).to eq(selector.pattern_hash[:h])
94
+ expect(selector.find_closest("MMMd")).to eq(selector.pattern_hash[:MMMd])
95
+ expect(selector.find_closest("Hms")).to eq(selector.pattern_hash[:Hms])
96
+ expect(selector.find_closest("yQQQQ")).to eq(selector.pattern_hash[:yQQQQ])
97
97
  end
98
98
 
99
99
  it "returns the next closest match (lowest score) if an exact match can't be found" do
100
- selector.find_closest("MMMMd").should == selector.pattern_hash[:MMMd]
101
- selector.find_closest("mHs").should == selector.pattern_hash[:Hms]
102
- selector.find_closest("Med").should == selector.pattern_hash[:MEd]
100
+ expect(selector.find_closest("MMMMd")).to eq(selector.pattern_hash[:MMMd])
101
+ expect(selector.find_closest("mHs")).to eq(selector.pattern_hash[:Hms])
102
+ expect(selector.find_closest("Med")).to eq(selector.pattern_hash[:MEd])
103
103
  end
104
104
 
105
105
  it "returns nil if an empty pattern is given" do
106
- selector.find_closest(nil).should be_nil
107
- selector.find_closest("").should be_nil
108
- selector.find_closest(" ").should be_nil
106
+ expect(selector.find_closest(nil)).to be_nil
107
+ expect(selector.find_closest("")).to be_nil
108
+ expect(selector.find_closest(" ")).to be_nil
109
109
  end
110
110
  end
111
111
 
112
112
  describe "#separate" do
113
113
  it "divides a string into entities by runs of equal characters" do
114
- selector.send(:separate, "ddMMyy").should == ["dd", "MM", "yy"]
115
- selector.send(:separate, "ddMMyyMM").should == ["dd", "MM", "yy", "MM"]
116
- selector.send(:separate, "mmMM").should == ["mm", "MM"]
114
+ expect(selector.send(:separate, "ddMMyy")).to eq(["dd", "MM", "yy"])
115
+ expect(selector.send(:separate, "ddMMyyMM")).to eq(["dd", "MM", "yy", "MM"])
116
+ expect(selector.send(:separate, "mmMM")).to eq(["mm", "MM"])
117
117
  end
118
118
  end
119
119
 
120
120
  describe "#patterns" do
121
121
  it "returns a list of all available patterns" do
122
122
  patterns = selector.patterns
123
- patterns.should be_a(Array)
124
- patterns.should include("MMMd")
125
- patterns.should include("yQQQ")
126
- patterns.should include("yQQQQ")
127
- patterns.should include("EHms")
128
- patterns.should include("d")
123
+ expect(patterns).to be_a(Array)
124
+ expect(patterns).to include("MMMd")
125
+ expect(patterns).to include("yQQQ")
126
+ expect(patterns).to include("yQQQQ")
127
+ expect(patterns).to include("EHms")
128
+ expect(patterns).to include("d")
129
129
  end
130
130
  end
131
131
 
@@ -12,8 +12,8 @@ describe DateTimeDataReader do
12
12
 
13
13
  describe "#initialize" do
14
14
  it "chooses gregorian as the calendar type if none is specified" do
15
- DateTimeDataReader.new(:es).calendar_type.should == :gregorian
16
- DateTimeDataReader.new(:es, :calendar_type => :julian).calendar_type.should == :julian
15
+ expect(DateTimeDataReader.new(:es).calendar_type).to eq(:gregorian)
16
+ expect(DateTimeDataReader.new(:es, :calendar_type => :julian).calendar_type).to eq(:julian)
17
17
  end
18
18
  end
19
19
 
@@ -12,7 +12,7 @@ describe NumberDataReader do
12
12
 
13
13
  describe "#get_key_for" do
14
14
  it "builds a power-of-ten key based on the number of digits in the input" do
15
- (3..15).each { |i| data_reader.send(:get_key_for, "1337#{"0" * (i - 3)}").should == 10 ** i }
15
+ (3..15).each { |i| expect(data_reader.send(:get_key_for, "1337#{"0" * (i - 3)}")).to eq(10 ** i) }
16
16
  end
17
17
  end
18
18
  end