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