phony 2.18.15 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -179,6 +179,14 @@ describe 'plausibility' do
179
179
  Phony.plausible?('+359 998 123456').should be_truthy
180
180
  Phony.plausible?('+359 999 123456').should be_truthy
181
181
  end
182
+ it_is_correct_for 'Colombia', :samples => ['+57 601 411 1899',
183
+ '+57 602 111 2222',
184
+ '+57 603 111 2222',
185
+ '+57 604 111 2222',
186
+ '+57 605 111 2222',
187
+ '+57 606 111 2222',
188
+ '+57 607 111 2222',
189
+ '+57 608 111 2222']
182
190
  it_is_correct_for 'Congo', :samples => '+242 1234 56789'
183
191
  it_is_correct_for 'Cook Islands', :samples => '+682 71928'
184
192
  it_is_correct_for 'Costa Rica', :samples => '+506 2 234 5678'
@@ -192,7 +200,7 @@ describe 'plausibility' do
192
200
  Phony.plausible?('+385 60 12 345').should be_truthy # Premium rate
193
201
  Phony.plausible?('+385 62 123 456').should be_truthy # Premium, personal and UAN
194
202
  end
195
- it_is_correct_for "Côte d'Ivoire", :samples => '+225 9358 8764'
203
+ it_is_correct_for "Côte d'Ivoire", :samples => '+225 01 9358 8764'
196
204
  it_is_correct_for 'Democratic Republic of Timor-Leste', :samples => ['+670 465 7886', '+670 7465 7886']
197
205
  it_is_correct_for 'Democratic Republic of the Congo', :samples => '+243 80 864 9794'
198
206
  it_is_correct_for 'Diego Garcia', :samples => '+246 123 7686'
@@ -249,7 +257,14 @@ describe 'plausibility' do
249
257
  end
250
258
  it_is_correct_for 'French Guiana (French Department of)', :samples => '+594 594 123 456'
251
259
  it_is_correct_for "French Polynesia (Territoire français d'outre-mer)", :samples => '+689 87 27 84 00'
252
- it_is_correct_for 'Gabonese Republic', :samples => '+241 1 627 739'
260
+ it 'is correct for Gabon' do
261
+ Phony.plausible?('+241 1 627 739').should be_truthy
262
+ Phony.plausible?('+241 12 34 56 78').should be_truthy
263
+ end
264
+ # it_is_correct_for 'Gabonese Republic', :samples => [
265
+ # '+241 1 627 739',
266
+ # '+241 12 34 56 78',
267
+ # ]
253
268
  it_is_correct_for 'Gambia', :samples => '+220 989 5148'
