ladybird/Libraries/LibJS/Tests/to-number-basic.js
Brian Gianforcaro bc40908d32 LibJS: Use the native assert() implementation now avaiable in 'js -t'
Switch the LibJS test suite to use the native assert implementation
surfaced inside the js repl when it's launched in test mode.
2020-04-05 15:28:45 +02:00

43 lines
1.1 KiB
JavaScript

try {
assert(+false === 0);
assert(-false === 0);
assert(+true === 1);
assert(-true === -1);
assert(+null === 0);
assert(-null === 0);
assert(+[] === 0);
assert(-[] === 0);
assert(+[[[[[]]]]] === 0);
assert(-[[[[[]]]]] === 0);
assert(+[[[[[42]]]]] === 42);
assert(-[[[[[42]]]]] === -42);
assert(+"" === 0);
assert(-"" === 0);
assert(+"42" === 42);
assert(-"42" === -42);
assert(+42 === 42);
assert(-42 === -42);
// FIXME: returns NaN
// assert(+"1.23" === 1.23)
// assert(-"1.23" === -1.23)
// FIXME: chokes on ASSERT
// assert(+1.23 === 1.23);
// assert(-1.23 === -1.23);
assert(isNaN(+undefined));
assert(isNaN(-undefined));
assert(isNaN(+{}));
assert(isNaN(-{}));
assert(isNaN(+{a: 1}));
assert(isNaN(-{a: 1}));
assert(isNaN(+[1, 2, 3]));
assert(isNaN(-[1, 2, 3]));
assert(isNaN(+[[[["foo"]]]]));
assert(isNaN(-[[[["foo"]]]]));
assert(isNaN(+"foo"));
assert(isNaN(-"foo"));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}