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