-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
phonenumberutil_test.js
3875 lines (3483 loc) · 164 KB
/
phonenumberutil_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @license
* Copyright (C) 2010 The Libphonenumber Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Unit tests for the PhoneNumberUtil.
*
* Note that these tests use the metadata contained in metadatafortesting.js,
* not the normal metadata files, so should not be used for regression test
* purposes - these tests are illustrative only and test functionality.
*
* @author Nikolaos Trogkanis
*/
goog.require('goog.array');
goog.require('goog.string.StringBuffer');
goog.require('goog.testing.jsunit');
goog.require('i18n.phonenumbers.NumberFormat');
goog.require('i18n.phonenumbers.PhoneMetadata');
goog.require('i18n.phonenumbers.PhoneNumber');
goog.require('i18n.phonenumbers.PhoneNumberDesc');
goog.require('i18n.phonenumbers.PhoneNumberUtil');
goog.require('i18n.phonenumbers.RegionCode');
/** @type {i18n.phonenumbers.PhoneNumberUtil} */
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
// Set up some test numbers to re-use.
// TODO: Rewrite this as static functions that return new numbers each time to
// avoid any risk of accidental changes to mutable static state affecting many
// tests.
/** @type {i18n.phonenumbers.PhoneNumber} */
var ALPHA_NUMERIC_NUMBER = new i18n.phonenumbers.PhoneNumber();
ALPHA_NUMERIC_NUMBER.setCountryCode(1);
ALPHA_NUMERIC_NUMBER.setNationalNumber(80074935247);
/** @type {i18n.phonenumbers.PhoneNumber} */
var AE_UAN = new i18n.phonenumbers.PhoneNumber();
AE_UAN.setCountryCode(971);
AE_UAN.setNationalNumber(600123456);
/** @type {i18n.phonenumbers.PhoneNumber} */
var AR_MOBILE = new i18n.phonenumbers.PhoneNumber();
AR_MOBILE.setCountryCode(54);
AR_MOBILE.setNationalNumber(91187654321);
/** @type {i18n.phonenumbers.PhoneNumber} */
var AR_NUMBER = new i18n.phonenumbers.PhoneNumber();
AR_NUMBER.setCountryCode(54);
AR_NUMBER.setNationalNumber(1187654321);
/** @type {i18n.phonenumbers.PhoneNumber} */
var AU_NUMBER = new i18n.phonenumbers.PhoneNumber();
AU_NUMBER.setCountryCode(61);
AU_NUMBER.setNationalNumber(236618300);
/** @type {i18n.phonenumbers.PhoneNumber} */
var BS_MOBILE = new i18n.phonenumbers.PhoneNumber();
BS_MOBILE.setCountryCode(1);
BS_MOBILE.setNationalNumber(2423570000);
/** @type {i18n.phonenumbers.PhoneNumber} */
var BS_NUMBER = new i18n.phonenumbers.PhoneNumber();
BS_NUMBER.setCountryCode(1);
BS_NUMBER.setNationalNumber(2423651234);
// Note that this is the same as the example number for DE in the metadata.
/** @type {i18n.phonenumbers.PhoneNumber} */
var DE_NUMBER = new i18n.phonenumbers.PhoneNumber();
DE_NUMBER.setCountryCode(49);
DE_NUMBER.setNationalNumber(30123456);
/** @type {i18n.phonenumbers.PhoneNumber} */
var DE_SHORT_NUMBER = new i18n.phonenumbers.PhoneNumber();
DE_SHORT_NUMBER.setCountryCode(49);
DE_SHORT_NUMBER.setNationalNumber(1234);
/** @type {i18n.phonenumbers.PhoneNumber} */
var GB_MOBILE = new i18n.phonenumbers.PhoneNumber();
GB_MOBILE.setCountryCode(44);
GB_MOBILE.setNationalNumber(7912345678);
/** @type {i18n.phonenumbers.PhoneNumber} */
var GB_NUMBER = new i18n.phonenumbers.PhoneNumber();
GB_NUMBER.setCountryCode(44);
GB_NUMBER.setNationalNumber(2070313000);
/** @type {i18n.phonenumbers.PhoneNumber} */
var IT_MOBILE = new i18n.phonenumbers.PhoneNumber();
IT_MOBILE.setCountryCode(39);
IT_MOBILE.setNationalNumber(345678901);
/** @type {i18n.phonenumbers.PhoneNumber} */
var IT_NUMBER = new i18n.phonenumbers.PhoneNumber();
IT_NUMBER.setCountryCode(39);
IT_NUMBER.setNationalNumber(236618300);
IT_NUMBER.setItalianLeadingZero(true);
/** @type {i18n.phonenumbers.PhoneNumber} */
var JP_STAR_NUMBER = new i18n.phonenumbers.PhoneNumber();
JP_STAR_NUMBER.setCountryCode(81);
JP_STAR_NUMBER.setNationalNumber(2345);
// Numbers to test the formatting rules from Mexico.
/** @type {i18n.phonenumbers.PhoneNumber} */
var MX_MOBILE1 = new i18n.phonenumbers.PhoneNumber();
MX_MOBILE1.setCountryCode(52);
MX_MOBILE1.setNationalNumber(12345678900);
/** @type {i18n.phonenumbers.PhoneNumber} */
var MX_MOBILE2 = new i18n.phonenumbers.PhoneNumber();
MX_MOBILE2.setCountryCode(52);
MX_MOBILE2.setNationalNumber(15512345678);
/** @type {i18n.phonenumbers.PhoneNumber} */
var MX_NUMBER1 = new i18n.phonenumbers.PhoneNumber();
MX_NUMBER1.setCountryCode(52);
MX_NUMBER1.setNationalNumber(3312345678);
/** @type {i18n.phonenumbers.PhoneNumber} */
var MX_NUMBER2 = new i18n.phonenumbers.PhoneNumber();
MX_NUMBER2.setCountryCode(52);
MX_NUMBER2.setNationalNumber(8211234567);
/** @type {i18n.phonenumbers.PhoneNumber} */
var NZ_NUMBER = new i18n.phonenumbers.PhoneNumber();
NZ_NUMBER.setCountryCode(64);
NZ_NUMBER.setNationalNumber(33316005);
/** @type {i18n.phonenumbers.PhoneNumber} */
var SG_NUMBER = new i18n.phonenumbers.PhoneNumber();
SG_NUMBER.setCountryCode(65);
SG_NUMBER.setNationalNumber(65218000);
// A too-long and hence invalid US number.
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_LONG_NUMBER = new i18n.phonenumbers.PhoneNumber();
US_LONG_NUMBER.setCountryCode(1);
US_LONG_NUMBER.setNationalNumber(65025300001);
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_NUMBER = new i18n.phonenumbers.PhoneNumber();
US_NUMBER.setCountryCode(1);
US_NUMBER.setNationalNumber(6502530000);
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_PREMIUM = new i18n.phonenumbers.PhoneNumber();
US_PREMIUM.setCountryCode(1);
US_PREMIUM.setNationalNumber(9002530000);
// Too short, but still possible US numbers.
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_LOCAL_NUMBER = new i18n.phonenumbers.PhoneNumber();
US_LOCAL_NUMBER.setCountryCode(1);
US_LOCAL_NUMBER.setNationalNumber(2530000);
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_SHORT_BY_ONE_NUMBER = new i18n.phonenumbers.PhoneNumber();
US_SHORT_BY_ONE_NUMBER.setCountryCode(1);
US_SHORT_BY_ONE_NUMBER.setNationalNumber(650253000);
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_TOLLFREE = new i18n.phonenumbers.PhoneNumber();
US_TOLLFREE.setCountryCode(1);
US_TOLLFREE.setNationalNumber(8002530000);
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_SPOOF = new i18n.phonenumbers.PhoneNumber();
US_SPOOF.setCountryCode(1);
US_SPOOF.setNationalNumber(0);
/** @type {i18n.phonenumbers.PhoneNumber} */
var US_SPOOF_WITH_RAW_INPUT = new i18n.phonenumbers.PhoneNumber();
US_SPOOF_WITH_RAW_INPUT.setCountryCode(1);
US_SPOOF_WITH_RAW_INPUT.setNationalNumber(0);
US_SPOOF_WITH_RAW_INPUT.setRawInput('000-000-0000');
/** @type {i18n.phonenumbers.PhoneNumber} */
var INTERNATIONAL_TOLL_FREE = new i18n.phonenumbers.PhoneNumber();
INTERNATIONAL_TOLL_FREE.setCountryCode(800);
INTERNATIONAL_TOLL_FREE.setNationalNumber(12345678);
// We set this to be the same length as numbers for the other non-geographical
// country prefix that we have in our test metadata. However, this is not
// considered valid because they differ in their country calling code.
/** @type {i18n.phonenumbers.PhoneNumber} */
var INTERNATIONAL_TOLL_FREE_TOO_LONG = new i18n.phonenumbers.PhoneNumber();
INTERNATIONAL_TOLL_FREE_TOO_LONG.setCountryCode(800);
INTERNATIONAL_TOLL_FREE_TOO_LONG.setNationalNumber(123456789);
/** @type {i18n.phonenumbers.PhoneNumber} */
var UNIVERSAL_PREMIUM_RATE = new i18n.phonenumbers.PhoneNumber();
UNIVERSAL_PREMIUM_RATE.setCountryCode(979);
UNIVERSAL_PREMIUM_RATE.setNationalNumber(123456789);
/** @type {i18n.phonenumbers.PhoneNumber} */
var UNKNOWN_COUNTRY_CODE_NO_RAW_INPUT = new i18n.phonenumbers.PhoneNumber();
UNKNOWN_COUNTRY_CODE_NO_RAW_INPUT.setCountryCode(2);
UNKNOWN_COUNTRY_CODE_NO_RAW_INPUT.setNationalNumber(12345);
var RegionCode = i18n.phonenumbers.RegionCode;
function testGetInstanceLoadUSMetadata() {
/** @type {i18n.phonenumbers.PhoneMetadata} */
var metadata = phoneUtil.getMetadataForRegion(RegionCode.US);
assertEquals(RegionCode.US, metadata.getId());
assertEquals(1, metadata.getCountryCode());
assertEquals('011', metadata.getInternationalPrefix());
assertTrue(metadata.hasNationalPrefix());
assertEquals(2, metadata.numberFormatCount());
assertEquals('(\\d{3})(\\d{3})(\\d{4})',
metadata.getNumberFormat(1).getPattern());
assertEquals('$1 $2 $3', metadata.getNumberFormat(1).getFormat());
assertEquals('[13-689]\\d{9}|2[0-35-9]\\d{8}',
metadata.getGeneralDesc().getNationalNumberPattern());
assertEquals('[13-689]\\d{9}|2[0-35-9]\\d{8}',
metadata.getFixedLine().getNationalNumberPattern());
assertEquals('900\\d{7}',
metadata.getPremiumRate().getNationalNumberPattern());
// No shared-cost data is available, so its national number data should not be
// set.
assertFalse(metadata.getSharedCost().hasNationalNumberPattern());
}
function testGetInstanceLoadDEMetadata() {
/** @type {i18n.phonenumbers.PhoneMetadata} */
var metadata = phoneUtil.getMetadataForRegion(RegionCode.DE);
assertEquals(RegionCode.DE, metadata.getId());
assertEquals(49, metadata.getCountryCode());
assertEquals('00', metadata.getInternationalPrefix());
assertEquals('0', metadata.getNationalPrefix());
assertEquals(6, metadata.numberFormatCount());
assertEquals(1, metadata.getNumberFormat(5).leadingDigitsPatternCount());
assertEquals('900', metadata.getNumberFormat(5).getLeadingDigitsPattern(0));
assertEquals('(\\d{3})(\\d{3,4})(\\d{4})',
metadata.getNumberFormat(5).getPattern());
assertEquals('$1 $2 $3', metadata.getNumberFormat(5).getFormat());
assertEquals('(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:0[2-9]|[1-9]\\d))\\d{1,8}',
metadata.getFixedLine().getNationalNumberPattern());
assertEquals('30123456', metadata.getFixedLine().getExampleNumber());
assertEquals('900([135]\\d{6}|9\\d{7})',
metadata.getPremiumRate().getNationalNumberPattern());
}
function testGetInstanceLoadARMetadata() {
/** @type {i18n.phonenumbers.PhoneMetadata} */
var metadata = phoneUtil.getMetadataForRegion(RegionCode.AR);
assertEquals(RegionCode.AR, metadata.getId());
assertEquals(54, metadata.getCountryCode());
assertEquals('00', metadata.getInternationalPrefix());
assertEquals('0', metadata.getNationalPrefix());
assertEquals('0(?:(11|343|3715)15)?', metadata.getNationalPrefixForParsing());
assertEquals('9$1', metadata.getNationalPrefixTransformRule());
assertEquals('$2 15 $3-$4', metadata.getNumberFormat(2).getFormat());
assertEquals('(9)(\\d{4})(\\d{2})(\\d{4})',
metadata.getNumberFormat(3).getPattern());
assertEquals('(9)(\\d{4})(\\d{2})(\\d{4})',
metadata.getIntlNumberFormat(3).getPattern());
assertEquals('$1 $2 $3 $4', metadata.getIntlNumberFormat(3).getFormat());
}
function testGetInstanceLoadInternationalTollFreeMetadata() {
/** @type {i18n.phonenumbers.PhoneMetadata} */
var metadata = phoneUtil.getMetadataForNonGeographicalRegion(800);
assertEquals('001', metadata.getId());
assertEquals(800, metadata.getCountryCode());
assertEquals('$1 $2', metadata.getNumberFormat(0).getFormat());
assertEquals('(\\d{4})(\\d{4})', metadata.getNumberFormat(0).getPattern());
assertEquals(0, metadata.getGeneralDesc().possibleLengthLocalOnlyCount());
assertEquals(1, metadata.getGeneralDesc().possibleLengthCount());
assertEquals('12345678', metadata.getTollFree().getExampleNumber());
}
function testIsNumberGeographical() {
// Bahamas, mobile phone number.
assertFalse(phoneUtil.isNumberGeographical(BS_MOBILE));
// Australian fixed line number.
assertTrue(phoneUtil.isNumberGeographical(AU_NUMBER));
// International toll free number.
assertFalse(phoneUtil.isNumberGeographical(INTERNATIONAL_TOLL_FREE));
// We test that mobile phone numbers in relevant regions are indeed considered
// geographical.
// Argentina, mobile phone number.
assertTrue(phoneUtil.isNumberGeographical(AR_MOBILE));
// Mexico, mobile phone number.
assertTrue(phoneUtil.isNumberGeographical(MX_MOBILE1));
// Mexico, another mobile phone number.
assertTrue(phoneUtil.isNumberGeographical(MX_MOBILE2));
}
function testGetLengthOfGeographicalAreaCode() {
// Google MTV, which has area code '650'.
assertEquals(3, phoneUtil.getLengthOfGeographicalAreaCode(US_NUMBER));
// A North America toll-free number, which has no area code.
assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(US_TOLLFREE));
// Google London, which has area code '20'.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(GB_NUMBER));
// A UK mobile phone, which has no area code.
assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(GB_MOBILE));
// Google Buenos Aires, which has area code '11'.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(AR_NUMBER));
// Google Sydney, which has area code '2'.
assertEquals(1, phoneUtil.getLengthOfGeographicalAreaCode(AU_NUMBER));
// Italian numbers - there is no national prefix, but it still has an area
// code.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(IT_NUMBER));
// Google Singapore. Singapore has no area code and no national prefix.
assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(SG_NUMBER));
// An invalid US number (1 digit shorter), which has no area code.
assertEquals(0,
phoneUtil.getLengthOfGeographicalAreaCode(US_SHORT_BY_ONE_NUMBER));
// An international toll free number, which has no area code.
assertEquals(0,
phoneUtil.getLengthOfGeographicalAreaCode(INTERNATIONAL_TOLL_FREE));
}
function testGetLengthOfNationalDestinationCode() {
// Google MTV, which has national destination code (NDC) '650'.
assertEquals(3, phoneUtil.getLengthOfNationalDestinationCode(US_NUMBER));
// A North America toll-free number, which has NDC '800'.
assertEquals(3, phoneUtil.getLengthOfNationalDestinationCode(US_TOLLFREE));
// Google London, which has NDC '20'.
assertEquals(2, phoneUtil.getLengthOfNationalDestinationCode(GB_NUMBER));
// A UK mobile phone, which has NDC '7912'.
assertEquals(4, phoneUtil.getLengthOfNationalDestinationCode(GB_MOBILE));
// Google Buenos Aires, which has NDC '11'.
assertEquals(2, phoneUtil.getLengthOfNationalDestinationCode(AR_NUMBER));
// An Argentinian mobile which has NDC '911'.
assertEquals(3, phoneUtil.getLengthOfNationalDestinationCode(AR_MOBILE));
// Google Sydney, which has NDC '2'.
assertEquals(1, phoneUtil.getLengthOfNationalDestinationCode(AU_NUMBER));
// Google Singapore, which has NDC '6521'.
assertEquals(4, phoneUtil.getLengthOfNationalDestinationCode(SG_NUMBER));
// An invalid US number (1 digit shorter), which has no NDC.
assertEquals(0,
phoneUtil.getLengthOfNationalDestinationCode(US_SHORT_BY_ONE_NUMBER));
// A number containing an invalid country calling code, which shouldn't have
// any NDC.
/** @type {i18n.phonenumbers.PhoneNumber} */
var number = new i18n.phonenumbers.PhoneNumber();
number.setCountryCode(123);
number.setNationalNumber(6502530000);
assertEquals(0, phoneUtil.getLengthOfNationalDestinationCode(number));
// An international toll free number, which has NDC '1234'.
assertEquals(4,
phoneUtil.getLengthOfNationalDestinationCode(INTERNATIONAL_TOLL_FREE));
}
function testGetCountryMobileToken() {
assertEquals('1', i18n.phonenumbers.PhoneNumberUtil.getCountryMobileToken(
phoneUtil.getCountryCodeForRegion(RegionCode.MX)));
// Country calling code for Sweden, which has no mobile token.
assertEquals('', i18n.phonenumbers.PhoneNumberUtil.getCountryMobileToken(
phoneUtil.getCountryCodeForRegion(RegionCode.SE)));
}
function testGetSupportedRegions() {
assertTrue(phoneUtil.getSupportedRegions().length > 0);
assertTrue(goog.array.contains(
phoneUtil.getSupportedRegions(), RegionCode.US));
assertFalse(goog.array.contains(
phoneUtil.getSupportedRegions(), RegionCode.UN001));
assertFalse(goog.array.contains(phoneUtil.getSupportedRegions(), '800'));
}
function testGetSupportedGlobalNetworkCallingCodes() {
assertTrue(phoneUtil.getSupportedGlobalNetworkCallingCodes().length > 0);
assertFalse(goog.array.contains(
phoneUtil.getSupportedGlobalNetworkCallingCodes(), RegionCode.US));
assertTrue(goog.array.contains(
phoneUtil.getSupportedGlobalNetworkCallingCodes(), 800));
goog.array.forEach(
phoneUtil.getSupportedGlobalNetworkCallingCodes(),
function(countryCallingCode) {
assertEquals(RegionCode.UN001,
phoneUtil.getRegionCodeForCountryCode(countryCallingCode));
});
}
function testGetSupportedCallingCodes() {
assertTrue(phoneUtil.getSupportedCallingCodes().length > 0);
goog.array.forEach(
phoneUtil.getSupportedCallingCodes(),
function(callingCode) {
assertTrue(callingCode > 0);
assertFalse(phoneUtil.getRegionCodeForCountryCode(callingCode)
== RegionCode.ZZ);
});
// There should be more than just the global network calling codes in this set.
assertTrue(phoneUtil.getSupportedCallingCodes().length >
phoneUtil.getSupportedGlobalNetworkCallingCodes().length);
// But they should be included. Testing one of them.
assertTrue(goog.array.contains(
phoneUtil.getSupportedGlobalNetworkCallingCodes(), 979));
}
function testGetSupportedTypesForRegion() {
var PNT = i18n.phonenumbers.PhoneNumberType;
var types = phoneUtil.getSupportedTypesForRegion(RegionCode.BR);
assertTrue(goog.array.contains(types, PNT.FIXED_LINE));
// Our test data has no mobile numbers for Brazil.
assertFalse(goog.array.contains(types, PNT.MOBILE));
// UNKNOWN should never be returned.
assertFalse(goog.array.contains(types, PNT.UNKNOWN));
// In the US, many numbers are classified as FIXED_LINE_OR_MOBILE; but we
// don't want to expose this as a supported type, instead we say FIXED_LINE
// and MOBILE are both present.
types = phoneUtil.getSupportedTypesForRegion(RegionCode.US);
assertTrue(goog.array.contains(types, PNT.FIXED_LINE));
assertTrue(goog.array.contains(types, PNT.MOBILE));
assertFalse(goog.array.contains(types, PNT.FIXED_LINE_OR_MOBILE));
types = phoneUtil.getSupportedTypesForRegion(RegionCode.ZZ);
assertTrue(types.length == 0);
}
function testGetSupportedTypesForNonGeoEntity() {
var PNT = i18n.phonenumbers.PhoneNumberType;
var types = phoneUtil.getSupportedTypesForNonGeoEntity(999);
// No data exists for 999 at all, no types should be returned.
assertTrue(types.length == 0);
types = phoneUtil.getSupportedTypesForNonGeoEntity(979);
assertTrue(goog.array.contains(types, PNT.PREMIUM_RATE));
// Our test data has no mobile numbers for Brazil.
assertFalse(goog.array.contains(types, PNT.MOBILE));
// UNKNOWN should never be returned.
assertFalse(goog.array.contains(types, PNT.UNKNOWN));
}
function testGetNationalSignificantNumber() {
assertEquals('6502530000',
phoneUtil.getNationalSignificantNumber(US_NUMBER));
// An Italian mobile number.
assertEquals('345678901',
phoneUtil.getNationalSignificantNumber(IT_MOBILE));
// An Italian fixed line number.
assertEquals('0236618300',
phoneUtil.getNationalSignificantNumber(IT_NUMBER));
assertEquals('12345678',
phoneUtil.getNationalSignificantNumber(INTERNATIONAL_TOLL_FREE));
// An empty number.
/** @type {i18n.phonenumbers.PhoneNumber} */
var emptyNumber = new i18n.phonenumbers.PhoneNumber();
assertEquals('', phoneUtil.getNationalSignificantNumber(emptyNumber));
}
function testGetNationalSignificantNumber_ManyLeadingZeros() {
/** @type {i18n.phonenumbers.PhoneNumber} */
var number = new i18n.phonenumbers.PhoneNumber();
number.setCountryCode(1);
number.setNationalNumber(650);
number.setItalianLeadingZero(true);
number.setNumberOfLeadingZeros(2);
assertEquals('00650', phoneUtil.getNationalSignificantNumber(number));
// Set a bad value; we shouldn't crash, we shouldn't output any leading zeros
// at all.
number.setNumberOfLeadingZeros(-3);
assertEquals('650', phoneUtil.getNationalSignificantNumber(number));
}
function testGetExampleNumber() {
var PNT = i18n.phonenumbers.PhoneNumberType;
assertTrue(DE_NUMBER.equals(phoneUtil.getExampleNumber(RegionCode.DE)));
assertTrue(DE_NUMBER.equals(
phoneUtil.getExampleNumberForType(RegionCode.DE, PNT.FIXED_LINE)));
// Should return the same response if asked for FIXED_LINE_OR_MOBILE too.
assertTrue(DE_NUMBER.equals(
phoneUtil.getExampleNumberForType(
RegionCode.DE, PNT.FIXED_LINE_OR_MOBILE)));
// We have data for the US, but no data for VOICEMAIL.
assertNull(
phoneUtil.getExampleNumberForType(RegionCode.US, PNT.VOICEMAIL));
assertNotNull(
phoneUtil.getExampleNumberForType(RegionCode.US, PNT.FIXED_LINE));
assertNotNull(phoneUtil.getExampleNumberForType(RegionCode.US, PNT.MOBILE));
// CS is an invalid region, so we have no data for it.
assertNull(phoneUtil.getExampleNumberForType(RegionCode.CS, PNT.MOBILE));
// RegionCode 001 is reserved for supporting non-geographical country calling
// code. We don't support getting an example number for it with this method.
assertNull(phoneUtil.getExampleNumber(RegionCode.UN001));
}
function testGetExampleNumberForNonGeoEntity() {
assertTrue(INTERNATIONAL_TOLL_FREE.equals(
phoneUtil.getExampleNumberForNonGeoEntity(800)));
assertTrue(UNIVERSAL_PREMIUM_RATE.equals(
phoneUtil.getExampleNumberForNonGeoEntity(979)));
}
function testConvertAlphaCharactersInNumber() {
/** @type {string} */
var input = '1800-ABC-DEF';
// Alpha chars are converted to digits; everything else is left untouched.
/** @type {string} */
var expectedOutput = '1800-222-333';
assertEquals(expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.convertAlphaCharactersInNumber(input));
}
function testNormaliseRemovePunctuation() {
/** @type {string} */
var inputNumber = '034-56&+#2\u00AD34';
/** @type {string} */
var expectedOutput = '03456234';
assertEquals('Conversion did not correctly remove punctuation',
expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.normalize(inputNumber));
}
function testNormaliseReplaceAlphaCharacters() {
/** @type {string} */
var inputNumber = '034-I-am-HUNGRY';
/** @type {string} */
var expectedOutput = '034426486479';
assertEquals('Conversion did not correctly replace alpha characters',
expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.normalize(inputNumber));
}
function testNormaliseOtherDigits() {
/** @type {string} */
var inputNumber = '\uFF125\u0665';
/** @type {string} */
var expectedOutput = '255';
assertEquals('Conversion did not correctly replace non-latin digits',
expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.normalize(inputNumber));
// Eastern-Arabic digits.
inputNumber = '\u06F52\u06F0';
expectedOutput = '520';
assertEquals('Conversion did not correctly replace non-latin digits',
expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.normalize(inputNumber));
}
function testNormaliseStripAlphaCharacters() {
/** @type {string} */
var inputNumber = '034-56&+a#234';
/** @type {string} */
var expectedOutput = '03456234';
assertEquals('Conversion did not correctly remove alpha character',
expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.normalizeDigitsOnly(inputNumber));
}
function testNormaliseStripNonDiallableCharacters() {
/** @type {string} */
var inputNumber = '03*4-56&+1a#234';
/** @type {string} */
var expectedOutput = '03*456+1#234';
assertEquals('Conversion did not correctly remove non-diallable characters',
expectedOutput,
i18n.phonenumbers.PhoneNumberUtil.normalizeDiallableCharsOnly(
inputNumber));
}
function testFormatUSNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('650 253 0000',
phoneUtil.format(US_NUMBER, PNF.NATIONAL));
assertEquals('+1 650 253 0000',
phoneUtil.format(US_NUMBER, PNF.INTERNATIONAL));
assertEquals('800 253 0000',
phoneUtil.format(US_TOLLFREE, PNF.NATIONAL));
assertEquals('+1 800 253 0000',
phoneUtil.format(US_TOLLFREE, PNF.INTERNATIONAL));
assertEquals('900 253 0000',
phoneUtil.format(US_PREMIUM, PNF.NATIONAL));
assertEquals('+1 900 253 0000',
phoneUtil.format(US_PREMIUM, PNF.INTERNATIONAL));
assertEquals('tel:+1-900-253-0000',
phoneUtil.format(US_PREMIUM, PNF.RFC3966));
// Numbers with all zeros in the national number part will be formatted by
// using the raw_input if that is available no matter which format is
// specified.
assertEquals('000-000-0000',
phoneUtil.format(US_SPOOF_WITH_RAW_INPUT, PNF.NATIONAL));
assertEquals('0', phoneUtil.format(US_SPOOF, PNF.NATIONAL));
}
function testFormatBSNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('242 365 1234',
phoneUtil.format(BS_NUMBER, PNF.NATIONAL));
assertEquals('+1 242 365 1234',
phoneUtil.format(BS_NUMBER, PNF.INTERNATIONAL));
}
function testFormatGBNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('(020) 7031 3000',
phoneUtil.format(GB_NUMBER, PNF.NATIONAL));
assertEquals('+44 20 7031 3000',
phoneUtil.format(GB_NUMBER, PNF.INTERNATIONAL));
assertEquals('(07912) 345 678',
phoneUtil.format(GB_MOBILE, PNF.NATIONAL));
assertEquals('+44 7912 345 678',
phoneUtil.format(GB_MOBILE, PNF.INTERNATIONAL));
}
function testFormatDENumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
/** @type {i18n.phonenumbers.PhoneNumber} */
var deNumber = new i18n.phonenumbers.PhoneNumber();
deNumber.setCountryCode(49);
deNumber.setNationalNumber(301234);
assertEquals('030/1234',
phoneUtil.format(deNumber, PNF.NATIONAL));
assertEquals('+49 30/1234',
phoneUtil.format(deNumber, PNF.INTERNATIONAL));
assertEquals('tel:+49-30-1234',
phoneUtil.format(deNumber, PNF.RFC3966));
deNumber = new i18n.phonenumbers.PhoneNumber();
deNumber.setCountryCode(49);
deNumber.setNationalNumber(291123);
assertEquals('0291 123',
phoneUtil.format(deNumber, PNF.NATIONAL));
assertEquals('+49 291 123',
phoneUtil.format(deNumber, PNF.INTERNATIONAL));
deNumber = new i18n.phonenumbers.PhoneNumber();
deNumber.setCountryCode(49);
deNumber.setNationalNumber(29112345678);
assertEquals('0291 12345678',
phoneUtil.format(deNumber, PNF.NATIONAL));
assertEquals('+49 291 12345678',
phoneUtil.format(deNumber, PNF.INTERNATIONAL));
deNumber = new i18n.phonenumbers.PhoneNumber();
deNumber.setCountryCode(49);
deNumber.setNationalNumber(912312345);
assertEquals('09123 12345',
phoneUtil.format(deNumber, PNF.NATIONAL));
assertEquals('+49 9123 12345',
phoneUtil.format(deNumber, PNF.INTERNATIONAL));
deNumber = new i18n.phonenumbers.PhoneNumber();
deNumber.setCountryCode(49);
deNumber.setNationalNumber(80212345);
assertEquals('08021 2345',
phoneUtil.format(deNumber, PNF.NATIONAL));
assertEquals('+49 8021 2345',
phoneUtil.format(deNumber, PNF.INTERNATIONAL));
// Note this number is correctly formatted without national prefix. Most of
// the numbers that are treated as invalid numbers by the library are short
// numbers, and they are usually not dialed with national prefix.
assertEquals('1234',
phoneUtil.format(DE_SHORT_NUMBER, PNF.NATIONAL));
assertEquals('+49 1234',
phoneUtil.format(DE_SHORT_NUMBER, PNF.INTERNATIONAL));
deNumber = new i18n.phonenumbers.PhoneNumber();
deNumber.setCountryCode(49);
deNumber.setNationalNumber(41341234);
assertEquals('04134 1234',
phoneUtil.format(deNumber, PNF.NATIONAL));
}
function testFormatITNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('02 3661 8300',
phoneUtil.format(IT_NUMBER, PNF.NATIONAL));
assertEquals('+39 02 3661 8300',
phoneUtil.format(IT_NUMBER, PNF.INTERNATIONAL));
assertEquals('+390236618300',
phoneUtil.format(IT_NUMBER, PNF.E164));
assertEquals('345 678 901',
phoneUtil.format(IT_MOBILE, PNF.NATIONAL));
assertEquals('+39 345 678 901',
phoneUtil.format(IT_MOBILE, PNF.INTERNATIONAL));
assertEquals('+39345678901',
phoneUtil.format(IT_MOBILE, PNF.E164));
}
function testFormatAUNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('02 3661 8300',
phoneUtil.format(AU_NUMBER, PNF.NATIONAL));
assertEquals('+61 2 3661 8300',
phoneUtil.format(AU_NUMBER, PNF.INTERNATIONAL));
assertEquals('+61236618300',
phoneUtil.format(AU_NUMBER, PNF.E164));
/** @type {i18n.phonenumbers.PhoneNumber} */
var auNumber = new i18n.phonenumbers.PhoneNumber();
auNumber.setCountryCode(61);
auNumber.setNationalNumber(1800123456);
assertEquals('1800 123 456',
phoneUtil.format(auNumber, PNF.NATIONAL));
assertEquals('+61 1800 123 456',
phoneUtil.format(auNumber, PNF.INTERNATIONAL));
assertEquals('+611800123456',
phoneUtil.format(auNumber, PNF.E164));
}
function testFormatARNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('011 8765-4321',
phoneUtil.format(AR_NUMBER, PNF.NATIONAL));
assertEquals('+54 11 8765-4321',
phoneUtil.format(AR_NUMBER, PNF.INTERNATIONAL));
assertEquals('+541187654321',
phoneUtil.format(AR_NUMBER, PNF.E164));
assertEquals('011 15 8765-4321',
phoneUtil.format(AR_MOBILE, PNF.NATIONAL));
assertEquals('+54 9 11 8765 4321',
phoneUtil.format(AR_MOBILE, PNF.INTERNATIONAL));
assertEquals('+5491187654321',
phoneUtil.format(AR_MOBILE, PNF.E164));
}
function testFormatMXNumber() {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
assertEquals('045 234 567 8900',
phoneUtil.format(MX_MOBILE1, PNF.NATIONAL));
assertEquals('+52 1 234 567 8900',
phoneUtil.format(MX_MOBILE1, PNF.INTERNATIONAL));
assertEquals('+5212345678900',
phoneUtil.format(MX_MOBILE1, PNF.E164));
assertEquals('045 55 1234 5678',
phoneUtil.format(MX_MOBILE2, PNF.NATIONAL));
assertEquals('+52 1 55 1234 5678',
phoneUtil.format(MX_MOBILE2, PNF.INTERNATIONAL));
assertEquals('+5215512345678',
phoneUtil.format(MX_MOBILE2, PNF.E164));
assertEquals('01 33 1234 5678',
phoneUtil.format(MX_NUMBER1, PNF.NATIONAL));
assertEquals('+52 33 1234 5678',
phoneUtil.format(MX_NUMBER1, PNF.INTERNATIONAL));
assertEquals('+523312345678',
phoneUtil.format(MX_NUMBER1, PNF.E164));
assertEquals('01 821 123 4567',
phoneUtil.format(MX_NUMBER2, PNF.NATIONAL));
assertEquals('+52 821 123 4567',
phoneUtil.format(MX_NUMBER2, PNF.INTERNATIONAL));
assertEquals('+528211234567',
phoneUtil.format(MX_NUMBER2, PNF.E164));
}
function testFormatOutOfCountryCallingNumber() {
assertEquals('00 1 900 253 0000',
phoneUtil.formatOutOfCountryCallingNumber(US_PREMIUM, RegionCode.DE));
assertEquals('1 650 253 0000',
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.BS));
assertEquals('00 1 650 253 0000',
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.PL));
assertEquals('011 44 7912 345 678',
phoneUtil.formatOutOfCountryCallingNumber(GB_MOBILE, RegionCode.US));
assertEquals('00 49 1234',
phoneUtil.formatOutOfCountryCallingNumber(DE_SHORT_NUMBER,
RegionCode.GB));
// Note this number is correctly formatted without national prefix. Most of
// the numbers that are treated as invalid numbers by the library are short
// numbers, and they are usually not dialed with national prefix.
assertEquals('1234',
phoneUtil.formatOutOfCountryCallingNumber(DE_SHORT_NUMBER,
RegionCode.DE));
assertEquals('011 39 02 3661 8300',
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.US));
assertEquals('02 3661 8300',
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.IT));
assertEquals('+39 02 3661 8300',
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.SG));
assertEquals('6521 8000',
phoneUtil.formatOutOfCountryCallingNumber(SG_NUMBER, RegionCode.SG));
assertEquals('011 54 9 11 8765 4321',
phoneUtil.formatOutOfCountryCallingNumber(AR_MOBILE, RegionCode.US));
assertEquals('011 800 1234 5678',
phoneUtil.formatOutOfCountryCallingNumber(INTERNATIONAL_TOLL_FREE,
RegionCode.US));
/** @type {i18n.phonenumbers.PhoneNumber} */
var arNumberWithExtn = AR_MOBILE.clone();
arNumberWithExtn.setExtension('1234');
assertEquals('011 54 9 11 8765 4321 ext. 1234',
phoneUtil.formatOutOfCountryCallingNumber(arNumberWithExtn,
RegionCode.US));
assertEquals('0011 54 9 11 8765 4321 ext. 1234',
phoneUtil.formatOutOfCountryCallingNumber(arNumberWithExtn,
RegionCode.AU));
assertEquals('011 15 8765-4321 ext. 1234',
phoneUtil.formatOutOfCountryCallingNumber(arNumberWithExtn,
RegionCode.AR));
}
function testFormatOutOfCountryWithInvalidRegion() {
// AQ/Antarctica isn't a valid region code for phone number formatting,
// so this falls back to intl formatting.
assertEquals('+1 650 253 0000',
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.AQ));
// For region code 001, the out-of-country format always turns into the
// international format.
assertEquals('+1 650 253 0000',
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.UN001));
}
function testFormatOutOfCountryWithPreferredIntlPrefix() {
// This should use 0011, since that is the preferred international prefix
// (both 0011 and 0012 are accepted as possible international prefixes in our
// test metadta.)
assertEquals('0011 39 02 3661 8300',
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER,
RegionCode.AU));
}
function testFormatOutOfCountryKeepingAlphaChars() {
/** @type {i18n.phonenumbers.PhoneNumber} */
var alphaNumericNumber = new i18n.phonenumbers.PhoneNumber();
alphaNumericNumber.setCountryCode(1);
alphaNumericNumber.setNationalNumber(8007493524);
alphaNumericNumber.setRawInput('1800 six-flag');
assertEquals('0011 1 800 SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
alphaNumericNumber.setRawInput('1-800-SIX-flag');
assertEquals('0011 1 800-SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
alphaNumericNumber.setRawInput('Call us from UK: 00 1 800 SIX-flag');
assertEquals('0011 1 800 SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
alphaNumericNumber.setRawInput('800 SIX-flag');
assertEquals('0011 1 800 SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
// Formatting from within the NANPA region.
assertEquals('1 800 SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.US));
assertEquals('1 800 SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.BS));
// Testing that if the raw input doesn't exist, it is formatted using
// formatOutOfCountryCallingNumber.
alphaNumericNumber.clearRawInput();
assertEquals('00 1 800 749 3524',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.DE));
// Testing AU alpha number formatted from Australia.
alphaNumericNumber.setCountryCode(61);
alphaNumericNumber.setNationalNumber(827493524);
alphaNumericNumber.setRawInput('+61 82749-FLAG');
// This number should have the national prefix fixed.
assertEquals('082749-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
alphaNumericNumber.setRawInput('082749-FLAG');
assertEquals('082749-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
alphaNumericNumber.setNationalNumber(18007493524);
alphaNumericNumber.setRawInput('1-800-SIX-flag');
// This number should not have the national prefix prefixed, in accordance
// with the override for this specific formatting rule.
assertEquals('1-800-SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AU));
// The metadata should not be permanently changed, since we copied it before
// modifying patterns. Here we check this.
alphaNumericNumber.setNationalNumber(1800749352);
assertEquals('1800 749 352',
phoneUtil.formatOutOfCountryCallingNumber(alphaNumericNumber,
RegionCode.AU));
// Testing a region with multiple international prefixes.
assertEquals('+61 1-800-SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.SG));
// Testing the case of calling from a non-supported region.
assertEquals('+61 1-800-SIX-FLAG',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.AQ));
// Testing the case with an invalid country calling code.
alphaNumericNumber.setCountryCode(0);
alphaNumericNumber.setNationalNumber(18007493524);
alphaNumericNumber.setRawInput('1-800-SIX-flag');
// Uses the raw input only.
assertEquals('1-800-SIX-flag',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.DE));
// Testing the case of an invalid alpha number.
alphaNumericNumber.setCountryCode(1);
alphaNumericNumber.setNationalNumber(80749);
alphaNumericNumber.setRawInput('180-SIX');
// No country-code stripping can be done.
assertEquals('00 1 180-SIX',
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber,
RegionCode.DE));
// Testing the case of calling from a non-supported region.
alphaNumericNumber.setCountryCode(1);
alphaNumericNumber.setNationalNumber(80749);
alphaNumericNumber.setRawInput('180-SIX');
// No country-code stripping can be done since the number is invalid.