Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 290 lines (280 sloc) 11.494 kb
b010a78 Florian R. Hanke + e164 spec
authored
1 # encoding: utf-8
2 #
3 require 'spec_helper'
41cbfce Florian R. Hanke + initial commit
authored
4
cedc4c2 Florian R. Hanke + phony rename
authored
5 describe Phony do
0ab6b39 Florian R. Hanke + refactoring e164
authored
6
41cbfce Florian R. Hanke + initial commit
authored
7 describe "split" do
8 it "should handle austrian numbers" do
cedc4c2 Florian R. Hanke + phony rename
authored
9 Phony.split('43198110').should == ['43', '1', '98110']
41cbfce Florian R. Hanke + initial commit
authored
10 end
28f5cab Florian R. Hanke + Oiii Brasil!
authored
11 it 'handles brazilian numbers' do
12 Phony.split('551112341234').should == ['55', '11', '1234', '1234']
13 end
9c99b67 Florian R. Hanke + Hej Danmark!
authored
14 it 'handles danish numbers' do
15 Phony.split('4532121212').should == ['45', '32', '12', '12', '12']
16 end
28f5cab Florian R. Hanke + Oiii Brasil!
authored
17 it 'handles dutch numbers' do
da33c53 Florian R. Hanke + sweden, yay, + russia, sweden specs
authored
18 Phony.split('31612345678').should == ['31', '6', '12345678'] # mobile
f01d580 Florian R. Hanke + first draft for the netherlands
authored
19 Phony.split('31201234567').should == ['31', '20', '1234567']
da33c53 Florian R. Hanke + sweden, yay, + russia, sweden specs
authored
20 Phony.split('31222123456').should == ['31', '222', '123456']
f01d580 Florian R. Hanke + first draft for the netherlands
authored
21 end
332d1bd Florian R. Hanke + egyptian splitting
authored
22 it "should handle egyptian numbers" do
03f78b6 Florian R. Hanke + egyptian specs
authored
23 Phony.split('20212345678').should == ['20', '2', '12345678']
24 Phony.split('20951234567').should == ['20', '95', '1234567']
332d1bd Florian R. Hanke + egyptian splitting
authored
25 end
41cbfce Florian R. Hanke + initial commit
authored
26 it "should handle french numbers" do
cedc4c2 Florian R. Hanke + phony rename
authored
27 Phony.split('33112345678').should == ['33', '1', '12','34','56','78']
41cbfce Florian R. Hanke + initial commit
authored
28 end
31085d7 Florian R. Hanke + README, + gem, + Rakefile, + gemspec, + setup
authored
29 it "should handle german numbers" do
4948138 Florian R. Hanke + german spec
authored
30 Phony.split('4930123456').should == ['49', '30', '123', '456']
cedc4c2 Florian R. Hanke + phony rename
authored
31 Phony.split('4976112345').should == ['49', '761', '123', '45']
41cbfce Florian R. Hanke + initial commit
authored
32 end
29ea6bb Florian R. Hanke + greece
authored
33 it "should handle greek numbers" do
34 Phony.split('3022631234').should == ['30', '2263', '1234']
35 end
7a40c1c Florian R. Hanke + hungarian numbers, swiss specs
authored
36 it "should handle hungarian numbers" do
37 Phony.split('3612345678').should == ['36', '1', '234', '5678']
38 end
0fa7caa Florian R. Hanke + Polish numbers :)
authored
39 it "should handle italian numbers" do
9b37d4c Florian R. Hanke + italian phone numbers
authored
40 Phony.split('3928061371').should == ['39', '2', '806', '1371']
41cbfce Florian R. Hanke + initial commit
authored
41 end
0c193a4 Florian R. Hanke + Hola Peru!
authored
42 it 'handles peruvian numbers' do
43 Phony.split('51112341234').should == ['51', '1', '1234', '1234'] # Lima
44 Phony.split('51912341234').should == ['51', '9', '1234', '1234'] # mobile
45 Phony.split('51841234123').should == ['51', '84', '1234', '123'] # Cuzco, best effort
46 end
0fa7caa Florian R. Hanke + Polish numbers :)
authored
47 it "should handle polish numbers" do
48 Phony.split('48121123123').should == ['48', '12', '1', '123', '123']
49 end
e32f33e Florian R. Hanke + romania, best effort, + 1.1.3
authored
50 it 'handles romanian numbers' do
0c193a4 Florian R. Hanke + Hola Peru!
authored
51 Phony.split('40211231234').should == ['40', '21', '123', '1234'] # Bucureşti
52 Phony.split('40721231234').should == ['40', '72', '123', '1234'] # mobile
53 Phony.split('40249123123').should == ['40', '249', '123', '123'] # Olt
54 end
55 it 'handles russian numbers' do
56 Phony.split('78122345678').should == ['7', '812', '234', '56', '78']
e32f33e Florian R. Hanke + romania, best effort, + 1.1.3
authored
57 end
da33c53 Florian R. Hanke + sweden, yay, + russia, sweden specs
authored
58 it "should handle swedish numbers" do
59 Phony.split('46812345678').should == ['46', '8', '12345678']
60 Phony.split('46111234567').should == ['46', '11', '1234567']
61 Phony.split('46125123456').should == ['46', '125', '123456']
62 end
41cbfce Florian R. Hanke + initial commit
authored
63 it "should handle swiss numbers" do
cedc4c2 Florian R. Hanke + phony rename
authored
64 Phony.split('41443643532').should == ['41', '44', '364', '35', '32']
41cbfce Florian R. Hanke + initial commit
authored
65 end
66 it "should handle US numbers" do
cedc4c2 Florian R. Hanke + phony rename
authored
67 Phony.split('15551115511').should == ['1', '555', '111', '5511']
41cbfce Florian R. Hanke + initial commit
authored
68 end
69 it "should handle new zealand numbers" do
cedc4c2 Florian R. Hanke + phony rename
authored
70 Phony.split('6491234567').should == ['64', '9', '123', '4567']
41cbfce Florian R. Hanke + initial commit
authored
71 end
7a40c1c Florian R. Hanke + hungarian numbers, swiss specs
authored
72
a6fb758 Florian R. Hanke + service numbers use the same local format as the rest of the numbers b...
authored
73 it "should handle french service numbers" do
74 Phony.split('33812345678').should == ['33', '8', '12','34','56','78']
75 end
83d2d66 Florian R. Hanke + local splitter
authored
76 it "should handle swiss service numbers" do
59f0936 Florian R. Hanke + specs all run
authored
77 Phony.split('41800334455').should == ['41', '800', '334', '455']
83d2d66 Florian R. Hanke + local splitter
authored
78 end
98cc263 Florian R. Hanke + vanity, normalize
authored
79 end
80
81 describe "normalize" do
82 describe "some examples" do
83 it "should normalize an already normalized number" do
84 Phony.normalize('41443643533').should == '41443643533'
85 end
86 it "should normalize a formatted number" do
87 Phony.normalize('+41 44 364 35 33').should == '41443643533'
88 end
89 it "should normalize a formatted number" do
90 Phony.normalize('+41 44 364 35 33').should == '41443643533'
91 end
92 it "should normalize a service number" do
93 Phony.normalize('+41 800 11 22 33').should == '41800112233'
94 end
95 it "should remove characters from the number" do
96 Phony.normalize('John: +41 44 364 35 33').should == '41443643533'
97 end
98 it "should normalize one of these crazy american numbers" do
99 Phony.normalize('1 (703) 451-5115').should == '17034515115'
100 end
101 it "should normalize another one of these crazy american numbers" do
102 Phony.normalize('1-888-407-4747').should == '18884074747'
103 end
104 it "should normalize a number with colons" do
105 Phony.normalize('1.906.387.1698').should == '19063871698'
106 end
107 it "should normalize a number with optional ndc" do
108 Phony.normalize('+41 (044) 364 35 33').should == '41443643533'
109 end
110 it "should normalize a number with erroneous zero inside" do
111 Phony.normalize('+410443643533').should == '41443643533'
112 end
147ea5f Andi Schacke + Strategy Pattern for FixedSplitter to handle Special Services numbers
andi authored
113 end
41cbfce Florian R. Hanke + initial commit
authored
114 end
c0a9f79 Florian R. Hanke + doc, + lots of specs
authored
115
b742c4f Florian R. Hanke + cleanup
authored
116 describe "formatted" do
117 describe "default" do
118 it "should format swiss numbers" do
119 Phony.formatted('41443643532').should == '+41 44 364 35 32'
120 end
83d2d66 Florian R. Hanke + local splitter
authored
121 # TODO
122 #
b742c4f Florian R. Hanke + cleanup
authored
123 it "should format swiss service numbers" do
59f0936 Florian R. Hanke + specs all run
authored
124 Phony.formatted('41800112233').should == '+41 800 112 233'
b742c4f Florian R. Hanke + cleanup
authored
125 end
126 it "should format austrian numbers" do
127 Phony.formatted('43198110').should == '+43 1 98110'
128 end
129 it "should format american numbers" do
130 Phony.formatted('18705551122').should == '+1 870 555 1122'
131 end
132 end
133 describe "international" do
134 it "should format north american numbers" do
135 Phony.formatted('18091231234', :format => :international).should == '+1 809 123 1234'
136 end
137 it "should format austrian numbers" do
138 Phony.formatted('43198110', :format => :international).should == '+43 1 98110'
139 end
140 it "should format austrian numbers" do
141 Phony.formatted('43198110', :format => :international_absolute).should == '+43 1 98110'
142 end
143 it "should format french numbers" do
144 Phony.formatted('33142278186', :format => :+).should == '+33 1 42 27 81 86'
145 end
146 it "should format austrian numbers" do
147 Phony.formatted('43198110', :format => :international_relative).should == '0043 1 98110'
148 end
149 it 'should format liechtensteiner numbers' do
150 Phony.formatted('4233841148', :format => :international_relative).should == '00423 384 11 48'
151 end
152 context 'with no spaces' do
153 it "should format north american numbers" do
154 Phony.formatted('18091231234', :format => :international, :spaces => '').should == '+18091231234'
155 end
156 it "should format austrian numbers" do
157 Phony.formatted('43198110', :format => :international, :spaces => '').should == '+43198110'
158 end
159 it "should format austrian numbers" do
160 Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'
161 end
162 it "should format french numbers" do
163 Phony.formatted('33142278186', :format => :+, :spaces => '').should == '+33142278186'
164 end
165 it "should format austrian numbers" do
166 Phony.formatted('43198110', :format => :international_relative, :spaces => '').should == '0043198110'
167 end
168 it 'should format liechtensteiner numbers' do
169 Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should == '004233841148'
170 end
171 end
172 context 'with special spaces' do
173 it "should format swiss numbers" do
174 Phony.formatted('41443643532', :format => :international).should == '+41 44 364 35 32'
175 end
176 it "should format north american numbers" do
177 Phony.formatted('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'
178 end
179 it "should format austrian numbers" do
180 Phony.formatted('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'
181 end
182 it "should format austrian numbers" do
183 Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'
184 end
185 it "should format french numbers" do
186 Phony.formatted('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'
187 end
188 it "should format austrian numbers" do
189 Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'
190 end
191 it 'should format liechtensteiner numbers' do
192 Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'
193 end
194 end
195 end
196 describe "national" do
197 it "should format swiss numbers" do
198 Phony.formatted('41443643532', :format => :national).should == '044 364 35 32'
199 end
83d2d66 Florian R. Hanke + local splitter
authored
200 # TODO
201 #
b742c4f Florian R. Hanke + cleanup
authored
202 it "should format swiss service numbers" do
40e77a8 Florian R. Hanke + intermediate commit
authored
203 Phony.formatted('41800112233', :format => :national).should == '0800 112 233'
b742c4f Florian R. Hanke + cleanup
authored
204 end
205 it "should format austrian numbers" do
206 Phony.formatted('43198110', :format => :national).should == '01 98110'
207 end
208 end
209 describe "local" do
210 it "should format swiss numbers" do
211 Phony.formatted('41443643532', :format => :local).should == '364 35 32'
212 end
213 it "should format german numbers" do
214 Phony.formatted('493038625454', :format => :local).should == '386 25454'
215 end
216 end
217 end
98cc263 Florian R. Hanke + vanity, normalize
authored
218
eda887f Florian R. Hanke + more speed specs
authored
219 context "speed" do
a050691 Florian R. Hanke + speed specs
authored
220 before(:each) do
221 @phone_numbers = [
222 '41443643532',
223 '18091231234',
224 '43198110',
225 '33142278186',
226 '4233841148'
227 ]
228 end
eda887f Florian R. Hanke + more speed specs
authored
229 describe 'split' do
230 it 'is fast' do
e807d5c Florian R. Hanke + single speed specs, - GC involvement
authored
231 number = @phone_numbers.first
232 performance_of { Phony.split(number) }.should < 0.00005
233 end
234 it 'is fast' do
eda887f Florian R. Hanke + more speed specs
authored
235 performance_of { @phone_numbers.each { |number| Phony.split(number) } }.should < 0.00015
236 end
237 end
238 describe 'normalize' do
239 it 'is fast' do
e807d5c Florian R. Hanke + single speed specs, - GC involvement
authored
240 number = @phone_numbers.first
d7e9305 Florian R. Hanke + normalize is not consistently fast
authored
241 performance_of { Phony.normalize(number) }.should < 0.0001
e807d5c Florian R. Hanke + single speed specs, - GC involvement
authored
242 end
243 it 'is fast' do
eda887f Florian R. Hanke + more speed specs
authored
244 performance_of { @phone_numbers.each { |number| Phony.normalize(number) } }.should < 0.00015
245 end
246 end
247 describe 'formatted' do
248 it 'is fast' do
e807d5c Florian R. Hanke + single speed specs, - GC involvement
authored
249 number = @phone_numbers.first
250 performance_of { Phony.formatted(number) }.should < 0.000075
251 end
252 it 'is fast' do
eda887f Florian R. Hanke + more speed specs
authored
253 performance_of { @phone_numbers.each { |number| Phony.formatted(number) } }.should < 0.00015
254 end
a050691 Florian R. Hanke + speed specs
authored
255 end
256 end
257
59f0936 Florian R. Hanke + specs all run
authored
258 # describe "service?" do
259 #
260 # end
261 # describe "mobile?" do
262 # # TODO Test dirty numbers.
263 # #
264 # it 'is correct' do
265 # Phony.mobile?('49172123456').should == true
266 # end
267 # it 'is correct' do
268 # Phony.mobile?('12172123456').should == false
269 # end
270 # end
03dc48d Florian R. Hanke - old code (80% replaced), + preparation for new features
authored
271
525e5f5 Florian R. Hanke + vanity number handling
authored
272 describe 'vanity' do
273 describe 'vanity_number?' do
274 it {Phony.vanity?('41800 WEGGLI').should be_true}
275 it {Phony.vanity?('41800WEGGLI').should be_true}
276 it {Phony.vanity?('41848 SUCCESSMATCH').should be_true}
277 it {Phony.vanity?('4180 NO NO NO').should be_false}
278 it {Phony.vanity?('41900 KURZ').should be_false}
279 it {Phony.vanity?('41 44 364 35 32').should be_false}
280 end
281
282 describe 'vanity_to_number' do
283 it {Phony.vanity_to_number('41800WEGGLI').should == '41800934454'}
284 it {Phony.vanity_to_number('41800weggli').should == '41800934454'}
285 it {Phony.vanity_to_number('41800SUCCESSMATCH').should == '41800782237'} # Cut off according to the swiss norms.
286 it {Phony.vanity_to_number('4180BLA').should == '4180252'} # Does not check for validity of number.
287 end
288 end
41cbfce Florian R. Hanke + initial commit
authored
289
290 end
Something went wrong with that request. Please try again.