Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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