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