Home | History | Annotate | Download | only in webkit
      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('Tests for the parseFloat function.');
     25 
     26 var nonASCIINonSpaceCharacter = String.fromCharCode(0x13A0);
     27 var illegalUTF16Sequence = String.fromCharCode(0xD800);
     28 
     29 var tab = String.fromCharCode(9);
     30 var nbsp = String.fromCharCode(0xA0);
     31 var ff = String.fromCharCode(0xC);
     32 var vt = String.fromCharCode(0xB);
     33 var cr = String.fromCharCode(0xD);
     34 var lf = String.fromCharCode(0xA);
     35 var ls = String.fromCharCode(0x2028);
     36 var ps = String.fromCharCode(0x2029);
     37 
     38 var oghamSpaceMark = String.fromCharCode(0x1680);
     39 var mongolianVowelSeparator = String.fromCharCode(0x180E);
     40 var enQuad = String.fromCharCode(0x2000);
     41 var emQuad = String.fromCharCode(0x2001);
     42 var enSpace = String.fromCharCode(0x2002);
     43 var emSpace = String.fromCharCode(0x2003);
     44 var threePerEmSpace = String.fromCharCode(0x2004);
     45 var fourPerEmSpace = String.fromCharCode(0x2005);
     46 var sixPerEmSpace = String.fromCharCode(0x2006);
     47 var figureSpace = String.fromCharCode(0x2007);
     48 var punctuationSpace = String.fromCharCode(0x2008);
     49 var thinSpace = String.fromCharCode(0x2009);
     50 var hairSpace = String.fromCharCode(0x200A);
     51 var narrowNoBreakSpace = String.fromCharCode(0x202F);
     52 var mediumMathematicalSpace = String.fromCharCode(0x205F);
     53 var ideographicSpace = String.fromCharCode(0x3000);
     54 
     55 shouldBe("parseFloat()", "NaN");
     56 shouldBe("parseFloat('')", "NaN");
     57 shouldBe("parseFloat(' ')", "NaN");
     58 shouldBe("parseFloat(' 0')", "0");
     59 shouldBe("parseFloat('0 ')", "0");
     60 shouldBe("parseFloat('x0')", "NaN");
     61 shouldBe("parseFloat('0x')", "0");
     62 shouldBe("parseFloat(' 1')", "1");
     63 shouldBe("parseFloat('1 ')", "1");
     64 shouldBe("parseFloat('x1')", "NaN");
     65 shouldBe("parseFloat('1x')", "1");
     66 shouldBe("parseFloat(' 2.3')", "2.3");
     67 shouldBe("parseFloat('2.3 ')", "2.3");
     68 shouldBe("parseFloat('x2.3')", "NaN");
     69 shouldBe("parseFloat('2.3x')", "2.3");
     70 shouldBe("parseFloat('0x2')", "0");
     71 shouldBe("parseFloat('1' + nonASCIINonSpaceCharacter)", "1");
     72 shouldBe("parseFloat(nonASCIINonSpaceCharacter + '1')", "NaN");
     73 shouldBe("parseFloat('1' + illegalUTF16Sequence)", "1");
     74 shouldBe("parseFloat(illegalUTF16Sequence + '1')", "NaN");
     75 shouldBe("parseFloat(tab + '1')", "1");
     76 shouldBe("parseFloat(nbsp + '1')", "1");
     77 shouldBe("parseFloat(ff + '1')", "1");
     78 shouldBe("parseFloat(vt + '1')", "1");
     79 shouldBe("parseFloat(cr + '1')", "1");
     80 shouldBe("parseFloat(lf + '1')", "1");
     81 shouldBe("parseFloat(ls + '1')", "1");
     82 shouldBe("parseFloat(ps + '1')", "1");
     83 shouldBe("parseFloat(oghamSpaceMark + '1')", "1");
     84 shouldBe("parseFloat(mongolianVowelSeparator + '1')", "1");
     85 shouldBe("parseFloat(enQuad + '1')", "1");
     86 shouldBe("parseFloat(emQuad + '1')", "1");
     87 shouldBe("parseFloat(enSpace + '1')", "1");
     88 shouldBe("parseFloat(emSpace + '1')", "1");
     89 shouldBe("parseFloat(threePerEmSpace + '1')", "1");
     90 shouldBe("parseFloat(fourPerEmSpace + '1')", "1");
     91 shouldBe("parseFloat(sixPerEmSpace + '1')", "1");
     92 shouldBe("parseFloat(figureSpace + '1')", "1");
     93 shouldBe("parseFloat(punctuationSpace + '1')", "1");
     94 shouldBe("parseFloat(thinSpace + '1')", "1");
     95 shouldBe("parseFloat(hairSpace + '1')", "1");
     96 shouldBe("parseFloat(narrowNoBreakSpace + '1')", "1");
     97 shouldBe("parseFloat(mediumMathematicalSpace + '1')", "1");
     98 shouldBe("parseFloat(ideographicSpace + '1')", "1");
     99