phony 2.19.2 → 2.20.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.textile +5 -1
- data/lib/phony/countries/brazil.rb +2 -2
- data/lib/phony/countries/italy.rb +34 -16
- data/lib/phony/countries/japan.rb +51 -2
- data/lib/phony/countries/libya.rb +1 -1
- data/lib/phony/countries/taiwan.rb +1 -0
- data/lib/phony/countries/vietnam.rb +3 -0
- data/lib/phony/countries.rb +72 -36
- data/lib/phony/country.rb +4 -0
- data/lib/phony/country_codes.rb +14 -1
- data/lib/phony/local_splitters/fixed.rb +2 -0
- data/lib/phony/national_splitters/none.rb +1 -3
- data/spec/functional/config_spec.rb +5 -5
- data/spec/functional/plausibility_spec.rb +71 -17
- data/spec/lib/phony/countries_spec.rb +42 -15
- data/spec/lib/phony/country_codes_spec.rb +78 -55
- data/spec/lib/phony/country_spec.rb +13 -13
- data/spec/lib/phony/dsl_spec.rb +6 -2
- data/spec/lib/phony/local_splitters/regex_spec.rb +12 -15
- data/spec/lib/phony/national_code_spec.rb +15 -45
- data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
- data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
- data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
- data/spec/lib/phony/vanity_spec.rb +4 -4
- metadata +15 -15
@@ -25,11 +25,11 @@ describe 'plausibility' do
|
|
25
25
|
incorrect = [shortest.sub(/\d\s*\z/, '')] # , longest + '0']
|
26
26
|
|
27
27
|
correct.each do |value|
|
28
|
-
Phony.plausible?(value).
|
28
|
+
expect(Phony.plausible?(value)).to be_truthy,
|
29
29
|
"It should validate #{value}, but does not."
|
30
30
|
end
|
31
31
|
incorrect.each do |value|
|
32
|
-
Phony.plausible?(value).
|
32
|
+
expect(Phony.plausible?(value)).to be_falsey,
|
33
33
|
"It should not validate #{value}, but does."
|
34
34
|
end
|
35
35
|
end
|
@@ -38,7 +38,7 @@ describe 'plausibility' do
|
|
38
38
|
invalid = [*sample]
|
39
39
|
|
40
40
|
invalid.each do |value|
|
41
|
-
Phony.plausible?(value).
|
41
|
+
expect(Phony.plausible?(value)).to be_falsey,
|
42
42
|
"It should not validate #{value}, but does."
|
43
43
|
end
|
44
44
|
end
|
@@ -51,6 +51,14 @@ describe 'plausibility' do
|
|
51
51
|
it_is_correct_for 'Bosnia and Herzegovina', :samples => ['+387 66 666 666',
|
52
52
|
'+387 37 123 456',
|
53
53
|
'+387 33 222 111']
|
54
|
+
it 'is correct for Brasil' do
|
55
|
+
Phony.plausible?('+55 67 998280912').should be_truthy
|
56
|
+
Phony.plausible?('+55 67 98280912').should be_falsey
|
57
|
+
Phony.plausible?('+55 11 12345678').should be_falsey
|
58
|
+
Phony.plausible?('+55 11 123456789').should be_falsey
|
59
|
+
Phony.plausible?('+55 11 023456789').should be_falsey
|
60
|
+
Phony.plausible?('+55 11 22345678').should be_truthy
|
61
|
+
end
|
54
62
|
it 'is correct for Bulgaria' do
|
55
63
|
Phony.plausible?('+359 2 1234567').should be_truthy
|
56
64
|
Phony.plausible?('+359 30 12345').should be_truthy
|
@@ -179,6 +187,14 @@ describe 'plausibility' do
|
|
179
187
|
Phony.plausible?('+359 998 123456').should be_truthy
|
180
188
|
Phony.plausible?('+359 999 123456').should be_truthy
|
181
189
|
end
|
190
|
+
it_is_correct_for 'Colombia', :samples => ['+57 601 411 1899',
|
191
|
+
'+57 602 111 2222',
|
192
|
+
'+57 603 111 2222',
|
193
|
+
'+57 604 111 2222',
|
194
|
+
'+57 605 111 2222',
|
195
|
+
'+57 606 111 2222',
|
196
|
+
'+57 607 111 2222',
|
197
|
+
'+57 608 111 2222']
|
182
198
|
it_is_correct_for 'Congo', :samples => '+242 1234 56789'
|
183
199
|
it_is_correct_for 'Cook Islands', :samples => '+682 71928'
|
184
200
|
it_is_correct_for 'Costa Rica', :samples => '+506 2 234 5678'
|
@@ -285,7 +301,7 @@ describe 'plausibility' do
|
|
285
301
|
'+964 71 1234 5678']
|
286
302
|
|
287
303
|
|
288
|
-
it_is_correct_for 'Kiribati (Republic of)', :samples => '+686
|
304
|
+
it_is_correct_for 'Kiribati (Republic of)', :samples => '+686 34814527'
|
289
305
|
it_is_correct_for "Democratic People's Republic of Korea", :samples => ['+850 2 123 45',
|
290
306
|
'+850 2 123 456 789',
|
291
307
|
'+850 2 381 2356',
|
@@ -324,10 +340,19 @@ describe 'plausibility' do
|
|
324
340
|
it_is_correct_for 'Macedonia', :samples => ['+389 2 123 4567',
|
325
341
|
'+389 7 124 3456',
|
326
342
|
'+389 7 234 5678']
|
327
|
-
it_is_correct_for 'Madagascar', :samples => ['+261 20
|
328
|
-
'+261
|
329
|
-
'+261
|
330
|
-
'+261
|
343
|
+
it_is_correct_for 'Madagascar', :samples => ['+261 20 23 456 78',
|
344
|
+
'+261 32 34 546 78',
|
345
|
+
'+261 33 34 546 78',
|
346
|
+
'+261 34 34 546 78',
|
347
|
+
'+261 38 34 546 78']
|
348
|
+
it 'is incorrect for Madagascar' do
|
349
|
+
Phony.plausible?('+261 20 012 345 678').should be_falsey
|
350
|
+
Phony.plausible?('+261 20 12 434 569').should be_falsey
|
351
|
+
Phony.plausible?('+261 51 23 4567 8').should be_falsey
|
352
|
+
Phony.plausible?('+261 34 345 46789').should be_falsey
|
353
|
+
Phony.plausible?('+261 34 345 467').should be_falsey
|
354
|
+
end
|
355
|
+
|
331
356
|
it_is_correct_for 'Malawi', :samples => ['+265 1725 123',
|
332
357
|
'+265 213 456 789',
|
333
358
|
'+265 9123 456',
|
@@ -338,7 +363,8 @@ describe 'plausibility' do
|
|
338
363
|
it_is_correct_for 'Marshall Islands (Republic of the)', :samples => '+692 372 7183'
|
339
364
|
it_is_correct_for 'Martinique (French Department of)', :samples => '+596 596 123 456'
|
340
365
|
it_is_correct_for 'Mauritania', :samples => '+222 1234 5678'
|
341
|
-
it_is_correct_for 'Mauritius', :samples => '+230
|
366
|
+
it_is_correct_for 'Mauritius', :samples => ['+230 5 695 2277',
|
367
|
+
'+230 260 0070']
|
342
368
|
it_is_correct_for 'Micronesia (Federated States of)', :samples => '+691 766 7914'
|
343
369
|
it_is_correct_for 'Moldova', :samples => ['+373 800 123 45',
|
344
370
|
'+373 22 123 345',
|
@@ -507,7 +533,10 @@ describe 'plausibility' do
|
|
507
533
|
it_is_correct_for 'Lybia', :samples => ['+218 205 123 45',
|
508
534
|
'+218 22 123 456',
|
509
535
|
'+218 21 1234 456',
|
510
|
-
'+218 91 1234 456'
|
536
|
+
'+218 91 1234 456',
|
537
|
+
'+218 92 1234 456',
|
538
|
+
'+218 94 1234 456',
|
539
|
+
'+218 95 1234 456']
|
511
540
|
it_is_correct_for 'Mongolia', :samples => ['+976 11 123 45',
|
512
541
|
['+976 121 12 34', '+976 121 12 345'],
|
513
542
|
'+976 70 123 456',
|
@@ -561,19 +590,21 @@ describe 'plausibility' do
|
|
561
590
|
'+598 805 123 45']
|
562
591
|
it_is_correct_for 'Vietnam', :samples => ['+84 24 41234567',
|
563
592
|
'+84 28 41234567',
|
564
|
-
'+84 23 61234567'
|
593
|
+
'+84 23 61234567',
|
594
|
+
'+84 1900 1212',
|
595
|
+
'+84 1900 541234']
|
565
596
|
it_is_correct_for 'Yemen', :samples => [['+967 1 234 567', '+967 1 234 5678'],
|
566
597
|
'+967 7 234 567',
|
567
598
|
'+967 77 123 4567',
|
568
599
|
'+967 58 1234']
|
569
600
|
it 'is correct for Zambia' do
|
570
601
|
Phony.plausible?('+260 211 123456').should be_truthy # Fixed
|
571
|
-
Phony.plausible?('+260
|
572
|
-
Phony.plausible?('+260
|
573
|
-
Phony.plausible?('+260
|
574
|
-
Phony.plausible?('+260
|
575
|
-
Phony.plausible?('+260
|
576
|
-
Phony.plausible?('+260
|
602
|
+
Phony.plausible?('+260 96 512 4567').should be_truthy # MTN Mobile
|
603
|
+
Phony.plausible?('+260 97 712 3456').should be_truthy # Airtel Mobile
|
604
|
+
Phony.plausible?('+260 95 512 4567').should be_truthy # Zamtel Mobile
|
605
|
+
Phony.plausible?('+260 96 512 456').should be_falsy # MTN Mobile (Too short)
|
606
|
+
Phony.plausible?('+260 97 812 345').should be_falsy # Airtel Mobile (Too short)
|
607
|
+
Phony.plausible?('+260 95 512 345').should be_falsy # Zamtel Mobile (Too short)
|
577
608
|
Phony.plausible?('+260 800 123 456').should be_truthy # Toll free
|
578
609
|
end
|
579
610
|
it_is_correct_for 'Zimbabwe', :samples => [['+263 2582 123 456', '+263 2582 123'],
|
@@ -589,6 +620,29 @@ describe 'plausibility' do
|
|
589
620
|
Phony.plausible?('+62 22 000 000 000').should be_truthy
|
590
621
|
end
|
591
622
|
|
623
|
+
it 'is correct for Italy' do
|
624
|
+
Phony.plausible?('+39 0574 123').should be_falsy
|
625
|
+
Phony.plausible?('+39 0574 1234').should be_truthy
|
626
|
+
Phony.plausible?('+39 0574 12345').should be_falsy
|
627
|
+
|
628
|
+
Phony.plausible?('+39 085 541').should be_falsy
|
629
|
+
Phony.plausible?('+39 085 5410').should be_truthy
|
630
|
+
Phony.plausible?('+39 085 54105').should be_truthy
|
631
|
+
|
632
|
+
Phony.plausible?('+39 06 4991').should be_falsy
|
633
|
+
Phony.plausible?('+39 06 49911').should be_truthy
|
634
|
+
Phony.plausible?('+39 06 499112').should be_truthy
|
635
|
+
|
636
|
+
Phony.plausible?('+39 800 081631').should be_truthy
|
637
|
+
Phony.plausible?('+39 800 0816311').should be_falsy
|
638
|
+
|
639
|
+
Phony.plausible?('+39 803 08163').should be_falsy
|
640
|
+
Phony.plausible?('+39 803 081').should be_truthy
|
641
|
+
|
642
|
+
Phony.plausible?('+39 06 8323074181').should be_falsy
|
643
|
+
Phony.plausible?('+39 06 832307418').should be_truthy
|
644
|
+
end
|
645
|
+
|
592
646
|
it 'is correct for Russia' do
|
593
647
|
Phony.plausible?('+7 3522 000 000').should be_truthy
|
594
648
|
end
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe 'country descriptions' do
|
6
6
|
|
7
7
|
def self.it_splits number, expected
|
8
|
-
it { Phony.split(number).
|
8
|
+
it { expect(Phony.split(number)).to eq expected }
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'regression' do
|
@@ -110,6 +110,7 @@ describe 'country descriptions' do
|
|
110
110
|
it_splits '32466123456', ['32', '466', '12', '34', '56'] # mobile (Vectone)
|
111
111
|
it_splits '32467123456', ['32', '467', '12', '34', '56'] # mobile (Telenet)
|
112
112
|
it_splits '32468123456', ['32', '468', '12', '34', '56'] # mobile (Telenet)
|
113
|
+
it_splits '32469123456', ['32', '469', '12', '34', '56'] # mobile ()
|
113
114
|
it_splits '32475123456', ['32', '475', '12', '34', '56'] # mobile (Proximus)
|
114
115
|
it_splits '32485123456', ['32', '485', '12', '34', '56'] # mobile (Telenet)
|
115
116
|
it_splits '32495123456', ['32', '495', '12', '34', '56'] # mobile (Orange)
|
@@ -146,9 +147,8 @@ describe 'country descriptions' do
|
|
146
147
|
end
|
147
148
|
|
148
149
|
describe 'Brazil' do
|
149
|
-
it_splits '
|
150
|
+
it_splits '551122341234', ['55', '11', '2234', '1234']
|
150
151
|
it_splits '5511981231234', ['55', '11', '98123', '1234'] # São Paulo's 9 digits mobile
|
151
|
-
it_splits '552181231234', ['55', '21', '8123', '1234']
|
152
152
|
it_splits '5521981231234', ['55', '21', '98123', '1234'] # Rio de Janeiro's 9 digits mobile
|
153
153
|
it_splits '551931311234', ['55', '19', '3131', '1234']
|
154
154
|
it_splits '5531991311234', ['55', '31', '99131', '1234'] # Belo Horizonte's 9th digit
|
@@ -156,6 +156,7 @@ describe 'country descriptions' do
|
|
156
156
|
it_splits '5579991311234', ['55', '79', '99131', '1234'] # Sergipe's 9th digit
|
157
157
|
it_splits '5547991311234', ['55', '47', '99131', '1234'] # Santa Catarina's 9th digit
|
158
158
|
it_splits '5541991311234', ['55', '41', '99131', '1234'] # Parana's 9th digit
|
159
|
+
it_splits '556734212121', ['55', '67', '3421', '2121']
|
159
160
|
|
160
161
|
context 'mobile numbers' do
|
161
162
|
%w{
|
@@ -239,7 +240,7 @@ describe 'country descriptions' do
|
|
239
240
|
end
|
240
241
|
end
|
241
242
|
describe 'Colombia' do
|
242
|
-
it_splits '5711234567', ['57', '1', '123', '4567']
|
243
|
+
it_splits '5711234567', ['57', '1', '123', '4567'] # Outdated.
|
243
244
|
it_splits '573101234567', ['57', '310', '123', '4567'] # mobile
|
244
245
|
end
|
245
246
|
describe 'Croatia' do
|
@@ -459,8 +460,9 @@ describe 'country descriptions' do
|
|
459
460
|
it_splits '3934869528123',['39', '348', '695', '2812', '3'] # Mobile (8-digit subscriber no - new)
|
460
461
|
it_splits '393357210488', ['39', '335', '721', '0488'] # Mobile
|
461
462
|
it_splits '393248644272', ['39', '324', '864', '4272'] # Mobile
|
462
|
-
it_splits '
|
463
|
-
it_splits '
|
463
|
+
it_splits '390612341', ['39', '06', '12341'] # Roma 5 digit
|
464
|
+
it_splits '3906123412', ['39', '06', '1234', '12'] # Roma 6 digit
|
465
|
+
it_splits '39061234123', ['39', '06', '1234', '123'] # Roma 7 digit
|
464
466
|
it_splits '390612341234', ['39', '06', '1234', '1234'] # Roma 8 digit
|
465
467
|
it_splits '3902888388', ['39', '02', '8883', '88'] # Milano 6 digit
|
466
468
|
it_splits '39028883888', ['39', '02', '8883', '888'] # Milano 7 digit
|
@@ -469,6 +471,7 @@ describe 'country descriptions' do
|
|
469
471
|
it_splits '3903123391', ['39', '031', '23391'] # Como
|
470
472
|
it_splits '390909709511', ['39', '090', '9709511'] # Barcellona
|
471
473
|
it_splits '390471811353', ['39', '0471', '811', '353'] # Bolzano
|
474
|
+
it_splits '3905745730', ['39', '0574', '5730'] # Prato
|
472
475
|
end
|
473
476
|
describe 'Japan' do
|
474
477
|
it_splits '81312345678', %w(81 3 1234 5678) # Tokyo
|
@@ -525,6 +528,8 @@ describe 'country descriptions' do
|
|
525
528
|
it_splits '352545258', ['352', '54', '52', '58']
|
526
529
|
it_splits '352818181', ['352', '81', '81', '81']
|
527
530
|
it_splits '3523572141', ['352', '35', '72', '14', '1']
|
531
|
+
it_splits '3522634731', ['352', '26', '34', '73', '1']
|
532
|
+
it_splits '352264412701', ['352', '26', '44', '12', '701']
|
528
533
|
end
|
529
534
|
describe 'Macedonia' do
|
530
535
|
it_splits '38921234567', ['389', '2', '123', '4567'] # Skopje
|
@@ -590,6 +595,10 @@ describe 'country descriptions' do
|
|
590
595
|
it_splits '31222123456', ['31', '222', '123', '456']
|
591
596
|
it_splits '3197012345678', ['31', '970', '1234', '5678'] # machine-to-machine
|
592
597
|
end
|
598
|
+
describe 'Norfolk Island' do
|
599
|
+
it_splits '672321234', ['672', '3', '21', '234'] # fixed
|
600
|
+
it_splits '672351234', ['672', '3', '51', '234'] # mobile
|
601
|
+
end
|
593
602
|
describe 'Norway' do
|
594
603
|
it_splits '4721234567', ['47',false,'21','23','45','67']
|
595
604
|
it_splits '4731234567', ['47',false,'31','23','45','67']
|
@@ -762,6 +771,7 @@ describe 'country descriptions' do
|
|
762
771
|
describe 'Switzerland' do
|
763
772
|
it_splits '41443643532', ['41', '44', '364', '35', '32'] # Zurich (usually)
|
764
773
|
it_splits '41800334455', ['41', '800', '334', '455'] # Service number
|
774
|
+
it_splits '41860443643532', ['41', '860', '44', '364', '35', '32'] # Voicemail access
|
765
775
|
it_splits '41900123456', ['41', '900', '123', '456'] # Business Number
|
766
776
|
it_splits '41901123456', ['41', '901', '123', '456'] # Business Number Entertainment
|
767
777
|
it_splits '41906123456', ['41', '906', '123', '456'] # Business Number Adult Entertainment
|
@@ -847,12 +857,14 @@ describe 'country descriptions' do
|
|
847
857
|
it_splits '842841234567', ['84', '28', '4123', '4567'] # Ho Chi Minh City
|
848
858
|
it_splits '84341234567', ['84', '34', '1234567'] # Viettel
|
849
859
|
it_splits '84841234567', ['84', '84', '1234567'] # Vinaphone
|
860
|
+
it_splits '8419001212', ['84', '1900', '1212'] # Vinaphone
|
861
|
+
it_splits '841900541234', ['84', '1900', '541234'] # Vinaphone
|
850
862
|
end
|
851
863
|
describe 'Zambia' do
|
852
864
|
it_splits '260211123456', ['260', '211', '123456'] # Fixed
|
853
|
-
it_splits '260955123456', ['260', '
|
854
|
-
it_splits '260967123456', ['260', '
|
855
|
-
it_splits '260978123456', ['260', '
|
865
|
+
it_splits '260955123456', ['260', '95', '512', '3456'] # Mobile
|
866
|
+
it_splits '260967123456', ['260', '96', '712', '3456'] # Mobile
|
867
|
+
it_splits '260978123456', ['260', '97', '812', '3456'] # Mobile
|
856
868
|
it_splits '260800123456', ['260', '800', '123', '456'] # Toll free
|
857
869
|
end
|
858
870
|
describe 'New Zealand' do
|
@@ -867,7 +879,8 @@ describe 'country descriptions' do
|
|
867
879
|
it_splits '6737932744', %w(673 7 932 744)
|
868
880
|
end
|
869
881
|
describe 'Burkina Faso' do
|
870
|
-
it_splits '22667839323', ['226', false, '
|
882
|
+
it_splits '22667839323', ['226', false, '67', '83', '93', '23']
|
883
|
+
it_splits '22601234567', ['226', false, '01', '23', '45', '67'] # 0 not removed.
|
871
884
|
end
|
872
885
|
describe 'Burundi' do
|
873
886
|
it_splits '25712345678', ['257', false, '1234', '5678']
|
@@ -1008,7 +1021,7 @@ describe 'country descriptions' do
|
|
1008
1021
|
it_splits '96287901456', %w(962 8790 1456)
|
1009
1022
|
end
|
1010
1023
|
describe 'Kiribati (Republic of)' do
|
1011
|
-
it_splits '
|
1024
|
+
it_splits '68634814527', ['686', false, '34814527']
|
1012
1025
|
end
|
1013
1026
|
describe "Democratic People's Republic of Korea" do
|
1014
1027
|
it_splits '850212345', %w(850 2 123 45)
|
@@ -1050,11 +1063,14 @@ describe 'country descriptions' do
|
|
1050
1063
|
it_splits '21822123456', %w(218 22 123 456)
|
1051
1064
|
it_splits '218211234456', %w(218 21 1234 456)
|
1052
1065
|
it_splits '218911234456', %w(218 91 1234 456)
|
1066
|
+
it_splits '218941234456', %w(218 94 1234 456)
|
1067
|
+
it_splits '218951234456', %w(218 95 1234 456)
|
1053
1068
|
end
|
1054
1069
|
describe 'Madagascar' do
|
1055
|
-
it_splits '
|
1056
|
-
it_splits '
|
1057
|
-
it_splits '
|
1070
|
+
it_splits '261202254716', ['261', '20', *%w(22 547 16)]
|
1071
|
+
it_splits '261320254716', ['261', '32', *%w(02 547 16)]
|
1072
|
+
it_splits '261330254716', ['261', '33', *%w(02 547 16)]
|
1073
|
+
it_splits '261340254716', ['261', '34', *%w(02 547 16)]
|
1058
1074
|
end
|
1059
1075
|
describe 'Malawi' do
|
1060
1076
|
it_splits '2651725123', ['265', false, '1725', '123']
|
@@ -1078,7 +1094,8 @@ describe 'country descriptions' do
|
|
1078
1094
|
it_splits '22212345678', ['222', false, '1234', '5678']
|
1079
1095
|
end
|
1080
1096
|
describe 'Mauritius' do
|
1081
|
-
it_splits '23059518919', ['230', false, '
|
1097
|
+
it_splits '23059518919', ['230', false, '5', '951', '8919']
|
1098
|
+
it_splits '2302600070', ['230', false, '260', '0070']
|
1082
1099
|
end
|
1083
1100
|
describe 'Micronesia (Federated States of)' do
|
1084
1101
|
it_splits '6911991754', ['691', false, '199', '1754']
|
@@ -1229,6 +1246,7 @@ describe 'country descriptions' do
|
|
1229
1246
|
describe 'Samoa (Independent State of)' do
|
1230
1247
|
it_splits '685800123', ['685', false, '800', '123']
|
1231
1248
|
it_splits '68561123', ['685', false, '61', '123']
|
1249
|
+
it_splits '6857112345', ['685', false, '711', '2345']
|
1232
1250
|
it_splits '6857212345', ['685', false, '721', '2345']
|
1233
1251
|
it_splits '685830123', ['685', false, '830', '123']
|
1234
1252
|
it_splits '685601234', ['685', false, '601', '234']
|
@@ -1317,6 +1335,7 @@ describe 'country descriptions' do
|
|
1317
1335
|
it_splits '88633123456', %w(886 3 312 3456)
|
1318
1336
|
it_splits '88637123456', %w(886 37 12 3456)
|
1319
1337
|
it_splits '88682712345', %w(886 82 71 2345)
|
1338
|
+
it_splits '886801123123', %w(886 801 123 123)
|
1320
1339
|
it_splits '88689712345', %w(886 89 71 2345)
|
1321
1340
|
it_splits '88682672345', %w(886 826 7 2345)
|
1322
1341
|
it_splits '88683672345', %w(886 836 7 2345)
|
@@ -1427,6 +1446,14 @@ describe 'country descriptions' do
|
|
1427
1446
|
it_splits number, ['263', prefix, '234', '5678']
|
1428
1447
|
end
|
1429
1448
|
end
|
1449
|
+
|
1450
|
+
describe 'Universal International Freephone' do
|
1451
|
+
it_splits '80012345678', ['800', false, '12345678']
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
describe 'Shared-Cost Service' do
|
1455
|
+
it_splits '80812345678', ['808', false, '12345678']
|
1456
|
+
end
|
1430
1457
|
end
|
1431
1458
|
|
1432
1459
|
end
|
@@ -4,197 +4,220 @@ describe Phony::CountryCodes do
|
|
4
4
|
|
5
5
|
let(:countries) { Phony::CountryCodes.instance }
|
6
6
|
|
7
|
+
describe '#plausible?' do
|
8
|
+
it 'raises an error on a too long ccc' do
|
9
|
+
expect do
|
10
|
+
countries.plausible?('+1 868 7620266', ccc: '1868123')
|
11
|
+
end.to raise_error(ArgumentError, %Q{The provided ccc option is too long and includes more than a cc ('1') and ndc ('868'). It also includes '123'.})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'ccc handling' do
|
16
|
+
it 'splits a ccc correctly' do
|
17
|
+
cc, ndc, *local = countries.split('1868')
|
18
|
+
|
19
|
+
expect(cc).to eq '1'
|
20
|
+
expect(ndc).to eq '868'
|
21
|
+
end
|
22
|
+
it 'splits a ccc correctly' do
|
23
|
+
cc, ndc, *local = countries.split('1868')
|
24
|
+
|
25
|
+
expect(cc).to eq '1'
|
26
|
+
expect(ndc).to eq '868'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
7
30
|
describe '#[]' do
|
8
31
|
it 'returns a country' do
|
9
|
-
countries['41'].class.
|
32
|
+
expect(countries['41'].class).to eq Phony::Country
|
10
33
|
end
|
11
34
|
end
|
12
35
|
|
13
36
|
describe '#country_for' do
|
14
37
|
it 'returns a country' do
|
15
|
-
countries.send(:country_for, '41').class.
|
38
|
+
expect(countries.send(:country_for, '41').class).to eq Phony::Country
|
16
39
|
end
|
17
40
|
end
|
18
41
|
|
19
42
|
describe '#countrify' do
|
20
43
|
it 'returns a country' do
|
21
|
-
countries.send(:countrify, '441231212', '41').
|
44
|
+
expect(countries.send(:countrify, '441231212', '41')).to eq '41441231212'
|
22
45
|
end
|
23
46
|
end
|
24
47
|
describe '#countrify!' do
|
25
48
|
it 'in-place replaces the number' do
|
26
49
|
number = '441231212'
|
27
|
-
countries.send(:countrify!, number, '41').
|
50
|
+
expect(countries.send(:countrify!, number, '41')).to eq number
|
28
51
|
|
29
|
-
number.
|
52
|
+
expect(number).to eq '41441231212'
|
30
53
|
end
|
31
54
|
end
|
32
55
|
|
33
56
|
describe '#vanity?' do
|
34
57
|
it 'returns true if so' do
|
35
|
-
countries.vanity?('1800HELLOES').
|
58
|
+
expect(countries.vanity?('1800HELLOES')).to eq true
|
36
59
|
end
|
37
60
|
it 'returns false if not' do
|
38
|
-
countries.vanity?('18001234567').
|
61
|
+
expect(countries.vanity?('18001234567')).to eq false
|
39
62
|
end
|
40
63
|
end
|
41
64
|
|
42
65
|
describe 'normalize' do
|
43
66
|
it 'normalizes correctly' do
|
44
|
-
countries.normalize('0041-44-364-35-32').
|
67
|
+
expect(countries.normalize('0041-44-364-35-32')).to eq '41443643532'
|
45
68
|
end
|
46
69
|
it 'normalizes correctly with CC option' do
|
47
|
-
countries.normalize('044-364-35-32', cc: '41').
|
70
|
+
expect(countries.normalize('044-364-35-32', cc: '41')).to eq '41443643532'
|
48
71
|
end
|
49
72
|
|
50
73
|
context 'specific countries' do
|
51
74
|
it 'handles Congo correctly' do
|
52
|
-
countries.normalize('+242 0571 73992').
|
53
|
-
countries.normalize('+242 2221 15932').
|
75
|
+
expect(countries.normalize('+242 0571 73992')).to eq '242057173992'
|
76
|
+
expect(countries.normalize('+242 2221 15932')).to eq '242222115932'
|
54
77
|
end
|
55
78
|
end
|
56
79
|
end
|
57
80
|
|
58
81
|
describe 'formatted' do
|
59
82
|
it 'formats correctly' do
|
60
|
-
countries.formatted('41443643532', :format => :international, :spaces => :-).
|
83
|
+
expect(countries.formatted('41443643532', :format => :international, :spaces => :-)).to eq '+41-44-364-35-32'
|
61
84
|
end
|
62
85
|
it 'formats correctly' do
|
63
|
-
countries.formatted('41443643532', :format => :international_relative, :spaces => :-).
|
86
|
+
expect(countries.formatted('41443643532', :format => :international_relative, :spaces => :-)).to eq '0041-44-364-35-32'
|
64
87
|
end
|
65
88
|
it 'formats correctly' do
|
66
|
-
countries.formatted('41443643532', :format => :national, :spaces => :-).
|
89
|
+
expect(countries.formatted('41443643532', :format => :national, :spaces => :-)).to eq '044-364-35-32'
|
67
90
|
end
|
68
91
|
context 'specific' do
|
69
92
|
it 'formats Ireland correctly' do
|
70
|
-
countries.formatted("3533451234", :format => :national).
|
93
|
+
expect(countries.formatted("3533451234", :format => :national)).to eq '0345 1234'
|
71
94
|
end
|
72
95
|
it 'formats Ireland correctly' do
|
73
|
-
countries.formatted("353411231234", :format => :national).
|
96
|
+
expect(countries.formatted("353411231234", :format => :national)).to eq '041 123 1234'
|
74
97
|
end
|
75
98
|
it 'formats Spain correctly' do
|
76
|
-
countries.formatted("34123456789", :format => :national).
|
99
|
+
expect(countries.formatted("34123456789", :format => :national)).to eq '123 456 789'
|
77
100
|
end
|
78
101
|
it 'formats Cambodia correctly' do
|
79
|
-
countries.formatted('85512239123', :format => :national).
|
102
|
+
expect(countries.formatted('85512239123', :format => :national)).to eq '012 239 123'
|
80
103
|
end
|
81
104
|
it 'formats the US correctly' do
|
82
|
-
countries.formatted('18005551212', :format => :national, :spaces => :-).
|
105
|
+
expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
|
83
106
|
end
|
84
107
|
it 'formats the US correctly' do
|
85
|
-
countries.formatted('18005551212', :format => :national, :spaces => :-).
|
108
|
+
expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
|
86
109
|
end
|
87
110
|
end
|
88
111
|
context 'default' do
|
89
112
|
it "should format swiss numbers" do
|
90
|
-
countries.formatted('41443643532').
|
113
|
+
expect(countries.formatted('41443643532')).to eq '+41 44 364 35 32'
|
91
114
|
end
|
92
115
|
it "should format swiss service numbers" do
|
93
|
-
countries.formatted('41800112233').
|
116
|
+
expect(countries.formatted('41800112233')).to eq '+41 800 112 233'
|
94
117
|
end
|
95
118
|
it "should format austrian numbers" do
|
96
|
-
countries.formatted('43198110').
|
119
|
+
expect(countries.formatted('43198110')).to eq '+43 1 98110'
|
97
120
|
end
|
98
121
|
it "should format american numbers" do
|
99
|
-
countries.formatted('18705551122').
|
122
|
+
expect(countries.formatted('18705551122')).to eq '+1 (870) 555-1122'
|
100
123
|
end
|
101
124
|
it "should format irish numbers" do
|
102
|
-
countries.formatted('35311234567').
|
125
|
+
expect(countries.formatted('35311234567')).to eq '+353 1 123 4567'
|
103
126
|
end
|
104
127
|
end
|
105
128
|
describe "international" do
|
106
129
|
it "should format north american numbers" do
|
107
|
-
countries.formatted('18091231234', :format => :international).
|
130
|
+
expect(countries.formatted('18091231234', :format => :international)).to eq '+1 (809) 123-1234'
|
108
131
|
end
|
109
132
|
it "should format austrian numbers" do
|
110
|
-
countries.formatted('43198110', :format => :international).
|
133
|
+
expect(countries.formatted('43198110', :format => :international)).to eq '+43 1 98110'
|
111
134
|
end
|
112
135
|
it "should format austrian numbers" do
|
113
|
-
countries.formatted('43198110', :format => :international_absolute).
|
136
|
+
expect(countries.formatted('43198110', :format => :international_absolute)).to eq '+43 1 98110'
|
114
137
|
end
|
115
138
|
it "should format french numbers" do
|
116
|
-
countries.formatted('33142278186', :format => :+).
|
139
|
+
expect(countries.formatted('33142278186', :format => :+)).to eq '+33 1 42 27 81 86'
|
117
140
|
end
|
118
141
|
it "should format austrian numbers" do
|
119
|
-
countries.formatted('43198110', :format => :international_relative).
|
142
|
+
expect(countries.formatted('43198110', :format => :international_relative)).to eq '0043 1 98110'
|
120
143
|
end
|
121
144
|
it 'should format liechtensteiner numbers' do
|
122
|
-
countries.formatted('4233841148', :format => :international_relative).
|
145
|
+
expect(countries.formatted('4233841148', :format => :international_relative)).to eq '00423 384 11 48'
|
123
146
|
end
|
124
147
|
it "should format irish numbers" do
|
125
|
-
countries.formatted('35311234567', :format => :international).
|
148
|
+
expect(countries.formatted('35311234567', :format => :international)).to eq '+353 1 123 4567'
|
126
149
|
end
|
127
150
|
it "should format luxembourgian numbers" do
|
128
|
-
countries.formatted('352222809', :format => :international).
|
151
|
+
expect(countries.formatted('352222809', :format => :international)).to eq '+352 22 28 09'
|
129
152
|
end
|
130
153
|
it "should format luxembourgian 4-digit ndc numbers" do
|
131
|
-
countries.formatted('35226222809', :format => :international).
|
154
|
+
expect(countries.formatted('35226222809', :format => :international)).to eq '+352 2622 28 09'
|
132
155
|
end
|
133
156
|
it "should format luxembourgian mobile numbers" do
|
134
|
-
countries.formatted('352621123456', :format => :international).
|
157
|
+
expect(countries.formatted('352621123456', :format => :international)).to eq '+352 621 123 456'
|
135
158
|
end
|
136
159
|
it "should format luxembourgian city numbers" do
|
137
|
-
countries.formatted('3524123456', :format => :international).
|
160
|
+
expect(countries.formatted('3524123456', :format => :international)).to eq '+352 41 23 45 6'
|
138
161
|
end
|
139
162
|
it "should format luxembourgian machine to machine numbers" do
|
140
|
-
countries.formatted('352602112345678', :format => :international).
|
163
|
+
expect(countries.formatted('352602112345678', :format => :international)).to eq '+352 6021 12 34 56 78'
|
141
164
|
end
|
142
165
|
it "should format luxembourgian numbers" do
|
143
|
-
countries.formatted('352370431', :format => :international).
|
166
|
+
expect(countries.formatted('352370431', :format => :international)).to eq '+352 37 04 31'
|
144
167
|
end
|
145
168
|
it "should format luxembourgian numbers" do
|
146
|
-
countries.formatted('35227855', :format => :international).
|
169
|
+
expect(countries.formatted('35227855', :format => :international)).to eq '+352 27 85 5'
|
147
170
|
end
|
148
171
|
it "should format nigerian lagosian numbers" do
|
149
|
-
countries.formatted('23414480000', :format => :international).
|
172
|
+
expect(countries.formatted('23414480000', :format => :international)).to eq '+234 1 448 0000'
|
150
173
|
end
|
151
174
|
it "should format nigerian beninese numbers" do
|
152
|
-
countries.formatted('23452123456', :format => :international).
|
175
|
+
expect(countries.formatted('23452123456', :format => :international)).to eq '+234 52 123 456'
|
153
176
|
end
|
154
177
|
it "should format nigerian mobile numbers" do
|
155
|
-
countries.formatted('2347061234567', :format => :international).
|
178
|
+
expect(countries.formatted('2347061234567', :format => :international)).to eq '+234 706 123 4567'
|
156
179
|
end
|
157
180
|
context 'with no spaces' do
|
158
181
|
it "should format north american numbers" do
|
159
|
-
Phony.formatted('18091231234', :format => :international, :spaces => '').
|
182
|
+
expect(Phony.formatted('18091231234', :format => :international, :spaces => '')).to eq '+1(809)123-1234'
|
160
183
|
end
|
161
184
|
it "should format austrian numbers" do
|
162
|
-
Phony.formatted('43198110', :format => :international, :spaces => '').
|
185
|
+
expect(Phony.formatted('43198110', :format => :international, :spaces => '')).to eq '+43198110'
|
163
186
|
end
|
164
187
|
it "should format austrian numbers" do
|
165
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => '').
|
188
|
+
expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => '')).to eq '+43198110'
|
166
189
|
end
|
167
190
|
it "should format french numbers" do
|
168
|
-
Phony.formatted('33142278186', :format => :+, :spaces => '').
|
191
|
+
expect(Phony.formatted('33142278186', :format => :+, :spaces => '')).to eq '+33142278186'
|
169
192
|
end
|
170
193
|
it "should format austrian numbers" do
|
171
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => '').
|
194
|
+
expect(Phony.formatted('43198110', :format => :international_relative, :spaces => '')).to eq '0043198110'
|
172
195
|
end
|
173
196
|
it 'should format liechtensteiner numbers' do
|
174
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => '').
|
197
|
+
expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => '')).to eq '004233841148'
|
175
198
|
end
|
176
199
|
end
|
177
200
|
context 'with special spaces' do
|
178
201
|
it "should format swiss numbers" do
|
179
|
-
Phony.formatted('41443643532', :format => :international).
|
202
|
+
expect(Phony.formatted('41443643532', :format => :international)).to eq '+41 44 364 35 32'
|
180
203
|
end
|
181
204
|
it "should format north american numbers" do
|
182
|
-
Phony.formatted('18091231234', :format => :international, :spaces => :-).
|
205
|
+
expect(Phony.formatted('18091231234', :format => :international, :spaces => :-)).to eq '+1-(809)-123-1234'
|
183
206
|
end
|
184
207
|
it "should format austrian numbers" do
|
185
|
-
Phony.formatted('43198110', :format => :international, :spaces => :-).
|
208
|
+
expect(Phony.formatted('43198110', :format => :international, :spaces => :-)).to eq '+43-1-98110'
|
186
209
|
end
|
187
210
|
it "should format austrian numbers" do
|
188
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).
|
211
|
+
expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => :-)).to eq '+43-1-98110'
|
189
212
|
end
|
190
213
|
it "should format french numbers" do
|
191
|
-
Phony.formatted('33142278186', :format => :+, :spaces => :-).
|
214
|
+
expect(Phony.formatted('33142278186', :format => :+, :spaces => :-)).to eq '+33-1-42-27-81-86'
|
192
215
|
end
|
193
216
|
it "should format austrian numbers" do
|
194
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => :-).
|
217
|
+
expect(Phony.formatted('43198110', :format => :international_relative, :spaces => :-)).to eq '0043-1-98110'
|
195
218
|
end
|
196
219
|
it 'should format liechtensteiner numbers' do
|
197
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).
|
220
|
+
expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => :-)).to eq '00423-384-11-48'
|
198
221
|
end
|
199
222
|
|
200
223
|
end
|