|
1 // Copyright 2012 Google Inc. All rights reserved. |
|
2 // This code is governed by the BSD license found in the LICENSE file. |
|
3 |
|
4 /** |
|
5 * @description Tests that Intl.NumberFormat.prototype.format |
|
6 * handles NaN, Infinity, and -Infinity properly. |
|
7 * @author: Roozbeh Pournader |
|
8 */ |
|
9 |
|
10 // FIXME: We are only listing Numeric_Type=Decimal. May need to add more |
|
11 // when the spec clarifies. Current as of Unicode 6.1. |
|
12 var hasUnicodeDigits = new RegExp('.*([' + |
|
13 '0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F' + |
|
14 '\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF' + |
|
15 '\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0E50-\u0E59\u0ED0-\u0ED9' + |
|
16 '\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819' + |
|
17 '\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59' + |
|
18 '\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9' + |
|
19 '\uA900-\uA909\uA9D0-\uA9D9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19' + |
|
20 ']|' + |
|
21 '\uD801[\uDCA0-\uDCA9]|' + |
|
22 '\uD804[\uDC66-\uDC6F\uDCF0-\uDCF9\uDD36-\uDD3F\uDDD0-\uDDD9]|' + |
|
23 '\uD805[\uDEC0-\uDEC9]|' + |
|
24 '\uD835[\uDFCE-\uDFFF])'); |
|
25 |
|
26 var formatter = new Intl.NumberFormat(); |
|
27 var formattedNaN = formatter.format(NaN); |
|
28 var formattedInfinity = formatter.format(Infinity); |
|
29 var formattedNegativeInfinity = formatter.format(-Infinity); |
|
30 |
|
31 if (formattedNaN === formattedInfinity) { |
|
32 $ERROR('Intl.NumberFormat formats NaN and Infinity the ' + |
|
33 'same way.'); |
|
34 } |
|
35 |
|
36 if (formattedNaN === formattedNegativeInfinity) { |
|
37 $ERROR('Intl.NumberFormat formats NaN and negative ' + |
|
38 'Infinity the same way.'); |
|
39 } |
|
40 |
|
41 if (formattedInfinity === formattedNegativeInfinity) { |
|
42 $ERROR('Intl.NumberFormat formats Infinity and ' + |
|
43 'negative Infinity the same way.'); |
|
44 } |
|
45 |
|
46 if (hasUnicodeDigits.test(formattedNaN)) { |
|
47 $ERROR('Intl.NumberFormat formats NaN using a digit.'); |
|
48 } |
|
49 |
|
50 if (hasUnicodeDigits.test(formattedInfinity)) { |
|
51 $ERROR('Intl.NumberFormat formats Infinity using a ' + |
|
52 'digit.'); |
|
53 } |
|
54 |
|
55 if (hasUnicodeDigits.test(formattedNegativeInfinity)) { |
|
56 $ERROR('Intl.NumberFormat formats negative Infinity ' + |
|
57 'using a digit.'); |
|
58 } |
|
59 |