Home | History | Annotate | Download | only in kde
      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 
     24 description("KDE JS Test");
     25 var h = "a\xefc";
     26 var u = "a\u1234c";
     27 var z = "\x00";
     28 
     29 shouldBe("h.charCodeAt(1)", "239");
     30 shouldBe("u.charCodeAt(1)", "4660");
     31 shouldBe("escape(h)", "'a%EFc'");
     32 shouldBe("escape(u)", "'a%u1234c'");
     33 shouldBe("escape(z)", "'%00'");
     34 shouldBe("unescape(escape(h))", "h");
     35 shouldBe("unescape(escape(u))", "u");
     36 shouldBe("unescape(escape(z))", "z");
     37 
     38 shouldBeTrue("isNaN(NaN)");
     39 shouldBeTrue("isNaN('NaN')");
     40 shouldBeFalse("isNaN('1')");
     41 
     42 shouldBeTrue("isFinite(1)");
     43 shouldBeTrue("isFinite('1')");
     44 
     45 // all should return NaN because 1st char is non-number
     46 shouldBeFalse("isFinite('a')");
     47 shouldBe('isNaN(parseInt("Hello", 8))', "true");
     48 shouldBe('isNaN(parseInt("FFF", 10))', "true");
     49 shouldBe('isNaN(parseInt(".5", 10))', "true");
     50 
     51 shouldBeFalse("isFinite(Infinity)");
     52 shouldBeFalse("isFinite('Infinity')");
     53 
     54 shouldBeTrue("isNaN(parseInt())");
     55 shouldBeTrue("isNaN(parseInt(''))");
     56 shouldBeTrue("isNaN(parseInt(' '))");
     57 shouldBeTrue("isNaN(parseInt('a'))");
     58 shouldBe("parseInt(1)", "1");
     59 shouldBe("parseInt(1234567890123456)", "1234567890123456");
     60 shouldBe("parseInt(1.2)", "1");
     61 shouldBe("parseInt(' 2.3')", "2");
     62 shouldBe("parseInt('0x10')", "16");
     63 shouldBe("parseInt('11', 0)", "11");
     64 shouldBe("parseInt('F', 16)", "15");
     65 
     66 shouldBeTrue("isNaN(parseInt('10', 40))");
     67 shouldBe("parseInt('3x')", "3");
     68 shouldBe("parseInt('3 x')", "3");
     69 shouldBeTrue("isNaN(parseInt('Infinity'))");
     70 
     71 // all should return 15
     72 shouldBe('parseInt("15")', "15");
     73 shouldBe('parseInt("015")', "15"); // ES5 prohibits parseInt from handling octal, see annex E.
     74 shouldBe('parseInt("0xf")', "15");
     75 shouldBe('parseInt("15", 0)', "15");
     76 shouldBe('parseInt("15", 10)', "15");
     77 shouldBe('parseInt("F", 16)', "15");
     78 shouldBe('parseInt("17", 8)', "15");
     79 shouldBe('parseInt("15.99", 10)', "15");
     80 shouldBe('parseInt("FXX123", 16)', "15");
     81 shouldBe('parseInt("1111", 2)', "15");
     82 shouldBe('parseInt("15*3", 10)', "15");
     83 
     84 // this should be 0
     85 shouldBe('parseInt("0x7", 10)', "0");
     86 shouldBe('parseInt("1x7", 10)', "1");
     87 
     88 shouldBeTrue("isNaN(parseFloat())");
     89 shouldBeTrue("isNaN(parseFloat(''))");
     90 shouldBeTrue("isNaN(parseFloat(' '))");
     91 shouldBeTrue("isNaN(parseFloat('a'))");
     92 shouldBe("parseFloat(1)", "1");
     93 shouldBe("parseFloat(' 2.3')", "2.3");
     94 shouldBe("parseFloat('3.1 x', 3)", "3.1");
     95 shouldBe("parseFloat('3.1x', 3)", "3.1");
     96 shouldBeFalse("isFinite(parseFloat('Infinity'))");
     97 shouldBeFalse("delete NaN");
     98 shouldBeFalse("delete Infinity");
     99 shouldBeFalse("delete undefined");
    100