Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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