Skip to content

HTTPS clone URL

Subversion checkout URL

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