1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

LibJS: Reorganize tests into subfolders

This commit is contained in:
Matthew Olsson 2020-07-02 16:09:21 -07:00 committed by Andreas Kling
parent 21064a1883
commit 4c48c9d69d
213 changed files with 10 additions and 2 deletions

View file

@ -0,0 +1,29 @@
load("test-common.js");
try {
assert(isFinite.length === 1);
assert(isFinite(0) === true);
assert(isFinite(1.23) === true);
assert(isFinite(42) === true);
assert(isFinite("") === true);
assert(isFinite("0") === true);
assert(isFinite("42") === true);
assert(isFinite(true) === true);
assert(isFinite(false) === true);
assert(isFinite(null) === true);
assert(isFinite([]) === true);
assert(isFinite() === false);
assert(isFinite(NaN) === false);
assert(isFinite(undefined) === false);
assert(isFinite(Infinity) === false);
assert(isFinite(-Infinity) === false);
assert(isFinite("foo") === false);
assert(isFinite({}) === false);
assert(isFinite([1, 2, 3]) === false);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

@ -0,0 +1,28 @@
load("test-common.js");
try {
assert(isNaN.length === 1);
assert(isNaN(0) === false);
assert(isNaN(42) === false);
assert(isNaN("") === false);
assert(isNaN("0") === false);
assert(isNaN("42") === false);
assert(isNaN(true) === false);
assert(isNaN(false) === false);
assert(isNaN(null) === false);
assert(isNaN([]) === false);
assert(isNaN(Infinity) === false);
assert(isNaN(-Infinity) === false);
assert(isNaN() === true);
assert(isNaN(NaN) === true);
assert(isNaN(undefined) === true);
assert(isNaN("foo") === true);
assert(isNaN({}) === true);
assert(isNaN([1, 2, 3]) === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

@ -0,0 +1,71 @@
load("test-common.js");
try {
const NUMBER_TEST_CASES = [
[0, 0],
[1, 1],
[.23, 0.23],
[1.23, 1.23],
[0.0123E+2, 1.23],
[1.23e4, 12300],
[Infinity, Infinity]
];
NUMBER_TEST_CASES.forEach(test => {
const value = test[0];
const result = test[1];
assert(parseFloat(value) === result);
assert(parseFloat(+value) === result);
assert(parseFloat(-value) === -result);
});
const STRING_TEST_CASES = [
["0", 0],
["1", 1],
[".23", 0.23],
["1.23", 1.23],
["0.0123E+2", 1.23],
["1.23e4", 12300],
["Infinity", Infinity]
];
STRING_TEST_CASES.forEach(test => {
const value = test[0];
const result = test[1];
assert(parseFloat(value) === result);
assert(parseFloat(`+${value}`) === result);
assert(parseFloat(`-${value}`) === -result);
assert(parseFloat(`${value}foo`) === result);
assert(parseFloat(`+${value}foo`) === result);
assert(parseFloat(`-${value}foo`) === -result);
assert(parseFloat(` \n \t ${value} \v foo `) === result);
assert(parseFloat(` \r -${value} \f \n\n foo `) === -result);
assert(parseFloat({ toString: () => value }) === result);
});
const NAN_TEST_CASES = [
"",
[],
[],
true,
false,
null,
undefined,
NaN,
"foo123",
"foo+123",
"fooInfinity",
"foo+Infinity"
];
assert(isNaN(parseFloat()));
assert(isNaN(parseFloat("", 123, Infinity)));
NAN_TEST_CASES.forEach(value => {
assert(isNaN(parseFloat(value)));
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e)
}