Simple ES6 feature: Number constructor extras
[WebKit-https.git] / LayoutTests / js / script-tests / number-constructor.js
1 description('This test case tests the Number constructor.');
2
3 // isFinite
4 shouldBeTrue('Number.isFinite(0)');
5 shouldBeTrue('Number.isFinite(-0)');
6 shouldBeTrue('Number.isFinite(1)');
7 shouldBeTrue('Number.isFinite(-1)');
8 shouldBeTrue('Number.isFinite(1.0)');
9 shouldBeTrue('Number.isFinite(1.1)');
10 shouldBeTrue('Number.isFinite(-1.0)');
11 shouldBeTrue('Number.isFinite(-1.1)');
12 shouldBeTrue('Number.isFinite(Number.MAX_SAFE_INTEGER)');
13 shouldBeTrue('Number.isFinite(Number.MIN_SAFE_INTEGER)');
14 shouldBeTrue('Number.isFinite(Number.MAX_VALUE)');
15 shouldBeTrue('Number.isFinite(Number.MIN_VALUE)');
16 shouldBeFalse('Number.isFinite()');
17 shouldBeFalse('Number.isFinite({})');
18 shouldBeFalse('Number.isFinite([])');
19 shouldBeFalse('Number.isFinite(true)');
20 shouldBeFalse('Number.isFinite(false)');
21 shouldBeFalse('Number.isFinite(null)');
22 shouldBeFalse('Number.isFinite(Number.NaN)');
23 shouldBeFalse('Number.isFinite(Number.POSITIVE_INFINITY)');
24 shouldBeFalse('Number.isFinite(Number.NEGATIVE_INFINITY)');
25 shouldThrow('Number.isFinite(foo)');
26
27 // isInteger
28 shouldBeTrue('Number.isInteger(0)');
29 shouldBeTrue('Number.isInteger(-0)');
30 shouldBeTrue('Number.isInteger(1)');
31 shouldBeTrue('Number.isInteger(-1)');
32 shouldBeTrue('Number.isInteger(1.0)');
33 shouldBeTrue('Number.isInteger(-1.0)');
34 shouldBeTrue('Number.isInteger(Number.MAX_SAFE_INTEGER)');
35 shouldBeTrue('Number.isInteger(Number.MIN_SAFE_INTEGER)');
36 shouldBeTrue('Number.isInteger(Number.MAX_VALUE)');
37 shouldBeFalse('Number.isInteger(Number.MIN_VALUE)');
38 shouldBeFalse('Number.isInteger(1.1)');
39 shouldBeFalse('Number.isInteger(-1.1)');
40 shouldBeFalse('Number.isInteger()');
41 shouldBeFalse('Number.isInteger({})');
42 shouldBeFalse('Number.isInteger([])');
43 shouldBeFalse('Number.isInteger(true)');
44 shouldBeFalse('Number.isInteger(false)');
45 shouldBeFalse('Number.isInteger(null)');
46 shouldBeFalse('Number.isInteger(Number.NaN)');
47 shouldBeFalse('Number.isInteger(Number.POSITIVE_INFINITY)');
48 shouldBeFalse('Number.isInteger(Number.NEGATIVE_INFINITY)');
49 shouldThrow('Number.isInteger(foo)');
50
51 // isNaN
52 shouldBeTrue('Number.isNaN(Number.NaN)');
53 shouldBeFalse('Number.isNaN(0)');
54 shouldBeFalse('Number.isNaN(-0)');
55 shouldBeFalse('Number.isNaN(1)');
56 shouldBeFalse('Number.isNaN(-1)');
57 shouldBeFalse('Number.isNaN(1.0)');
58 shouldBeFalse('Number.isNaN(1.1)');
59 shouldBeFalse('Number.isNaN(-1.0)');
60 shouldBeFalse('Number.isNaN(-1.1)');
61 shouldBeFalse('Number.isNaN()');
62 shouldBeFalse('Number.isNaN({})');
63 shouldBeFalse('Number.isNaN([])');
64 shouldBeFalse('Number.isNaN(true)');
65 shouldBeFalse('Number.isNaN(false)');
66 shouldBeFalse('Number.isNaN(null)');
67 shouldBeFalse('Number.isNaN(Number.POSITIVE_INFINITY)');
68 shouldBeFalse('Number.isNaN(Number.NEGATIVE_INFINITY)');
69 shouldBeFalse('Number.isNaN(Number.MAX_SAFE_INTEGER)');
70 shouldBeFalse('Number.isNaN(Number.MIN_SAFE_INTEGER)');
71 shouldBeFalse('Number.isNaN(Number.MAX_VALUE)');
72 shouldBeFalse('Number.isNaN(Number.MIN_VALUE)');
73 shouldThrow('Number.isNaN(foo)');
74
75 // isSafeInteger
76 shouldBeTrue('Number.isSafeInteger(0)');
77 shouldBeTrue('Number.isSafeInteger(-0)');
78 shouldBeTrue('Number.isSafeInteger(1)');
79 shouldBeTrue('Number.isSafeInteger(-1)');
80 shouldBeTrue('Number.isSafeInteger(1.0)');
81 shouldBeTrue('Number.isSafeInteger(-1.0)');
82 shouldBeTrue('Number.isSafeInteger(Number.MAX_SAFE_INTEGER)');
83 shouldBeTrue('Number.isSafeInteger(Number.MAX_SAFE_INTEGER - 1)');
84 shouldBeTrue('Number.isSafeInteger(Number.MIN_SAFE_INTEGER)');
85 shouldBeTrue('Number.isSafeInteger(Number.MIN_SAFE_INTEGER + 1)');
86 shouldBeFalse('Number.isSafeInteger(1.1)');
87 shouldBeFalse('Number.isSafeInteger(-1.1)');
88 shouldBeFalse('Number.isSafeInteger()');
89 shouldBeFalse('Number.isSafeInteger({})');
90 shouldBeFalse('Number.isSafeInteger([])');
91 shouldBeFalse('Number.isSafeInteger(true)');
92 shouldBeFalse('Number.isSafeInteger(false)');
93 shouldBeFalse('Number.isSafeInteger(null)');
94 shouldBeFalse('Number.isSafeInteger(Number.NaN)');
95 shouldBeFalse('Number.isSafeInteger(Number.MAX_VALUE)');
96 shouldBeFalse('Number.isSafeInteger(Number.MIN_VALUE)');
97 shouldBeFalse('Number.isSafeInteger(Number.POSITIVE_INFINITY)');
98 shouldBeFalse('Number.isSafeInteger(Number.NEGATIVE_INFINITY)');
99 shouldBeFalse('Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)');
100 shouldBeFalse('Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)');
101 shouldThrow('Number.isSafeInteger(foo)');
102
103 // parseFloat
104 shouldBe('Number.parseFloat("0")', '0');
105 shouldBe('Number.parseFloat("-0")', '-0');
106 shouldBe('Number.parseFloat("1")', '1');
107 shouldBe('Number.parseFloat("-1")', '-1');
108 shouldBe('Number.parseFloat("1.1")', '1.1');
109 shouldBe('Number.parseFloat("-1.1")', '-1.1');
110 shouldBe('Number.parseFloat("10E6")', '10E6');
111 shouldBe('Number.parseFloat("0xA")', '0');
112 shouldBe('Number.parseFloat("050")', '50');
113 shouldBe('Number.parseFloat(050)', '40');
114 shouldBe('Number.parseFloat("0x20")', '0');
115 shouldBe('Number.parseFloat(0x20)', '32');
116 shouldBe('Number.parseFloat()', 'NaN');
117 shouldBe('Number.parseFloat({})', 'NaN');
118 shouldBe('Number.parseFloat([])', 'NaN');
119 shouldBe('Number.parseFloat(true)', 'NaN');
120 shouldBe('Number.parseFloat(false)', 'NaN');
121 shouldBe('Number.parseFloat(null)', 'NaN');
122 shouldBe('Number.parseFloat(Number.NaN)', 'NaN');
123 shouldBe('Number.parseFloat("1.7976931348623157E308")', '1.7976931348623157e+308');
124 shouldBe('Number.parseFloat("1.80E308")', "Infinity");
125 shouldBe('Number.parseFloat("5E-324")', '5e-324');
126 shouldBe('Number.parseFloat("5E-325")', '0');
127 shouldBe('Number.parseFloat("20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")', '2e+307');
128 shouldBe('Number.parseFloat("200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")', 'Infinity');
129 shouldThrow('Number.parseFloat(foo)');
130
131 // parseInt
132 shouldBe('Number.parseInt("0")', '0');
133 shouldBe('Number.parseInt("-0")', '-0');
134 shouldBe('Number.parseInt("1")', '1');
135 shouldBe('Number.parseInt("-1")', '-1');
136 shouldBe('Number.parseInt("1.1")', '1');
137 shouldBe('Number.parseInt("-1.1")', '-1');
138 shouldBe('Number.parseInt("10E6")', '10');
139 shouldBe('Number.parseInt("0xA")', '10');
140 shouldBe('Number.parseInt("050")', '50');
141 shouldBe('Number.parseInt("050", 8)', '40');
142 shouldBe('Number.parseInt(050)', '40');
143 shouldBe('Number.parseInt("0x20")', '32');
144 shouldBe('Number.parseInt("0x20", 16)', '32');
145 shouldBe('Number.parseInt("20", 16)', '32');
146 shouldBe('Number.parseInt(0x20)', '32');
147 shouldBe('Number.parseInt()', 'NaN');
148 shouldBe('Number.parseInt({})', 'NaN');
149 shouldBe('Number.parseInt([])', 'NaN');
150 shouldBe('Number.parseInt(true)', 'NaN');
151 shouldBe('Number.parseInt(false)', 'NaN');
152 shouldBe('Number.parseInt(null)', 'NaN');
153 shouldBe('Number.parseInt(Number.NaN)', 'NaN');
154 shouldBe('Number.parseInt("1.7976931348623157E308")', '1');
155 shouldBe('Number.parseInt("1.80E308")', '1');
156 shouldBe('Number.parseInt("5E-324")', '5');
157 shouldBe('Number.parseInt("5E-325")', '5');
158 shouldBe('Number.parseInt("20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")', '2e+307');
159 shouldBe('Number.parseInt("200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")', 'Infinity');
160 shouldThrow('Number.parseInt(foo)');