254
269
  it_is_correct_for 'Germany', :samples => [
255
270
  '+49 69 155 1',
@@ -317,10 +332,19 @@ describe 'plausibility' do
317
332
  it_is_correct_for 'Macedonia', :samples => ['+389 2 123 4567',
318
333
  '+389 7 124 3456',
319
334
  '+389 7 234 5678']
320
- it_is_correct_for 'Madagascar', :samples => ['+261 20 012 345 678',
321
- '+261 20 124 3456',
322
- '+261 512 345 678',
323
- '+261 33 345 6789']
335
+ it_is_correct_for 'Madagascar', :samples => ['+261 20 23 456 78',
336
+ '+261 32 34 546 78',
337
+ '+261 33 34 546 78',
338
+ '+261 34 34 546 78',
339
+ '+261 38 34 546 78']
340
+ it 'is incorrect for Madagascar' do
341
+ Phony.plausible?('+261 20 012 345 678').should be_falsey
342
+ Phony.plausible?('+261 20 12 434 569').should be_falsey
343
+ Phony.plausible?('+261 51 23 4567 8').should be_falsey
344
+ Phony.plausible?('+261 34 345 46789').should be_falsey
345
+ Phony.plausible?('+261 34 345 467').should be_falsey
346
+ end
347
+
324
348
  it_is_correct_for 'Malawi', :samples => ['+265 1725 123',
325
349
  '+265 213 456 789',
326
350
  '+265 9123 456',
@@ -392,6 +416,12 @@ describe 'plausibility' do
392
416
  '+507 6 123 4567',
393
417
  '+507 2 123 456']
394
418
  it_is_correct_for 'Reunion / Mayotte (new)', :samples => '+262 295 276 964'
419
+ it_is_correct_for 'Rwanda', :samples => ['+250 72 1234567',
420
+ '+250 73 1234567',
421
+ '+250 78 1234567',
422
+ '+250 79 1234567',
423
+ '+250 25 1234567',
424
+ '+250 06 123456']
395
425
  it_is_correct_for 'Saint Helena', :samples => '+290 5134'
396
426
  it_is_correct_for 'Saint Pierre and Miquelon (Collectivité territoriale de la République française)', :samples => '+508 474 714'
397
427
  it_is_correct_for 'Salvador (El)', :samples => [
@@ -420,8 +450,10 @@ describe 'plausibility' do
420
450
  ['+381 11 123 456', '+381 11 123 4567'],
421
451
  '+381 72 123 456',
422
452
  '+381 60 123',
423
- '+381 60 123 4567',
453
+ ['+381 60 123 4567', '+381 69 123 456'],
424
454
  '+381 42 123 456',
455
+ '+381 677 123 456',
456
+ '+381 678 123 456',
425
457
  '+381 9 123 4567',
426
458
  '+381 60 123',
427
459
  '+381 60 123 456 7890',
@@ -492,7 +524,10 @@ describe 'plausibility' do
492
524
  it_is_correct_for 'Lybia', :samples => ['+218 205 123 45',
493
525
  '+218 22 123 456',
494
526
  '+218 21 1234 456',
495
- '+218 91 1234 456']
527
+ '+218 91 1234 456',
528
+ '+218 92 1234 456',
529
+ '+218 94 1234 456',
530
+ '+218 95 1234 456']
496
531
  it_is_correct_for 'Mongolia', :samples => ['+976 11 123 45',
497
532
  ['+976 121 12 34', '+976 121 12 345'],
498
533
  '+976 70 123 456',
@@ -553,9 +588,12 @@ describe 'plausibility' do
553
588
  '+967 58 1234']
554
589
  it 'is correct for Zambia' do
555
590
  Phony.plausible?('+260 211 123456').should be_truthy # Fixed
556
- Phony.plausible?('+260 955 123456').should be_truthy # Mobile
557
- Phony.plausible?('+260 967 123456').should be_truthy # Mobile
558
- Phony.plausible?('+260 978 123456').should be_truthy # Mobile
591
+ Phony.plausible?('+260 96 512 4567').should be_truthy # MTN Mobile
592
+ Phony.plausible?('+260 97 712 3456').should be_truthy # Airtel Mobile
593
+ Phony.plausible?('+260 95 512 4567').should be_truthy # Zamtel Mobile
594
+ Phony.plausible?('+260 96 512 456').should be_falsy # MTN Mobile (Too short)
595
+ Phony.plausible?('+260 97 812 345').should be_falsy # Airtel Mobile (Too short)
596
+ Phony.plausible?('+260 95 512 345').should be_falsy # Zamtel Mobile (Too short)
559
597
  Phony.plausible?('+260 800 123 456').should be_truthy # Toll free
560
598
  end
561
599
  it_is_correct_for 'Zimbabwe', :samples => [['+263 2582 123 456', '+263 2582 123'],
@@ -570,6 +608,20 @@ describe 'plausibility' do
570
608
  Phony.plausible?('+62 22 0000 0000').should be_truthy
571
609
  Phony.plausible?('+62 22 000 000 000').should be_truthy
572
610
  end
611
+
612
+ it 'is correct for Italy' do
613
+ Phony.plausible?('+39 0574 123').should be_falsy
614
+ Phony.plausible?('+39 0574 1234').should be_truthy
615
+ Phony.plausible?('+39 0574 12345').should be_falsy
616
+
617
+ Phony.plausible?('+39 085 541').should be_falsy
618
+ Phony.plausible?('+39 085 5410').should be_truthy
619
+ Phony.plausible?('+39 085 54105').should be_truthy
620
+
621
+ Phony.plausible?('+39 06 4991').should be_falsy
622
+ Phony.plausible?('+39 06 49911').should be_truthy
623
+ Phony.plausible?('+39 06 499112').should be_truthy
624
+ end
573
625
 
574
626
  it 'is correct for Russia' do
575
627
  Phony.plausible?('+7 3522 000 000').should be_truthy
@@ -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)
@@ -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 '3906123412', ['39', '06', '1234', '12'] # Roma 6 digit
463
- it_splits '39061234123', ['39', '06', '1234', '123'] # Roma 7 digit
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
@@ -484,6 +487,8 @@ describe 'country descriptions' do
484
487
  it_splits '817012345678', %w(81 70 1234 5678) # PHS
485
488
  it_splits '818012345678', %w(81 80 1234 5678) # Cellular
486
489
  it_splits '819012345678', %w(81 90 1234 5678) # Cellular
490
+ it_splits '810570123456', %w(81 570 123 456) # Navi-dial
491
+ it_splits '810180123456', %w(81 180 123 456) # Tele-gong/Tele-dome
487
492
  end
488
493
  describe 'Kenya' do
489
494
  it_splits '254201234567', ['254', '20', '1234567'] # Nairobi
@@ -677,6 +682,7 @@ describe 'country descriptions' do
677
682
  it_splits '250781234567', ['250', '78', '1234567'] # mobile
678
683
  it_splits '250721234567', ['250', '72', '1234567'] # mobile
679
684
  it_splits '250731234567', ['250', '73', '1234567'] # mobile
685
+ it_splits '250791234567', ['250', '79', '1234567'] # mobile
680
686
  it_splits '250251234567', ['250', '25', '1234567'] # fixed
681
687
  it_splits '25006123456', ['250', '06', '123456'] # fixed
682
688
  end
@@ -759,6 +765,7 @@ describe 'country descriptions' do
759
765
  describe 'Switzerland' do
760
766
  it_splits '41443643532', ['41', '44', '364', '35', '32'] # Zurich (usually)
761
767
  it_splits '41800334455', ['41', '800', '334', '455'] # Service number
768
+ it_splits '41860443643532', ['41', '860', '44', '364', '35', '32'] # Voicemail access
762
769
  it_splits '41900123456', ['41', '900', '123', '456'] # Business Number
763
770
  it_splits '41901123456', ['41', '901', '123', '456'] # Business Number Entertainment
764
771
  it_splits '41906123456', ['41', '906', '123', '456'] # Business Number Adult Entertainment
@@ -847,9 +854,9 @@ describe 'country descriptions' do
847
854
  end
848
855
  describe 'Zambia' do
849
856
  it_splits '260211123456', ['260', '211', '123456'] # Fixed
850
- it_splits '260955123456', ['260', '955', '123456'] # Mobile
851
- it_splits '260967123456', ['260', '967', '123456'] # Mobile
852
- it_splits '260978123456', ['260', '978', '123456'] # Mobile
857
+ it_splits '260955123456', ['260', '95', '512', '3456'] # Mobile
858
+ it_splits '260967123456', ['260', '96', '712', '3456'] # Mobile
859
+ it_splits '260978123456', ['260', '97', '812', '3456'] # Mobile
853
860
  it_splits '260800123456', ['260', '800', '123', '456'] # Toll free
854
861
  end
855
862
  describe 'New Zealand' do
@@ -895,8 +902,8 @@ describe 'country descriptions' do
895
902
  it_splits '50622345678', %w(506 2 234 5678)
896
903
  end
897
904
  describe "Côte d'Ivoire" do
898
- it_splits '22507335518', ['225', '07', '33', '55', '18']
899
- it_splits '22537335518', ['225', '37', '33', '55', '18']
905
+ it_splits '2250107335518', ['225', '01', '07', '33', '55', '18']
906
+ it_splits '2250237335518', ['225', '02', '37', '33', '55', '18']
900
907
  end
901
908
  describe 'Democratic Republic of Timor-Leste' do
902
909
  it_splits '6701742945', ['670', false, '174', '2945']
@@ -959,6 +966,7 @@ describe 'country descriptions' do
959
966
  end
960
967
  describe 'Gabonese Republic' do
961
968
  it_splits '2411834375', ['241', '1', '834', '375']
969
+ it_splits '24174012345', ['241', '74', '01', '23', '45']
962
970
  end
963
971
  describe 'Gambia' do
964
972
  it_splits '2206683355', ['220', false, '668', '3355']
@@ -1046,11 +1054,14 @@ describe 'country descriptions' do
1046
1054
  it_splits '21822123456', %w(218 22 123 456)
1047
1055
  it_splits '218211234456', %w(218 21 1234 456)
1048
1056
  it_splits '218911234456', %w(218 91 1234 456)
1057
+ it_splits '218941234456', %w(218 94 1234 456)
1058
+ it_splits '218951234456', %w(218 95 1234 456)
1049
1059
  end
1050
1060
  describe 'Madagascar' do
1051
- it_splits '26120012345678', ['261', false, '20', '012', '345', '678']
1052
- it_splits '261201243456', ['261', false, *%w(20 124 3456)]
1053
- it_splits '261512345678', ['261', false, *%w(512 345 678)]
1061
+ it_splits '261202254716', ['261', '20', *%w(22 547 16)]
1062
+ it_splits '261320254716', ['261', '32', *%w(02 547 16)]
1063
+ it_splits '261330254716', ['261', '33', *%w(02 547 16)]
1064
+ it_splits '261340254716', ['261', '34', *%w(02 547 16)]
1054
1065
  end
1055
1066
  describe 'Malawi' do
1056
1067
  it_splits '2651725123', ['265', false, '1725', '123']
@@ -1163,6 +1174,17 @@ describe 'country descriptions' do
1163
1174
  it_splits '2349087661234', %w(234 908 766 1234)
1164
1175
  it_splits '2349097661234', %w(234 909 766 1234)
1165
1176
 
1177
+ it_splits '2349107661234', %w(234 910 766 1234)
1178
+ it_splits '2349117661234', %w(234 911 766 1234)
1179
+ it_splits '2349127661234', %w(234 912 766 1234)
1180
+ it_splits '2349137661234', %w(234 913 766 1234)
1181
+ it_splits '2349147661234', %w(234 914 766 1234)
1182
+ it_splits '2349157661234', %w(234 915 766 1234)
1183
+ it_splits '2349167661234', %w(234 916 766 1234)
1184
+ it_splits '2349177661234', %w(234 917 766 1234)
1185
+ it_splits '2349187661234', %w(234 918 766 1234)
1186
+ it_splits '2349197661234', %w(234 919 766 1234)
1187
+
1166
1188
  it_splits '2348107661234', %w(234 810 766 1234)
1167
1189
  it_splits '2348117661234', %w(234 811 766 1234)
1168
1190
  it_splits '2348127661234', %w(234 812 766 1234)
@@ -1214,6 +1236,7 @@ describe 'country descriptions' do
1214
1236
  describe 'Samoa (Independent State of)' do
1215
1237
  it_splits '685800123', ['685', false, '800', '123']
1216
1238
  it_splits '68561123', ['685', false, '61', '123']
1239
+ it_splits '6857112345', ['685', false, '711', '2345']
1217
1240
  it_splits '6857212345', ['685', false, '721', '2345']
1218
1241
  it_splits '685830123', ['685', false, '830', '123']
1219
1242
  it_splits '685601234', ['685', false, '601', '234']
@@ -1302,6 +1325,7 @@ describe 'country descriptions' do
1302
1325
  it_splits '88633123456', %w(886 3 312 3456)
1303
1326
  it_splits '88637123456', %w(886 37 12 3456)
1304
1327
  it_splits '88682712345', %w(886 82 71 2345)
1328
+ it_splits '886801123123', %w(886 801 123 123)
1305
1329
  it_splits '88689712345', %w(886 89 71 2345)
1306
1330
  it_splits '88682672345', %w(886 826 7 2345)
1307
1331
  it_splits '88683672345', %w(886 836 7 2345)
@@ -1412,6 +1436,14 @@ describe 'country descriptions' do
1412
1436
  it_splits number, ['263', prefix, '234', '5678']
1413
1437
  end
1414
1438
  end
1439
+
1440
+ describe 'Universal International Freephone' do
1441
+ it_splits '80012345678', ['800', false, '12345678']
1442
+ end
1443
+
1444
+ describe 'Shared-Cost Service' do
1445
+ it_splits '80812345678', ['808', false, '12345678']
1446
+ end
1415
1447
  end
1416
1448
 
1417
1449
  end
@@ -1,32 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phony::CountryCodes do
4
-
5
- before(:all) do
6
- @countries = Phony::CountryCodes.instance
4
+
5
+ let(:countries) { Phony::CountryCodes.instance }
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
+ cc.should eq('1')
19
+ ndc.should eq('868')
20
+ end
21
+ it 'splits a ccc correctly' do
22
+ cc, ndc, *local = countries.split('1868')
23
+ cc.should eq('1')
24
+ ndc.should eq('868')
25
+ end
7
26
  end
8
27
 
9
28
  describe '#[]' do
10
29
  it 'returns a country' do
11
- @countries['41'].class.should eql Phony::Country
30
+ countries['41'].class.should eql Phony::Country
12
31
  end
13
32
  end
14
33
 
15
34
  describe '#country_for' do
16
35
  it 'returns a country' do
17
- @countries.send(:country_for, '41').class.should eql Phony::Country
36
+ countries.send(:country_for, '41').class.should eql Phony::Country
18
37
  end
19
38
  end
20
39
 
21
40
  describe '#countrify' do
22
41
  it 'returns a country' do
23
- @countries.send(:countrify, '441231212', '41').should eql '41441231212'
42
+ countries.send(:countrify, '441231212', '41').should eql '41441231212'
24
43
  end
25
44
  end
26
45
  describe '#countrify!' do
27
46
  it 'in-place replaces the number' do
28
47
  number = '441231212'
29
- @countries.send(:countrify!, number, '41').should eql number
48
+ countries.send(:countrify!, number, '41').should eql number
30
49
 
31
50
  number.should == '41441231212'
32
51
  end
@@ -34,127 +53,127 @@ describe Phony::CountryCodes do
34
53
 
35
54
  describe '#vanity?' do
36
55
  it 'returns true if so' do
37
- @countries.vanity?('1800HELLOES').should eql true
56
+ countries.vanity?('1800HELLOES').should eql true
38
57
  end
39
58
  it 'returns false if not' do
40
- @countries.vanity?('18001234567').should eql false
59
+ countries.vanity?('18001234567').should eql false
41
60
  end
42
61
  end
43
62
 
44
63
  describe 'normalize' do
45
64
  it 'normalizes correctly' do
46
- @countries.normalize('0041-44-364-35-32').should eql '41443643532'
65
+ countries.normalize('0041-44-364-35-32').should eql '41443643532'
47
66
  end
48
67
  it 'normalizes correctly with CC option' do
49
- @countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
68
+ countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
50
69
  end
51
70
 
52
71
  context 'specific countries' do
53
72
  it 'handles Congo correctly' do
54
- @countries.normalize('+242 0571 73992').should eql '242057173992'
55
- @countries.normalize('+242 2221 15932').should eql '242222115932'
73
+ countries.normalize('+242 0571 73992').should eql '242057173992'
74
+ countries.normalize('+242 2221 15932').should eql '242222115932'
56
75
  end
57
76
  end
58
77
  end
59
78
 
60
79
  describe 'formatted' do
61
80
  it 'formats correctly' do
62
- @countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
81
+ countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
63
82
  end
64
83
  it 'formats correctly' do
65
- @countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
84
+ countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
66
85
  end
67
86
  it 'formats correctly' do
68
- @countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
87
+ countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
69
88
  end
70
89
  context 'specific' do
71
90
  it 'formats Ireland correctly' do
72
- @countries.formatted("3533451234", :format => :national).should eql '0345 1234'
91
+ countries.formatted("3533451234", :format => :national).should eql '0345 1234'
73
92
  end
74
93
  it 'formats Ireland correctly' do
75
- @countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
94
+ countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
76
95
  end
77
96
  it 'formats Spain correctly' do
78
- @countries.formatted("34123456789", :format => :national).should eql '123 456 789'
97
+ countries.formatted("34123456789", :format => :national).should eql '123 456 789'
79
98
  end
80
99
  it 'formats Cambodia correctly' do
81
- @countries.formatted('85512239123', :format => :national).should eql '012 239 123'
100
+ countries.formatted('85512239123', :format => :national).should eql '012 239 123'
82
101
  end
83
102
  it 'formats the US correctly' do
84
- @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
103
+ countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
85
104
  end
86
105
  it 'formats the US correctly' do
87
- @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
106
+ countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
88
107
  end
89
108
  end
90
109
  context 'default' do
91
110
  it "should format swiss numbers" do
92
- @countries.formatted('41443643532').should eql '+41 44 364 35 32'
111
+ countries.formatted('41443643532').should eql '+41 44 364 35 32'
93
112
  end
94
113
  it "should format swiss service numbers" do
95
- @countries.formatted('41800112233').should eql '+41 800 112 233'
114
+ countries.formatted('41800112233').should eql '+41 800 112 233'
96
115
  end
97
116
  it "should format austrian numbers" do
98
- @countries.formatted('43198110').should eql '+43 1 98110'
117
+ countries.formatted('43198110').should eql '+43 1 98110'
99
118
  end
100
119
  it "should format american numbers" do
101
- @countries.formatted('18705551122').should eql '+1 (870) 555-1122'
120
+ countries.formatted('18705551122').should eql '+1 (870) 555-1122'
102
121
  end
103
122
  it "should format irish numbers" do
104
- @countries.formatted('35311234567').should eql '+353 1 123 4567'
123
+ countries.formatted('35311234567').should eql '+353 1 123 4567'
105
124
  end
106
125
  end
107
126
  describe "international" do
108
127
  it "should format north american numbers" do
109
- @countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
128
+ countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
110
129
  end
111
130
  it "should format austrian numbers" do
112
- @countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
131
+ countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
113
132
  end
114
133
  it "should format austrian numbers" do
115
- @countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
134
+ countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
116
135
  end
117
136
  it "should format french numbers" do
118
- @countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
137
+ countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
119
138
  end
120
139
  it "should format austrian numbers" do
121
- @countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
140
+ countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
122
141
  end
123
142
  it 'should format liechtensteiner numbers' do
124
- @countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
143
+ countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
125
144
  end
126
145
  it "should format irish numbers" do
127
- @countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
146
+ countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
128
147
  end
129
148
  it "should format luxembourgian numbers" do
130
- @countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
149
+ countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
131
150
  end
132
151
  it "should format luxembourgian 4-digit ndc numbers" do
133
- @countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
152
+ countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
134
153
  end
135
154
  it "should format luxembourgian mobile numbers" do
136
- @countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
155
+ countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
137
156
  end
138
157
  it "should format luxembourgian city numbers" do
139
- @countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
158
+ countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
140
159
  end
141
160
  it "should format luxembourgian machine to machine numbers" do
142
- @countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
161
+ countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
143
162
  end
144
163
  it "should format luxembourgian numbers" do
145
- @countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
164
+ countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
146
165
  end
147
166
  it "should format luxembourgian numbers" do
148
- @countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
167
+ countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
149
168
  end
150
169
  it "should format nigerian lagosian numbers" do
151
- @countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
170
+ countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
152
171
  end
153
172
  it "should format nigerian beninese numbers" do
154
- @countries.formatted('23452123456', :format => :international).should eql '+234 52 123 456'
173
+ countries.formatted('23452123456', :format => :international).should eql '+234 52 123 456'
155
174
  end
156
175
  it "should format nigerian mobile numbers" do
157
- @countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
176
+ countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
158
177
  end
159
178
  context 'with no spaces' do
160
179
  it "should format north american numbers" do
@@ -43,6 +43,18 @@ describe Phony::Country do
43
43
  Phony.normalize('+378903549').should == '3780549903549'
44
44
  end
45
45
  end
46
+ describe 'Japan' do
47
+ it 'normalizes correctly' do
48
+ Phony.normalize('+81-03-1234-5634').should == '81312345634'
49
+ Phony.normalize('03-1234-5634', cc: '81').should == '81312345634'
50
+ end
51
+ it 'formats correctly' do
52
+ Phony.format('81312345634').should == '+81-3-1234-5634'
53
+ end
54
+ it 'splits correctly' do
55
+ Phony.split('81312345634').should == %w(81 3 1234 5634)
56
+ end
57
+ end
46
58
  end
47
59
 
48
60
  context "without special cases (with switzerland)" do
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phony::TrunkCode do
4
+
5
+ describe '#format' do
6
+ it 'is correct' do
7
+ code = described_class.new('0')
8
+ expect(code.format('%s %s')).to eq '0'
9
+ end
10
+ it 'is correct' do
11
+ code = described_class.new('0', format: true)
12
+ expect(code.format('%s %s')).to eq '0'
13
+ end
14
+ it 'is correct' do
15
+ code = described_class.new('0', format: false)
16
+ expect(code.format('%s %s')).to eq nil
17
+ end
18
+ it 'is correct' do
19
+ code = described_class.new('06')
20
+ expect(code.format('%s %s')).to eq '06'
21
+ end
22
+ it 'is correct' do
23
+ code = described_class.new('06', format: true)
24
+ expect(code.format('%s %s')).to eq '06'
25
+ end
26
+ it 'is correct' do
27
+ code = described_class.new('06', format: false)
28
+ expect(code.format('%s %s')).to eq nil
29
+ end
30
+ end
31
+
32
+ describe '#normalize' do
33
+ it 'is correct' do
34
+ code = described_class.new('0')
35
+ expect(code.normalize('0123')).to eq '0123'
36
+ end
37
+ it 'is correct' do
38
+ code = described_class.new('0', normalize: true)
39
+ expect(code.normalize('0123')).to eq '0123'
40
+ end
41
+ it 'is correct' do
42
+ code = described_class.new('0', normalize: false)
43
+ expect(code.normalize('0123')).to eq '0123'
44
+ end
45
+ it 'is correct' do
46
+ code = described_class.new('06')
47
+ expect(code.normalize('06123')).to eq '06123'
48
+ end
49
+ it 'is correct' do
50
+ code = described_class.new('06', normalize: true)
51
+ expect(code.normalize('06123')).to eq '06123'
52
+ end
53
+ it 'is correct' do
54
+ code = described_class.new('06', normalize: false)
55
+ expect(code.normalize('0123')).to eq '0123'
56
+ end
57
+ end
58
+
59
+ describe '#split' do
60
+ it 'is correct' do
61
+ code = described_class.new('0')
62
+ expect(code.split('0123')).to eq [code, '0123']
63
+ end
64
+ it 'is correct' do
65
+ code = described_class.new('0', split: true)
66
+ expect(code.split('0123')).to eq [code, '123']
67
+ end
68
+ it 'is correct' do
69
+ code = described_class.new('0', split: false)
70
+ expect(code.split('0123')).to eq [code, '0123']
71
+ end
72
+ it 'is correct' do
73
+ code = described_class.new('06')
74
+ expect(code.split('06123')).to eq [code, '06123']
75
+ end
76
+ it 'is correct' do
77
+ code = described_class.new('06', split: true)
78
+ expect(code.split('06123')).to eq [code, '123']
79
+ end
80
+ it 'is correct' do
81
+ code = described_class.new('06', split: false)
82
+ expect(code.split('06123')).to eq [code, '06123']
83
+ end
84
+ end
85
+ end