1// Copyright 2013 the V8 project authors. All rights reserved.
2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7// 1.  Redistributions of source code must retain the above copyright
8//     notice, this list of conditions and the following disclaimer.
9// 2.  Redistributions in binary form must reproduce the above copyright
10//     notice, this list of conditions and the following disclaimer in the
11//     documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24description("KDE JS Test");
25var h = "a\xefc";
26var u = "a\u1234c";
27var z = "\x00";
28
29shouldBe("h.charCodeAt(1)", "239");
30shouldBe("u.charCodeAt(1)", "4660");
31shouldBe("escape(h)", "'a%EFc'");
32shouldBe("escape(u)", "'a%u1234c'");
33shouldBe("escape(z)", "'%00'");
34shouldBe("unescape(escape(h))", "h");
35shouldBe("unescape(escape(u))", "u");
36shouldBe("unescape(escape(z))", "z");
37
38shouldBeTrue("isNaN(NaN)");
39shouldBeTrue("isNaN('NaN')");
40shouldBeFalse("isNaN('1')");
41
42shouldBeTrue("isFinite(1)");
43shouldBeTrue("isFinite('1')");
44
45// all should return NaN because 1st char is non-number
46shouldBeFalse("isFinite('a')");
47shouldBe('isNaN(parseInt("Hello", 8))', "true");
48shouldBe('isNaN(parseInt("FFF", 10))', "true");
49shouldBe('isNaN(parseInt(".5", 10))', "true");
50
51shouldBeFalse("isFinite(Infinity)");
52shouldBeFalse("isFinite('Infinity')");
53
54shouldBeTrue("isNaN(parseInt())");
55shouldBeTrue("isNaN(parseInt(''))");
56shouldBeTrue("isNaN(parseInt(' '))");
57shouldBeTrue("isNaN(parseInt('a'))");
58shouldBe("parseInt(1)", "1");
59shouldBe("parseInt(1234567890123456)", "1234567890123456");
60shouldBe("parseInt(1.2)", "1");
61shouldBe("parseInt(' 2.3')", "2");
62shouldBe("parseInt('0x10')", "16");
63shouldBe("parseInt('11', 0)", "11");
64shouldBe("parseInt('F', 16)", "15");
65
66shouldBeTrue("isNaN(parseInt('10', 40))");
67shouldBe("parseInt('3x')", "3");
68shouldBe("parseInt('3 x')", "3");
69shouldBeTrue("isNaN(parseInt('Infinity'))");
70
71// all should return 15
72shouldBe('parseInt("15")', "15");
73shouldBe('parseInt("015")', "15"); // ES5 prohibits parseInt from handling octal, see annex E.
74shouldBe('parseInt("0xf")', "15");
75shouldBe('parseInt("15", 0)', "15");
76shouldBe('parseInt("15", 10)', "15");
77shouldBe('parseInt("F", 16)', "15");
78shouldBe('parseInt("17", 8)', "15");
79shouldBe('parseInt("15.99", 10)', "15");
80shouldBe('parseInt("FXX123", 16)', "15");
81shouldBe('parseInt("1111", 2)', "15");
82shouldBe('parseInt("15*3", 10)', "15");
83
84// this should be 0
85shouldBe('parseInt("0x7", 10)', "0");
86shouldBe('parseInt("1x7", 10)', "1");
87
88shouldBeTrue("isNaN(parseFloat())");
89shouldBeTrue("isNaN(parseFloat(''))");
90shouldBeTrue("isNaN(parseFloat(' '))");
91shouldBeTrue("isNaN(parseFloat('a'))");
92shouldBe("parseFloat(1)", "1");
93shouldBe("parseFloat(' 2.3')", "2.3");
94shouldBe("parseFloat('3.1 x', 3)", "3.1");
95shouldBe("parseFloat('3.1x', 3)", "3.1");
96shouldBeFalse("isFinite(parseFloat('Infinity'))");
97shouldBeFalse("delete NaN");
98shouldBeFalse("delete Infinity");
99shouldBeFalse("delete undefined");
100