1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15assert(parseInt("123") === 123); 16assert(parseInt("+123") === 123); 17assert(parseInt("-123") === -123); 18assert(parseInt("0123") === 123); 19assert(parseInt(" 123") === 123); 20assert(parseInt(" \n 123") === 123); 21assert(parseInt(" \n 123 \t") === 123); 22assert(parseInt("0x123") === 291); 23assert(parseInt("0X123") === 291); 24assert(parseInt("123", 4) === 27); 25assert(parseInt("ABC", 16) === 2748); 26assert(parseInt("12A3") === 12); 27assert(parseInt("12.34") === 12); 28assert(isNaN(parseInt("AB"))); 29assert(isNaN(parseInt(""))); 30assert(isNaN(parseInt("-"))); 31assert(isNaN(parseInt("-", 11))); 32assert(parseInt("\u00a0123") === 123); 33assert(parseInt("\u20291 123\u00D0") === 1); 34assert(parseInt("\u00a0123", 13) === 198); 35assert(parseInt("\u2029123 1\u00D0", 11) === 146); 36assert(isNaN(parseInt("\u0009"))); 37assert(isNaN(parseInt("\u00A0"))); 38assert(parseInt("\u00A0\u00A0-1") === parseInt("-1")); 39assert(parseInt("\u00A01") === parseInt("1")); 40 41var bool = true; 42var obj = new Object(); 43var num = 8; 44var arr = [2,3,4]; 45var undef; 46 47assert(isNaN(parseInt(bool, bool))); 48assert(isNaN(parseInt(bool, obj))); 49assert(isNaN(parseInt(bool, num))); 50assert(isNaN(parseInt(bool, arr))); 51 52assert(isNaN(parseInt(obj, bool))); 53assert(isNaN(parseInt(obj, obj))); 54assert(isNaN(parseInt(obj, num))); 55assert(isNaN(parseInt(obj, arr))); 56 57assert(isNaN(parseInt(num, bool))); 58assert(parseInt(num, obj) === 8); 59assert(isNaN(parseInt(num, num))); 60assert(parseInt(num, arr) === 8); 61 62assert(isNaN(parseInt(arr, bool))); 63assert(parseInt(arr, obj) === 2); 64assert(parseInt(arr, num) === 2); 65assert(parseInt(arr, arr) === 2); 66 67assert(isNaN(parseInt(undef, bool))); 68assert(isNaN(parseInt(undef, obj))); 69assert(isNaN(parseInt(undef, num))); 70assert(isNaN(parseInt(undef, arr))); 71 72var obj = { toString : function () { throw new ReferenceError("foo") } }; 73try { 74 parseInt(obj); 75 assert(false); 76} catch (e) { 77 assert(e instanceof ReferenceError); 78 assert(e.message === "foo"); 79} 80