phony 2.20.13 → 2.20.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phony/config.rb +25 -26
- data/lib/phony/countries/argentina.rb +311 -314
- data/lib/phony/countries/austria.rb +71 -72
- data/lib/phony/countries/bangladesh.rb +27 -28
- data/lib/phony/countries/belarus.rb +110 -111
- data/lib/phony/countries/brazil.rb +92 -92
- data/lib/phony/countries/cambodia.rb +9 -9
- data/lib/phony/countries/china.rb +22 -21
- data/lib/phony/countries/croatia.rb +6 -5
- data/lib/phony/countries/georgia.rb +84 -84
- data/lib/phony/countries/germany.rb +4067 -4068
- data/lib/phony/countries/guinea.rb +8 -8
- data/lib/phony/countries/india.rb +31 -34
- data/lib/phony/countries/indonesia.rb +57 -46
- data/lib/phony/countries/ireland.rb +4 -5
- data/lib/phony/countries/italy.rb +54 -53
- data/lib/phony/countries/japan.rb +456 -456
- data/lib/phony/countries/kyrgyzstan.rb +109 -109
- data/lib/phony/countries/latvia.rb +34 -34
- data/lib/phony/countries/libya.rb +106 -106
- data/lib/phony/countries/malaysia.rb +12 -12
- data/lib/phony/countries/moldova.rb +42 -42
- data/lib/phony/countries/montenegro.rb +24 -20
- data/lib/phony/countries/myanmar.rb +39 -39
- data/lib/phony/countries/namibia.rb +35 -29
- data/lib/phony/countries/nepal.rb +60 -62
- data/lib/phony/countries/netherlands.rb +13 -13
- data/lib/phony/countries/pakistan.rb +135 -111
- data/lib/phony/countries/paraguay.rb +135 -135
- data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +125 -128
- data/lib/phony/countries/saudi_arabia.rb +5 -5
- data/lib/phony/countries/serbia.rb +47 -39
- data/lib/phony/countries/somalia.rb +18 -18
- data/lib/phony/countries/south_korea.rb +16 -13
- data/lib/phony/countries/sweden.rb +28 -28
- data/lib/phony/countries/taiwan.rb +20 -19
- data/lib/phony/countries/tajikistan.rb +70 -70
- data/lib/phony/countries/turkmenistan.rb +65 -65
- data/lib/phony/countries/ukraine.rb +607 -607
- data/lib/phony/countries/united_kingdom.rb +66 -66
- data/lib/phony/countries/uruguay.rb +40 -41
- data/lib/phony/countries/vietnam.rb +18 -17
- data/lib/phony/countries/zimbabwe.rb +31 -31
- data/lib/phony/countries.rb +440 -443
- data/lib/phony/country.rb +42 -44
- data/lib/phony/country_codes.rb +61 -60
- data/lib/phony/dsl.rb +23 -26
- data/lib/phony/local_splitters/fixed.rb +20 -29
- data/lib/phony/local_splitters/regex.rb +28 -31
- data/lib/phony/national_code.rb +7 -10
- data/lib/phony/national_splitters/default.rb +9 -11
- data/lib/phony/national_splitters/dsl.rb +8 -18
- data/lib/phony/national_splitters/fixed.rb +11 -14
- data/lib/phony/national_splitters/none.rb +7 -11
- data/lib/phony/national_splitters/regex.rb +13 -17
- data/lib/phony/national_splitters/variable.rb +36 -38
- data/lib/phony/trunk_code.rb +16 -18
- data/lib/phony/vanity.rb +12 -13
- data/lib/phony.rb +84 -84
- metadata +5 -39
- data/spec/functional/config_spec.rb +0 -44
- data/spec/functional/plausibility_spec.rb +0 -689
- data/spec/lib/phony/countries_spec.rb +0 -1459
- data/spec/lib/phony/country_codes_spec.rb +0 -227
- data/spec/lib/phony/country_spec.rb +0 -104
- data/spec/lib/phony/dsl_spec.rb +0 -28
- data/spec/lib/phony/local_splitters/fixed_spec.rb +0 -56
- data/spec/lib/phony/local_splitters/regex_spec.rb +0 -94
- data/spec/lib/phony/national_code_spec.rb +0 -61
- data/spec/lib/phony/national_splitters/default_spec.rb +0 -34
- data/spec/lib/phony/national_splitters/fixed_spec.rb +0 -45
- data/spec/lib/phony/national_splitters/none_spec.rb +0 -28
- data/spec/lib/phony/national_splitters/regex_spec.rb +0 -23
- data/spec/lib/phony/national_splitters/variable_spec.rb +0 -35
- data/spec/lib/phony/trunk_code_spec.rb +0 -85
- data/spec/lib/phony/vanity_spec.rb +0 -30
- data/spec/lib/phony_spec.rb +0 -70
@@ -1,227 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::CountryCodes do
|
4
|
-
|
5
|
-
let(:countries) { Phony::CountryCodes.instance }
|
6
|
-
|
7
|
-
describe '#plausible?' do
|
8
|
-
it 'raises an error on a too long ccc' do
|
9
|
-
expect do
|
10
|
-
countries.plausible?('+1 868 7620266', ccc: '1868123')
|
11
|
-
end.to raise_error(ArgumentError, %Q{The provided ccc option is too long and includes more than a cc ('1') and ndc ('868'). It also includes '123'.})
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'ccc handling' do
|
16
|
-
it 'splits a ccc correctly' do
|
17
|
-
cc, ndc, *local = countries.split('1868')
|
18
|
-
|
19
|
-
expect(cc).to eq '1'
|
20
|
-
expect(ndc).to eq '868'
|
21
|
-
end
|
22
|
-
it 'splits a ccc correctly' do
|
23
|
-
cc, ndc, *local = countries.split('1868')
|
24
|
-
|
25
|
-
expect(cc).to eq '1'
|
26
|
-
expect(ndc).to eq '868'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#[]' do
|
31
|
-
it 'returns a country' do
|
32
|
-
expect(countries['41'].class).to eq Phony::Country
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#country_for' do
|
37
|
-
it 'returns a country' do
|
38
|
-
expect(countries.send(:country_for, '41').class).to eq Phony::Country
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#countrify' do
|
43
|
-
it 'returns a country' do
|
44
|
-
expect(countries.send(:countrify, '441231212', '41')).to eq '41441231212'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
describe '#countrify!' do
|
48
|
-
it 'in-place replaces the number' do
|
49
|
-
number = '441231212'
|
50
|
-
expect(countries.send(:countrify!, number, '41')).to eq number
|
51
|
-
|
52
|
-
expect(number).to eq '41441231212'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#vanity?' do
|
57
|
-
it 'returns true if so' do
|
58
|
-
expect(countries.vanity?('1800HELLOES')).to eq true
|
59
|
-
end
|
60
|
-
it 'returns false if not' do
|
61
|
-
expect(countries.vanity?('18001234567')).to eq false
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'normalize' do
|
66
|
-
it 'normalizes correctly' do
|
67
|
-
expect(countries.normalize('0041-44-364-35-32')).to eq '41443643532'
|
68
|
-
end
|
69
|
-
it 'normalizes correctly with CC option' do
|
70
|
-
expect(countries.normalize('044-364-35-32', cc: '41')).to eq '41443643532'
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'specific countries' do
|
74
|
-
it 'handles Congo correctly' do
|
75
|
-
expect(countries.normalize('+242 0571 73992')).to eq '242057173992'
|
76
|
-
expect(countries.normalize('+242 2221 15932')).to eq '242222115932'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'formatted' do
|
82
|
-
it 'formats correctly' do
|
83
|
-
expect(countries.formatted('41443643532', :format => :international, :spaces => :-)).to eq '+41-44-364-35-32'
|
84
|
-
end
|
85
|
-
it 'formats correctly' do
|
86
|
-
expect(countries.formatted('41443643532', :format => :international_relative, :spaces => :-)).to eq '0041-44-364-35-32'
|
87
|
-
end
|
88
|
-
it 'formats correctly' do
|
89
|
-
expect(countries.formatted('41443643532', :format => :national, :spaces => :-)).to eq '044-364-35-32'
|
90
|
-
end
|
91
|
-
context 'specific' do
|
92
|
-
it 'formats Ireland correctly' do
|
93
|
-
expect(countries.formatted("3533451234", :format => :national)).to eq '0345 1234'
|
94
|
-
end
|
95
|
-
it 'formats Ireland correctly' do
|
96
|
-
expect(countries.formatted("353411231234", :format => :national)).to eq '041 123 1234'
|
97
|
-
end
|
98
|
-
it 'formats Spain correctly' do
|
99
|
-
expect(countries.formatted("34123456789", :format => :national)).to eq '123 456 789'
|
100
|
-
end
|
101
|
-
it 'formats Cambodia correctly' do
|
102
|
-
expect(countries.formatted('85512239123', :format => :national)).to eq '012 239 123'
|
103
|
-
end
|
104
|
-
it 'formats the US correctly' do
|
105
|
-
expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
|
106
|
-
end
|
107
|
-
it 'formats the US correctly' do
|
108
|
-
expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
|
109
|
-
end
|
110
|
-
end
|
111
|
-
context 'default' do
|
112
|
-
it "should format swiss numbers" do
|
113
|
-
expect(countries.formatted('41443643532')).to eq '+41 44 364 35 32'
|
114
|
-
end
|
115
|
-
it "should format swiss service numbers" do
|
116
|
-
expect(countries.formatted('41800112233')).to eq '+41 800 112 233'
|
117
|
-
end
|
118
|
-
it "should format austrian numbers" do
|
119
|
-
expect(countries.formatted('43198110')).to eq '+43 1 98110'
|
120
|
-
end
|
121
|
-
it "should format american numbers" do
|
122
|
-
expect(countries.formatted('18705551122')).to eq '+1 (870) 555-1122'
|
123
|
-
end
|
124
|
-
it "should format irish numbers" do
|
125
|
-
expect(countries.formatted('35311234567')).to eq '+353 1 123 4567'
|
126
|
-
end
|
127
|
-
end
|
128
|
-
describe "international" do
|
129
|
-
it "should format north american numbers" do
|
130
|
-
expect(countries.formatted('18091231234', :format => :international)).to eq '+1 (809) 123-1234'
|
131
|
-
end
|
132
|
-
it "should format austrian numbers" do
|
133
|
-
expect(countries.formatted('43198110', :format => :international)).to eq '+43 1 98110'
|
134
|
-
end
|
135
|
-
it "should format austrian numbers" do
|
136
|
-
expect(countries.formatted('43198110', :format => :international_absolute)).to eq '+43 1 98110'
|
137
|
-
end
|
138
|
-
it "should format french numbers" do
|
139
|
-
expect(countries.formatted('33142278186', :format => :+)).to eq '+33 1 42 27 81 86'
|
140
|
-
end
|
141
|
-
it "should format austrian numbers" do
|
142
|
-
expect(countries.formatted('43198110', :format => :international_relative)).to eq '0043 1 98110'
|
143
|
-
end
|
144
|
-
it 'should format liechtensteiner numbers' do
|
145
|
-
expect(countries.formatted('4233841148', :format => :international_relative)).to eq '00423 384 11 48'
|
146
|
-
end
|
147
|
-
it "should format irish numbers" do
|
148
|
-
expect(countries.formatted('35311234567', :format => :international)).to eq '+353 1 123 4567'
|
149
|
-
end
|
150
|
-
it "should format luxembourgian numbers" do
|
151
|
-
expect(countries.formatted('352222809', :format => :international)).to eq '+352 22 28 09'
|
152
|
-
end
|
153
|
-
it "should format luxembourgian 4-digit ndc numbers" do
|
154
|
-
expect(countries.formatted('35226222809', :format => :international)).to eq '+352 2622 28 09'
|
155
|
-
end
|
156
|
-
it "should format luxembourgian mobile numbers" do
|
157
|
-
expect(countries.formatted('352621123456', :format => :international)).to eq '+352 621 123 456'
|
158
|
-
end
|
159
|
-
it "should format luxembourgian city numbers" do
|
160
|
-
expect(countries.formatted('3524123456', :format => :international)).to eq '+352 41 23 45 6'
|
161
|
-
end
|
162
|
-
it "should format luxembourgian machine to machine numbers" do
|
163
|
-
expect(countries.formatted('352602112345678', :format => :international)).to eq '+352 6021 12 34 56 78'
|
164
|
-
end
|
165
|
-
it "should format luxembourgian numbers" do
|
166
|
-
expect(countries.formatted('352370431', :format => :international)).to eq '+352 37 04 31'
|
167
|
-
end
|
168
|
-
it "should format luxembourgian numbers" do
|
169
|
-
expect(countries.formatted('35227855', :format => :international)).to eq '+352 27 85 5'
|
170
|
-
end
|
171
|
-
it "should format nigerian lagosian numbers" do
|
172
|
-
expect(countries.formatted('23414480000', :format => :international)).to eq '+234 1 448 0000'
|
173
|
-
end
|
174
|
-
it "should format nigerian beninese numbers" do
|
175
|
-
expect(countries.formatted('23452123456', :format => :international)).to eq '+234 52 123 456'
|
176
|
-
end
|
177
|
-
it "should format nigerian mobile numbers" do
|
178
|
-
expect(countries.formatted('2347061234567', :format => :international)).to eq '+234 706 123 4567'
|
179
|
-
end
|
180
|
-
context 'with no spaces' do
|
181
|
-
it "should format north american numbers" do
|
182
|
-
expect(Phony.formatted('18091231234', :format => :international, :spaces => '')).to eq '+1(809)123-1234'
|
183
|
-
end
|
184
|
-
it "should format austrian numbers" do
|
185
|
-
expect(Phony.formatted('43198110', :format => :international, :spaces => '')).to eq '+43198110'
|
186
|
-
end
|
187
|
-
it "should format austrian numbers" do
|
188
|
-
expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => '')).to eq '+43198110'
|
189
|
-
end
|
190
|
-
it "should format french numbers" do
|
191
|
-
expect(Phony.formatted('33142278186', :format => :+, :spaces => '')).to eq '+33142278186'
|
192
|
-
end
|
193
|
-
it "should format austrian numbers" do
|
194
|
-
expect(Phony.formatted('43198110', :format => :international_relative, :spaces => '')).to eq '0043198110'
|
195
|
-
end
|
196
|
-
it 'should format liechtensteiner numbers' do
|
197
|
-
expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => '')).to eq '004233841148'
|
198
|
-
end
|
199
|
-
end
|
200
|
-
context 'with special spaces' do
|
201
|
-
it "should format swiss numbers" do
|
202
|
-
expect(Phony.formatted('41443643532', :format => :international)).to eq '+41 44 364 35 32'
|
203
|
-
end
|
204
|
-
it "should format north american numbers" do
|
205
|
-
expect(Phony.formatted('18091231234', :format => :international, :spaces => :-)).to eq '+1-(809)-123-1234'
|
206
|
-
end
|
207
|
-
it "should format austrian numbers" do
|
208
|
-
expect(Phony.formatted('43198110', :format => :international, :spaces => :-)).to eq '+43-1-98110'
|
209
|
-
end
|
210
|
-
it "should format austrian numbers" do
|
211
|
-
expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => :-)).to eq '+43-1-98110'
|
212
|
-
end
|
213
|
-
it "should format french numbers" do
|
214
|
-
expect(Phony.formatted('33142278186', :format => :+, :spaces => :-)).to eq '+33-1-42-27-81-86'
|
215
|
-
end
|
216
|
-
it "should format austrian numbers" do
|
217
|
-
expect(Phony.formatted('43198110', :format => :international_relative, :spaces => :-)).to eq '0043-1-98110'
|
218
|
-
end
|
219
|
-
it 'should format liechtensteiner numbers' do
|
220
|
-
expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => :-)).to eq '00423-384-11-48'
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::Country do
|
4
|
-
|
5
|
-
describe 'general' do
|
6
|
-
let(:country) do
|
7
|
-
national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
|
8
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
9
|
-
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
10
|
-
|
11
|
-
Phony::Country.new national_code
|
12
|
-
end
|
13
|
-
describe '#clean' do
|
14
|
-
it 'cleans the number' do
|
15
|
-
expect(country.clean('+41-44-123-12-12')).to eq '41441231212'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
describe '#vanity_to_number' do
|
19
|
-
it 'turns the vanity number into a number' do
|
20
|
-
expect(country.vanity_to_number('1-800-HELLO')).to eq '1-800-43556'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'regression' do
|
26
|
-
describe 'Iceland' do
|
27
|
-
let(:country) do
|
28
|
-
national_splitter = Phony::NationalSplitters::None.instance_for
|
29
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
|
30
|
-
|
31
|
-
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
32
|
-
described_class.new national_code
|
33
|
-
end
|
34
|
-
it 'splits correctly' do
|
35
|
-
expect(country.split('112')).to eq [nil, false, '112']
|
36
|
-
end
|
37
|
-
end
|
38
|
-
describe 'San Marino' do
|
39
|
-
it 'normalizes correctly' do
|
40
|
-
expect(Phony.normalize('+3780549903549')).to eq '3780549903549'
|
41
|
-
end
|
42
|
-
xit 'automatically adds the sole NC' do
|
43
|
-
expect(Phony.normalize('+378903549')).to eq '3780549903549'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
describe 'Japan' do
|
47
|
-
it 'normalizes correctly' do
|
48
|
-
expect(Phony.normalize('+81-03-1234-5634')).to eq '81312345634'
|
49
|
-
expect(Phony.normalize('03-1234-5634', cc: '81')).to eq '81312345634'
|
50
|
-
end
|
51
|
-
it 'formats correctly' do
|
52
|
-
expect(Phony.format('81312345634')).to eq '+81-3-1234-5634'
|
53
|
-
end
|
54
|
-
it 'splits correctly' do
|
55
|
-
expect(Phony.split('81312345634')).to eq %w(81 3 1234 5634)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "without special cases (with switzerland)" do
|
61
|
-
let(:country) do
|
62
|
-
national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
|
63
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
64
|
-
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
65
|
-
|
66
|
-
Phony::Country.new national_code
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "split" do
|
70
|
-
it "should handle ZH" do
|
71
|
-
expect(country.split('443643532')).to eq [nil, '44', '364', '35', '32']
|
72
|
-
end
|
73
|
-
end
|
74
|
-
describe 'normalize' do
|
75
|
-
it "should handle ZH" do
|
76
|
-
expect(country.normalize('0443643532')).to eq '443643532'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "without special cases" do
|
82
|
-
let(:country) do
|
83
|
-
special_national_splitter = Phony::NationalSplitters::Variable.new nil, ['800']
|
84
|
-
special_local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 3]
|
85
|
-
special_code = Phony::NationalCode.new special_national_splitter, special_local_splitter
|
86
|
-
|
87
|
-
national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
|
88
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
89
|
-
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
90
|
-
|
91
|
-
Phony::Country.new special_code, national_code
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "split" do
|
95
|
-
it "should handle ZH" do
|
96
|
-
expect(country.split('443643532')).to eq [nil, '44', '364', '35', '32']
|
97
|
-
end
|
98
|
-
it "should handle 800" do
|
99
|
-
expect(country.split('800333666')).to eq [nil, '800', '333', '666']
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
data/spec/lib/phony/dsl_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Phony::DSL do
|
6
|
-
|
7
|
-
let(:dsl) { described_class.new }
|
8
|
-
|
9
|
-
it 'has a todo' do
|
10
|
-
result = nil
|
11
|
-
|
12
|
-
Phony.define do
|
13
|
-
result = todo.split("123456789012345")
|
14
|
-
end
|
15
|
-
|
16
|
-
expect(result).to eq [nil, false, '123456789012345']
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'match' do
|
20
|
-
it 'checks for ( in regex' do
|
21
|
-
expect { dsl.match(/123/) }.to raise_error("Regexp /123/ needs a group in it that defines which digits belong to the NDC.")
|
22
|
-
end
|
23
|
-
it 'should return a Phony::NationalSplitters::Regex' do
|
24
|
-
expect(dsl.match(/(123)/).class.name).to eq Phony::NationalSplitters::Regex.name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::LocalSplitters::Fixed do
|
4
|
-
|
5
|
-
describe 'instance_for' do
|
6
|
-
it 'caches' do
|
7
|
-
described_class.instance_for([3,2,2]).should equal(described_class.instance_for([3,2,2]))
|
8
|
-
end
|
9
|
-
it 'caches correctly' do
|
10
|
-
described_class.instance_for([1,2,3]).should_not equal(described_class.instance_for([9,9,9]))
|
11
|
-
end
|
12
|
-
it 'caches correctly' do
|
13
|
-
described_class.instance_for.should equal(described_class.instance_for)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'split' do
|
18
|
-
context "without format" do
|
19
|
-
before(:each) do
|
20
|
-
@splitter = described_class.new
|
21
|
-
end
|
22
|
-
it 'splits correctly' do
|
23
|
-
@splitter.split('3643532').should == ['364','35','32']
|
24
|
-
end
|
25
|
-
it 'splits correctly even when the number is too long (but leniently)' do
|
26
|
-
@splitter.split('3643532111').should == ['364','35','32111']
|
27
|
-
end
|
28
|
-
it 'splits correctly even when the number is too short' do
|
29
|
-
@splitter.split('364353').should == ['364','35','3']
|
30
|
-
end
|
31
|
-
end
|
32
|
-
context "with format" do
|
33
|
-
before(:each) do
|
34
|
-
@splitter = described_class.new [3, 2, 2]
|
35
|
-
end
|
36
|
-
it 'splits correctly' do
|
37
|
-
@splitter.split('3643532').should == ['364','35','32']
|
38
|
-
end
|
39
|
-
it 'splits correctly even when the number is too long (but leniently)' do
|
40
|
-
@splitter.split('3643532111').should == ['364','35','32111']
|
41
|
-
end
|
42
|
-
it 'splits correctly even when the number is too short' do
|
43
|
-
@splitter.split('364353').should == ['364','35','3']
|
44
|
-
end
|
45
|
-
end
|
46
|
-
context "with hard number (iceland regression)" do
|
47
|
-
before(:each) do
|
48
|
-
@splitter = described_class.new [3, 4]
|
49
|
-
end
|
50
|
-
it 'splits correctly' do
|
51
|
-
@splitter.split('112').should == ['112']
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
main = self
|
4
|
-
|
5
|
-
describe Phony::LocalSplitters::Regex do
|
6
|
-
|
7
|
-
before do
|
8
|
-
load 'spec_helper_extensions.rb'
|
9
|
-
main.send :include, SpecHelperExtensions
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'instance_for' do
|
13
|
-
it 'does not cache' do
|
14
|
-
described_class.instance_for({}).should_not equal(described_class.instance_for({}))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'split' do
|
19
|
-
# Norway.
|
20
|
-
let(:splitter) { described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2]) }
|
21
|
-
it 'splits a number correctly' do
|
22
|
-
expect(splitter.split('21234567')).to eq ['21','23','45','67']
|
23
|
-
end
|
24
|
-
it 'splits a number correctly' do
|
25
|
-
expect(splitter.split('31234567')).to eq ['31','23','45','67']
|
26
|
-
end
|
27
|
-
it 'splits a number correctly' do
|
28
|
-
expect(splitter.split('41234567')).to eq ['412','34','567']
|
29
|
-
end
|
30
|
-
it 'splits a number correctly' do
|
31
|
-
expect(splitter.split('51234567')).to eq ['51','23','45','67']
|
32
|
-
end
|
33
|
-
it 'splits a number correctly' do
|
34
|
-
expect(splitter.split('61234567')).to eq ['61','23','45','67']
|
35
|
-
end
|
36
|
-
it 'splits a number correctly' do
|
37
|
-
expect(splitter.split('71234567')).to eq ['71','23','45','67']
|
38
|
-
end
|
39
|
-
it 'splits a number correctly' do
|
40
|
-
expect(splitter.split('81234567')).to eq ['812','34','567']
|
41
|
-
end
|
42
|
-
it 'splits a number correctly' do
|
43
|
-
expect(splitter.split('91234567')).to eq ['912','34','567']
|
44
|
-
end
|
45
|
-
it 'splits it fast' do
|
46
|
-
expect(performance_of { splitter.split('21234567') }).to be < 0.00005
|
47
|
-
end
|
48
|
-
it 'splits it fast' do
|
49
|
-
expect(performance_of { splitter.split('91234567') }).to be < 0.00004
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'plausible?' do
|
54
|
-
let(:number) {['123', '456']}
|
55
|
-
let(:result) { local_splitter.plausible?(number) }
|
56
|
-
|
57
|
-
context 'Local splitter without mappings' do
|
58
|
-
let(:local_splitter) { described_class.instance_for({})}
|
59
|
-
it 'returns false' do
|
60
|
-
result.should be_falsey
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'Mapping does not exist for a number' do
|
65
|
-
let(:local_splitter) { described_class.instance_for(/\A5/ => [1,2,3])}
|
66
|
-
it 'returns false' do
|
67
|
-
result.should be_falsey
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "Mapping exists, but the length is greater" do
|
72
|
-
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2])}
|
73
|
-
it 'returns false' do
|
74
|
-
result.should be_falsey
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "Mapping exists, but the length is less" do
|
79
|
-
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,3])}
|
80
|
-
it 'returns false' do
|
81
|
-
result.should be_falsey
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'Mapping exists and the length is equal' do
|
86
|
-
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,2])}
|
87
|
-
it 'returns true' do
|
88
|
-
result.should be_truthy
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::NationalCode do
|
4
|
-
|
5
|
-
describe 'split' do
|
6
|
-
context 'regression' do
|
7
|
-
describe 'iceland' do
|
8
|
-
let(:national) do
|
9
|
-
national_splitter = Phony::NationalSplitters::None.instance_for
|
10
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
|
11
|
-
|
12
|
-
Phony::NationalCode.new national_splitter, local_splitter
|
13
|
-
end
|
14
|
-
it 'splits correctly' do
|
15
|
-
expect(national.split('112')).to eq [nil, false, '112']
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
context 'with fixed ndc (Swiss)' do
|
20
|
-
let(:national) do
|
21
|
-
national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
|
22
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
23
|
-
|
24
|
-
Phony::NationalCode.new national_splitter, local_splitter
|
25
|
-
end
|
26
|
-
it 'splits correctly' do
|
27
|
-
expect(national.split('443643532')).to eq [nil, '44', '364', '35', '32']
|
28
|
-
end
|
29
|
-
it 'splits correctly' do
|
30
|
-
expect(national.split('44364353')).to eq [nil, '44', '364', '35', '3']
|
31
|
-
end
|
32
|
-
it 'normalizes correctly' do
|
33
|
-
expect(national.normalize('044364353')).to eq '44364353'
|
34
|
-
end
|
35
|
-
it 'normalizes correctly' do
|
36
|
-
expect(national.normalize('44364353')).to eq '44364353'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
context 'with fixed ndc (French)' do
|
40
|
-
let(:national) do
|
41
|
-
national_splitter = Phony::NationalSplitters::Fixed.instance_for 1
|
42
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for [2, 2, 2, 2]
|
43
|
-
|
44
|
-
Phony::NationalCode.new national_splitter, local_splitter
|
45
|
-
end
|
46
|
-
it 'splits correctly' do
|
47
|
-
expect(national.split('142278186')).to eq [nil, '1', '42', '27', '81', '86']
|
48
|
-
end
|
49
|
-
it 'splits correctly' do
|
50
|
-
expect(national.split('14227818')).to eq [nil, '1', '42', '27', '81', '8']
|
51
|
-
end
|
52
|
-
it 'normalizes correctly' do
|
53
|
-
expect(national.normalize('0142278186')).to eq '142278186'
|
54
|
-
end
|
55
|
-
it 'normalizes correctly' do
|
56
|
-
expect(national.normalize('142278186')).to eq '142278186'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::NationalSplitters::Default do
|
4
|
-
|
5
|
-
describe 'instance_for' do
|
6
|
-
it 'caches' do
|
7
|
-
described_class.instance_for.should equal(described_class.instance_for)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'with instance' do
|
12
|
-
let(:splitter) { described_class.instance_for }
|
13
|
-
|
14
|
-
describe 'split' do
|
15
|
-
it 'does only pretend split' do
|
16
|
-
splitter.split(:anything).should == [nil, :anything]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'plausible?' do
|
21
|
-
it 'is always plausible' do
|
22
|
-
splitter.plausible?(:anything, :anything).should be_truthy
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'length' do
|
27
|
-
it 'needs to be at least 3' do
|
28
|
-
splitter.length.should == 3
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::NationalSplitters::Fixed do
|
4
|
-
|
5
|
-
describe 'instance_for' do
|
6
|
-
it 'caches' do
|
7
|
-
expect(Phony::NationalSplitters::Fixed.instance_for(3)).to eq Phony::NationalSplitters::Fixed.instance_for(3)
|
8
|
-
end
|
9
|
-
it 'caches correctly' do
|
10
|
-
expect(Phony::NationalSplitters::Fixed.instance_for(1)).to_not eq Phony::NationalSplitters::Fixed.instance_for(2)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'split' do
|
15
|
-
let(:splitter) { Phony::NationalSplitters::Fixed.new(2) }
|
16
|
-
it 'splits correctly' do
|
17
|
-
expect(splitter.split('443643532')).to eq [nil, '44', '3643532']
|
18
|
-
end
|
19
|
-
it 'splits correctly even when the number is too long' do
|
20
|
-
expect(splitter.split('44364353211')).to eq [nil, '44', '364353211']
|
21
|
-
end
|
22
|
-
it 'splits correctly even when the number is too short' do
|
23
|
-
expect(splitter.split('443')).to eq [nil, '44','3']
|
24
|
-
end
|
25
|
-
it 'has a length of 2' do
|
26
|
-
expect(splitter.length).to eq 2
|
27
|
-
end
|
28
|
-
end
|
29
|
-
describe 'split' do
|
30
|
-
let(:splitter) { Phony::NationalSplitters::Fixed.new(nil) }
|
31
|
-
it 'splits correctly' do
|
32
|
-
expect(splitter.split('443643532')).to eq [nil, '443643532']
|
33
|
-
end
|
34
|
-
it 'splits correctly even when the number is too long' do
|
35
|
-
expect(splitter.split('44364353211')).to eq [nil, '44364353211']
|
36
|
-
end
|
37
|
-
it 'splits correctly even when the number is too short' do
|
38
|
-
expect(splitter.split('443')).to eq [nil, '443']
|
39
|
-
end
|
40
|
-
it 'has a length of nil' do
|
41
|
-
expect(splitter.length).to eq nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Phony::NationalSplitters::None do
|
4
|
-
|
5
|
-
describe 'instance_for' do
|
6
|
-
it 'caches' do
|
7
|
-
expect(described_class.instance_for).to eq described_class.instance_for
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'with instance' do
|
12
|
-
let(:splitter) { described_class.instance_for }
|
13
|
-
|
14
|
-
describe 'split' do
|
15
|
-
it 'splits correctly into ndc and rest' do
|
16
|
-
expect(splitter.split('123456789')).to eq [nil, false, '123456789']
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'length' do
|
21
|
-
it 'is always 0' do
|
22
|
-
expect(splitter.length).to be_zero
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|