• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @license
3 * Copyright (C) 2018 The Libphonenumber Authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @fileoverview  Unit tests for the ShortNumberInfo.
20 *
21 * Note that these tests use the test metadata for PhoneNumberUtil related
22 * operations, but the real short number metadata for testing ShortNumberInfo
23 * specific operations. This is not intentional, but mirrors the current state
24 * of the Java test suite.
25 *
26 * @author James Wright
27 */
28goog.provide('i18n.phonenumbers.ShortNumberInfoTest');
29goog.setTestOnly();
30
31goog.require('goog.testing.jsunit');
32goog.require('i18n.phonenumbers.PhoneNumber');
33goog.require('i18n.phonenumbers.PhoneNumberUtil');
34goog.require('i18n.phonenumbers.RegionCode');
35goog.require('i18n.phonenumbers.ShortNumberInfo');
36
37
38/** @type {i18n.phonenumbers.ShortNumberInfo} */
39var shortInfo = i18n.phonenumbers.ShortNumberInfo.getInstance();
40
41
42/** @type {i18n.phonenumbers.PhoneNumberUtil} */
43var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
44
45var RegionCode = i18n.phonenumbers.RegionCode;
46
47function testIsPossibleShortNumber() {
48  var possibleNumber = new i18n.phonenumbers.PhoneNumber();
49  possibleNumber.setCountryCode(33);
50  possibleNumber.setNationalNumber(123456);
51  assertTrue(shortInfo.isPossibleShortNumber(possibleNumber));
52  assertTrue(shortInfo.isPossibleShortNumberForRegion(
53      phoneUtil.parse('123456', RegionCode.FR), RegionCode.FR));
54
55  var impossibleNumber = new i18n.phonenumbers.PhoneNumber();
56  impossibleNumber.setCountryCode(33);
57  impossibleNumber.setNationalNumber(9);
58  assertFalse(shortInfo.isPossibleShortNumber(impossibleNumber));
59
60  // Note that GB and GG share the country calling code 44, and that this number
61  // is possible but not valid.
62  var impossibleUkNumber = new i18n.phonenumbers.PhoneNumber();
63  impossibleUkNumber.setCountryCode(44);
64  impossibleUkNumber.setNationalNumber(11001);
65  assertTrue(shortInfo.isPossibleShortNumber(impossibleUkNumber));
66}
67
68function testIsValidShortNumber() {
69  var shortNumber1 = new i18n.phonenumbers.PhoneNumber();
70  shortNumber1.setCountryCode(33);
71  shortNumber1.setNationalNumber(1010);
72  assertTrue(shortInfo.isValidShortNumber(shortNumber1));
73  assertTrue(shortInfo.isValidShortNumberForRegion(
74      phoneUtil.parse('1010', RegionCode.FR), RegionCode.FR));
75  var shortNumber2 = new i18n.phonenumbers.PhoneNumber();
76  shortNumber2.setCountryCode(33);
77  shortNumber2.setNationalNumber(123456);
78  assertFalse(shortInfo.isValidShortNumber(shortNumber2));
79  assertFalse(shortInfo.isValidShortNumberForRegion(
80      phoneUtil.parse('123456', RegionCode.FR), RegionCode.FR));
81
82  // Note that GB and GG share the country calling code 44.
83  var shortNumber3 = new i18n.phonenumbers.PhoneNumber();
84  shortNumber3.setCountryCode(44);
85  shortNumber3.setNationalNumber(18001);
86  assertTrue(shortInfo.isValidShortNumber(shortNumber3));
87}
88
89function testIsCarrierSpecific() {
90  var carrierSpecificNumber = new i18n.phonenumbers.PhoneNumber();
91  carrierSpecificNumber.setCountryCode(1);
92  carrierSpecificNumber.setNationalNumber(33669);
93  assertTrue(shortInfo.isCarrierSpecific(carrierSpecificNumber));
94  assertTrue(shortInfo.isCarrierSpecificForRegion(
95      phoneUtil.parse('33669', RegionCode.US), RegionCode.US));
96
97  var notCarrierSpecificNumber = new i18n.phonenumbers.PhoneNumber();
98  notCarrierSpecificNumber.setCountryCode(1);
99  notCarrierSpecificNumber.setNationalNumber(911);
100  assertFalse(shortInfo.isCarrierSpecific(notCarrierSpecificNumber));
101  assertFalse(shortInfo.isCarrierSpecificForRegion(
102      phoneUtil.parse('911', RegionCode.US), RegionCode.US));
103
104  var carrierSpecificNumberForSomeRegion = new i18n.phonenumbers.PhoneNumber();
105  carrierSpecificNumberForSomeRegion.setCountryCode(1);
106  carrierSpecificNumberForSomeRegion.setNationalNumber(211);
107  assertTrue(shortInfo.isCarrierSpecific(carrierSpecificNumberForSomeRegion));
108  assertTrue(shortInfo.isCarrierSpecificForRegion(
109      carrierSpecificNumberForSomeRegion, RegionCode.US));
110  assertFalse(shortInfo.isCarrierSpecificForRegion(
111      carrierSpecificNumberForSomeRegion, RegionCode.BB));
112}
113
114function testIsSmsService() {
115  var smsServiceNumberForSomeRegion = new i18n.phonenumbers.PhoneNumber();
116  smsServiceNumberForSomeRegion.setCountryCode(1);
117  smsServiceNumberForSomeRegion.setNationalNumber(21234);
118  assertTrue(shortInfo.isSmsServiceForRegion(
119      smsServiceNumberForSomeRegion, RegionCode.US));
120  assertFalse(shortInfo.isSmsServiceForRegion(
121      smsServiceNumberForSomeRegion, RegionCode.BB));
122}
123
124function testGetExpectedCost() {
125  var premiumRateExample = shortInfo.getExampleShortNumberForCost(
126      RegionCode.FR,
127      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.PREMIUM_RATE);
128  assertEquals(
129      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
130      shortInfo.getExpectedCostForRegion(
131          phoneUtil.parse(premiumRateExample, RegionCode.FR), RegionCode.FR));
132  var premiumRateNumber = new i18n.phonenumbers.PhoneNumber();
133  premiumRateNumber.setCountryCode(33);
134  premiumRateNumber.setNationalNumber(parseInt(premiumRateExample, 10));
135  assertEquals(
136      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
137      shortInfo.getExpectedCost(premiumRateNumber));
138
139  var standardRateExample = shortInfo.getExampleShortNumberForCost(
140      RegionCode.FR,
141      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.STANDARD_RATE);
142  assertEquals(
143      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
144      shortInfo.getExpectedCostForRegion(
145          phoneUtil.parse(standardRateExample, RegionCode.FR), RegionCode.FR));
146  var standardRateNumber = new i18n.phonenumbers.PhoneNumber();
147  standardRateNumber.setCountryCode(33);
148  standardRateNumber.setNationalNumber(parseInt(standardRateExample, 10));
149  assertEquals(
150      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
151      shortInfo.getExpectedCost(standardRateNumber));
152
153  var tollFreeExample = shortInfo.getExampleShortNumberForCost(
154      RegionCode.FR,
155      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE);
156  assertEquals(
157      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
158      shortInfo.getExpectedCostForRegion(
159          phoneUtil.parse(tollFreeExample, RegionCode.FR), RegionCode.FR));
160  var tollFreeNumber = new i18n.phonenumbers.PhoneNumber();
161  tollFreeNumber.setCountryCode(33);
162  tollFreeNumber.setNationalNumber(parseInt(tollFreeExample, 10));
163  assertEquals(
164      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
165      shortInfo.getExpectedCost(tollFreeNumber));
166
167  assertEquals(
168      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
169      shortInfo.getExpectedCostForRegion(
170          phoneUtil.parse('12345', RegionCode.FR), RegionCode.FR));
171  var unknownCostNumber = new i18n.phonenumbers.PhoneNumber();
172  unknownCostNumber.setCountryCode(33);
173  unknownCostNumber.setNationalNumber(12345);
174  assertEquals(
175      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
176      shortInfo.getExpectedCost(unknownCostNumber));
177
178  // Test that an invalid number may nevertheless have a cost other than
179  // UNKNOWN_COST.
180  assertFalse(shortInfo.isValidShortNumberForRegion(
181      phoneUtil.parse('116123', RegionCode.FR), RegionCode.FR));
182  assertEquals(
183      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
184      shortInfo.getExpectedCostForRegion(
185          phoneUtil.parse('116123', RegionCode.FR), RegionCode.FR));
186  var invalidNumber = new i18n.phonenumbers.PhoneNumber();
187  invalidNumber.setCountryCode(33);
188  invalidNumber.setNationalNumber(116123);
189  assertFalse(shortInfo.isValidShortNumber(invalidNumber));
190  assertEquals(
191      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
192      shortInfo.getExpectedCost(invalidNumber));
193
194  // Test a nonexistent country code.
195  assertEquals(
196      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
197      shortInfo.getExpectedCostForRegion(
198          phoneUtil.parse('911', RegionCode.US), RegionCode.ZZ));
199  unknownCostNumber = new i18n.phonenumbers.PhoneNumber();
200  unknownCostNumber.setCountryCode(123);
201  unknownCostNumber.setNationalNumber(911);
202  assertEquals(
203      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
204      shortInfo.getExpectedCost(unknownCostNumber));
205}
206
207function testGetExpectedCostForSharedCountryCallingCode() {
208  // Test some numbers which have different costs in countries sharing the same
209  // country calling code. In Australia, 1234 is premium-rate, 1194 is
210  // standard-rate, and 733 is toll-free. These are not known to be valid
211  // numbers in the Christmas Islands.
212  var ambiguousPremiumRateString = '1234';
213  var ambiguousPremiumRateNumber = new i18n.phonenumbers.PhoneNumber();
214  ambiguousPremiumRateNumber.setCountryCode(61);
215  ambiguousPremiumRateNumber.setNationalNumber(1234);
216  var ambiguousStandardRateString = '1194';
217  var ambiguousStandardRateNumber = new i18n.phonenumbers.PhoneNumber();
218  ambiguousStandardRateNumber.setCountryCode(61);
219  ambiguousStandardRateNumber.setNationalNumber(1194);
220  var ambiguousTollFreeString = '733';
221  var ambiguousTollFreeNumber = new i18n.phonenumbers.PhoneNumber();
222  ambiguousTollFreeNumber.setCountryCode(61);
223  ambiguousTollFreeNumber.setNationalNumber(733);
224  assertTrue(shortInfo.isValidShortNumber(ambiguousPremiumRateNumber));
225  assertTrue(shortInfo.isValidShortNumber(ambiguousStandardRateNumber));
226  assertTrue(shortInfo.isValidShortNumber(ambiguousTollFreeNumber));
227  assertTrue(shortInfo.isValidShortNumberForRegion(
228      phoneUtil.parse(ambiguousPremiumRateString, RegionCode.AU),
229      RegionCode.AU));
230  assertEquals(
231      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
232      shortInfo.getExpectedCostForRegion(
233          phoneUtil.parse(ambiguousPremiumRateString, RegionCode.AU),
234          RegionCode.AU));
235  assertFalse(shortInfo.isValidShortNumberForRegion(
236      phoneUtil.parse(ambiguousPremiumRateString, RegionCode.CX),
237      RegionCode.CX));
238  assertEquals(
239      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
240      shortInfo.getExpectedCostForRegion(
241          phoneUtil.parse(ambiguousPremiumRateString, RegionCode.CX),
242          RegionCode.CX));
243  // PREMIUM_RATE takes precedence over UNKNOWN_COST.
244  assertEquals(
245      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
246      shortInfo.getExpectedCost(ambiguousPremiumRateNumber));
247  assertTrue(shortInfo.isValidShortNumberForRegion(
248      phoneUtil.parse(ambiguousStandardRateString, RegionCode.AU),
249      RegionCode.AU));
250  assertEquals(
251      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
252      shortInfo.getExpectedCostForRegion(
253          phoneUtil.parse(ambiguousStandardRateString, RegionCode.AU),
254          RegionCode.AU));
255  assertFalse(shortInfo.isValidShortNumberForRegion(
256      phoneUtil.parse(ambiguousStandardRateString, RegionCode.CX),
257      RegionCode.CX));
258  assertEquals(
259      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
260      shortInfo.getExpectedCostForRegion(
261          phoneUtil.parse(ambiguousStandardRateString, RegionCode.CX),
262          RegionCode.CX));
263  assertEquals(
264      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
265      shortInfo.getExpectedCost(ambiguousStandardRateNumber));
266  assertTrue(shortInfo.isValidShortNumberForRegion(
267      phoneUtil.parse(ambiguousTollFreeString, RegionCode.AU), RegionCode.AU));
268  assertEquals(
269      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
270      shortInfo.getExpectedCostForRegion(
271          phoneUtil.parse(ambiguousTollFreeString, RegionCode.AU),
272          RegionCode.AU));
273  assertFalse(shortInfo.isValidShortNumberForRegion(
274      phoneUtil.parse(ambiguousTollFreeString, RegionCode.CX), RegionCode.CX));
275  assertEquals(
276      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
277      shortInfo.getExpectedCostForRegion(
278          phoneUtil.parse(ambiguousTollFreeString, RegionCode.CX),
279          RegionCode.CX));
280  assertEquals(
281      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
282      shortInfo.getExpectedCost(ambiguousTollFreeNumber));
283}
284
285function testExampleShortNumberPresence() {
286  assertNonEmptyString(shortInfo.getExampleShortNumber(RegionCode.AD));
287  assertNonEmptyString(shortInfo.getExampleShortNumber(RegionCode.FR));
288  assertEquals('', shortInfo.getExampleShortNumber(RegionCode.UN001));
289  assertEquals('', shortInfo.getExampleShortNumber(null));
290}
291
292function testConnectsToEmergencyNumber_US() {
293  assertTrue(shortInfo.connectsToEmergencyNumber('911', RegionCode.US));
294  assertTrue(shortInfo.connectsToEmergencyNumber('112', RegionCode.US));
295  assertFalse(shortInfo.connectsToEmergencyNumber('999', RegionCode.US));
296}
297
298function testConnectsToEmergencyNumberLongNumber_US() {
299  assertTrue(shortInfo.connectsToEmergencyNumber('9116666666', RegionCode.US));
300  assertTrue(shortInfo.connectsToEmergencyNumber('1126666666', RegionCode.US));
301  assertFalse(shortInfo.connectsToEmergencyNumber('9996666666', RegionCode.US));
302}
303
304function testConnectsToEmergencyNumberWithFormatting_US() {
305  assertTrue(shortInfo.connectsToEmergencyNumber('9-1-1', RegionCode.US));
306  assertTrue(shortInfo.connectsToEmergencyNumber('1-1-2', RegionCode.US));
307  assertFalse(shortInfo.connectsToEmergencyNumber('9-9-9', RegionCode.US));
308}
309
310function testConnectsToEmergencyNumberWithPlusSign_US() {
311  assertFalse(shortInfo.connectsToEmergencyNumber('+911', RegionCode.US));
312  assertFalse(shortInfo.connectsToEmergencyNumber('\uFF0B911', RegionCode.US));
313  assertFalse(shortInfo.connectsToEmergencyNumber(' +911', RegionCode.US));
314  assertFalse(shortInfo.connectsToEmergencyNumber('+112', RegionCode.US));
315  assertFalse(shortInfo.connectsToEmergencyNumber('+999', RegionCode.US));
316}
317
318function testConnectsToEmergencyNumber_BR() {
319  assertTrue(shortInfo.connectsToEmergencyNumber('911', RegionCode.BR));
320  assertTrue(shortInfo.connectsToEmergencyNumber('190', RegionCode.BR));
321  assertFalse(shortInfo.connectsToEmergencyNumber('999', RegionCode.BR));
322}
323
324function testConnectsToEmergencyNumberLongNumber_BR() {
325  // Brazilian emergency numbers don't work when additional digits are appended.
326  assertFalse(shortInfo.connectsToEmergencyNumber('9111', RegionCode.BR));
327  assertFalse(shortInfo.connectsToEmergencyNumber('1900', RegionCode.BR));
328  assertFalse(shortInfo.connectsToEmergencyNumber('9996', RegionCode.BR));
329}
330
331function testConnectsToEmergencyNumber_CL() {
332  assertTrue(shortInfo.connectsToEmergencyNumber('131', RegionCode.CL));
333  assertTrue(shortInfo.connectsToEmergencyNumber('133', RegionCode.CL));
334}
335
336function testConnectsToEmergencyNumberLongNumber_CL() {
337  // Chilean emergency numbers don't work when additional digits are appended.
338  assertFalse(shortInfo.connectsToEmergencyNumber('1313', RegionCode.CL));
339  assertFalse(shortInfo.connectsToEmergencyNumber('1330', RegionCode.CL));
340}
341
342function testConnectsToEmergencyNumber_AO() {
343  // Angola doesn't have any metadata for emergency numbers in the test
344  // metadata.
345  assertFalse(shortInfo.connectsToEmergencyNumber('911', RegionCode.AO));
346  assertFalse(shortInfo.connectsToEmergencyNumber('222123456', RegionCode.AO));
347  assertFalse(shortInfo.connectsToEmergencyNumber('923123456', RegionCode.AO));
348}
349
350function testConnectsToEmergencyNumber_ZW() {
351  // Zimbabwe doesn't have any metadata in the test metadata.
352  assertFalse(shortInfo.connectsToEmergencyNumber('911', RegionCode.ZW));
353  assertFalse(shortInfo.connectsToEmergencyNumber('01312345', RegionCode.ZW));
354  assertFalse(shortInfo.connectsToEmergencyNumber('0711234567', RegionCode.ZW));
355}
356
357function testIsEmergencyNumber_US() {
358  assertTrue(shortInfo.isEmergencyNumber('911', RegionCode.US));
359  assertTrue(shortInfo.isEmergencyNumber('112', RegionCode.US));
360  assertFalse(shortInfo.isEmergencyNumber('999', RegionCode.US));
361}
362
363function testIsEmergencyNumberLongNumber_US() {
364  assertFalse(shortInfo.isEmergencyNumber('9116666666', RegionCode.US));
365  assertFalse(shortInfo.isEmergencyNumber('1126666666', RegionCode.US));
366  assertFalse(shortInfo.isEmergencyNumber('9996666666', RegionCode.US));
367}
368
369function testIsEmergencyNumberWithFormatting_US() {
370  assertTrue(shortInfo.isEmergencyNumber('9-1-1', RegionCode.US));
371  assertTrue(shortInfo.isEmergencyNumber('*911', RegionCode.US));
372  assertTrue(shortInfo.isEmergencyNumber('1-1-2', RegionCode.US));
373  assertTrue(shortInfo.isEmergencyNumber('*112', RegionCode.US));
374  assertFalse(shortInfo.isEmergencyNumber('9-9-9', RegionCode.US));
375  assertFalse(shortInfo.isEmergencyNumber('*999', RegionCode.US));
376}
377
378function testIsEmergencyNumberWithPlusSign_US() {
379  assertFalse(shortInfo.isEmergencyNumber('+911', RegionCode.US));
380  assertFalse(shortInfo.isEmergencyNumber('\uFF0B911', RegionCode.US));
381  assertFalse(shortInfo.isEmergencyNumber(' +911', RegionCode.US));
382  assertFalse(shortInfo.isEmergencyNumber('+112', RegionCode.US));
383  assertFalse(shortInfo.isEmergencyNumber('+999', RegionCode.US));
384}
385
386function testIsEmergencyNumber_BR() {
387  assertTrue(shortInfo.isEmergencyNumber('911', RegionCode.BR));
388  assertTrue(shortInfo.isEmergencyNumber('190', RegionCode.BR));
389  assertFalse(shortInfo.isEmergencyNumber('999', RegionCode.BR));
390}
391
392function testIsEmergencyNumberLongNumber_BR() {
393  assertFalse(shortInfo.isEmergencyNumber('9111', RegionCode.BR));
394  assertFalse(shortInfo.isEmergencyNumber('1900', RegionCode.BR));
395  assertFalse(shortInfo.isEmergencyNumber('9996', RegionCode.BR));
396}
397
398function testIsEmergencyNumber_AO() {
399  // Angola doesn't have any metadata for emergency numbers in the test
400  // metadata.
401  assertFalse(shortInfo.isEmergencyNumber('911', RegionCode.AO));
402  assertFalse(shortInfo.isEmergencyNumber('222123456', RegionCode.AO));
403  assertFalse(shortInfo.isEmergencyNumber('923123456', RegionCode.AO));
404}
405
406function testIsEmergencyNumber_ZW() {
407  // Zimbabwe doesn't have any metadata in the test metadata.
408  assertFalse(shortInfo.isEmergencyNumber('911', RegionCode.ZW));
409  assertFalse(shortInfo.isEmergencyNumber('01312345', RegionCode.ZW));
410  assertFalse(shortInfo.isEmergencyNumber('0711234567', RegionCode.ZW));
411}
412
413function testEmergencyNumberForSharedCountryCallingCode() {
414  // Test the emergency number 112, which is valid in both Australia and the
415  // Christmas Islands.
416  assertTrue(shortInfo.isEmergencyNumber('112', RegionCode.AU));
417  assertTrue(shortInfo.isValidShortNumberForRegion(
418      phoneUtil.parse('112', RegionCode.AU), RegionCode.AU));
419  assertEquals(
420      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
421      shortInfo.getExpectedCostForRegion(
422          phoneUtil.parse('112', RegionCode.AU), RegionCode.AU));
423  assertTrue(shortInfo.isEmergencyNumber('112', RegionCode.CX));
424  assertTrue(shortInfo.isValidShortNumberForRegion(
425      phoneUtil.parse('112', RegionCode.CX), RegionCode.CX));
426  assertEquals(
427      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
428      shortInfo.getExpectedCostForRegion(
429          phoneUtil.parse('112', RegionCode.CX), RegionCode.CX));
430  var sharedEmergencyNumber = new i18n.phonenumbers.PhoneNumber();
431  sharedEmergencyNumber.setCountryCode(61);
432  sharedEmergencyNumber.setNationalNumber(112);
433  assertTrue(shortInfo.isValidShortNumber(sharedEmergencyNumber));
434  assertEquals(
435      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
436      shortInfo.getExpectedCost(sharedEmergencyNumber));
437}
438
439function testOverlappingNANPANumber() {
440  // 211 is an emergency number in Barbados, while it is a toll-free information
441  // line in Canada and the USA.
442  assertTrue(shortInfo.isEmergencyNumber('211', RegionCode.BB));
443  assertEquals(
444      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
445      shortInfo.getExpectedCostForRegion(
446          phoneUtil.parse('211', RegionCode.BB), RegionCode.BB));
447  assertFalse(shortInfo.isEmergencyNumber('211', RegionCode.US));
448  assertEquals(
449      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
450      shortInfo.getExpectedCostForRegion(
451          phoneUtil.parse('211', RegionCode.US), RegionCode.US));
452  assertFalse(shortInfo.isEmergencyNumber('211', RegionCode.CA));
453  assertEquals(
454      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.TOLL_FREE,
455      shortInfo.getExpectedCostForRegion(
456          phoneUtil.parse('211', RegionCode.CA), RegionCode.CA));
457}
458
459function testCountryCallingCodeIsNotIgnored() {
460  // +46 is the country calling code for Sweden (SE), and 40404 is a valid short
461  // number in the US.
462  assertFalse(shortInfo.isPossibleShortNumberForRegion(
463      phoneUtil.parse('+4640404', RegionCode.SE), RegionCode.US));
464  assertFalse(shortInfo.isValidShortNumberForRegion(
465      phoneUtil.parse('+4640404', RegionCode.SE), RegionCode.US));
466  assertEquals(
467      i18n.phonenumbers.ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
468      shortInfo.getExpectedCostForRegion(
469          phoneUtil.parse('+4640404', RegionCode.SE), RegionCode.US));
470}
471