mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:47:35 +00:00
LibJS: Reorganize tests into subfolders
This commit is contained in:
parent
21064a1883
commit
4c48c9d69d
213 changed files with 10 additions and 2 deletions
9
Libraries/LibJS/Tests/builtins/BigInt/BigInt.asIntN.js
Normal file
9
Libraries/LibJS/Tests/builtins/BigInt/BigInt.asIntN.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN.length === 2);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
9
Libraries/LibJS/Tests/builtins/BigInt/BigInt.asUintN.js
Normal file
9
Libraries/LibJS/Tests/builtins/BigInt/BigInt.asUintN.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN.length === 2);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
62
Libraries/LibJS/Tests/builtins/BigInt/BigInt.js
Normal file
62
Libraries/LibJS/Tests/builtins/BigInt/BigInt.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(BigInt.length === 1);
|
||||
assert(BigInt.name === "BigInt");
|
||||
|
||||
assert(BigInt(0) === 0n);
|
||||
assert(BigInt(1) === 1n);
|
||||
assert(BigInt(+1) === 1n);
|
||||
assert(BigInt(-1) === -1n);
|
||||
assert(BigInt("") === 0n);
|
||||
assert(BigInt("0") === 0n);
|
||||
assert(BigInt("1") === 1n);
|
||||
assert(BigInt("+1") === 1n);
|
||||
assert(BigInt("-1") === -1n);
|
||||
assert(BigInt("-1") === -1n);
|
||||
assert(BigInt([]) === 0n);
|
||||
assert(BigInt("42") === 42n);
|
||||
assert(BigInt(" \n 00100 \n ") === 100n);
|
||||
assert(BigInt(123n) === 123n);
|
||||
assert(BigInt("3323214327642987348732109829832143298746432437532197321") === 3323214327642987348732109829832143298746432437532197321n);
|
||||
|
||||
assertThrowsError(() => {
|
||||
new BigInt();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "BigInt is not a constructor"
|
||||
});
|
||||
|
||||
[null, undefined, Symbol()].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
BigInt(value);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: typeof value === "symbol"
|
||||
? "Cannot convert symbol to BigInt"
|
||||
: `Cannot convert ${value} to BigInt`
|
||||
});
|
||||
});
|
||||
|
||||
["foo", "123n", "1+1", {}, function () { }].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
BigInt(value);
|
||||
}, {
|
||||
error: SyntaxError,
|
||||
message: `Invalid value for BigInt: ${value}`
|
||||
});
|
||||
});
|
||||
|
||||
[1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
BigInt(value);
|
||||
}, {
|
||||
error: RangeError,
|
||||
message: "BigInt argument must be an integer"
|
||||
});
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(BigInt.prototype.toLocaleString.length === 0);
|
||||
|
||||
assertThrowsError(() => {
|
||||
BigInt.prototype.toLocaleString.call("foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Not a BigInt object"
|
||||
});
|
||||
|
||||
assert(BigInt(123).toLocaleString() === "123");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(BigInt.prototype.toString.length === 0);
|
||||
|
||||
assertThrowsError(() => {
|
||||
BigInt.prototype.toString.call("foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Not a BigInt object"
|
||||
});
|
||||
|
||||
assert(BigInt(123).toString() === "123");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(BigInt.prototype.valueOf.length === 0);
|
||||
|
||||
assertThrowsError(() => {
|
||||
BigInt.prototype.valueOf.call("foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Not a BigInt object"
|
||||
});
|
||||
|
||||
assert(typeof BigInt(123).valueOf() === "bigint");
|
||||
// FIXME: Uncomment once we support Object() with argument
|
||||
// assert(typeof Object(123n).valueOf() === "bigint");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
68
Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js
Normal file
68
Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var bigint = 123n;
|
||||
|
||||
assert(typeof bigint === "bigint");
|
||||
assert(-bigint === -123n);
|
||||
assert("" + bigint === "123")
|
||||
|
||||
assertThrowsError(() => {
|
||||
+bigint;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot convert BigInt to number"
|
||||
});
|
||||
|
||||
assert(12n + 34n === 46n);
|
||||
assert(12n - 34n === -22n);
|
||||
assert(8n * 12n === 96n);
|
||||
assert(123n / 10n === 12n);
|
||||
assert(2n ** 3n === 8n);
|
||||
assert(5n % 3n === 2n);
|
||||
assert(45977665298704210987n + 714320987142450987412098743217984576n / 4598741987421098765327980n * 987498743n === 199365500239020623962n);
|
||||
|
||||
assert((12n & 5n) === 4n);
|
||||
assert((1n | 2n) === 3n);
|
||||
assert((5n ^ 3n) === 6n);
|
||||
assert(~1n === -2n);
|
||||
|
||||
bigint = 1n;
|
||||
assert(bigint++ === 1n);
|
||||
assert(bigint === 2n);
|
||||
assert(bigint-- === 2n);
|
||||
assert(bigint === 1n);
|
||||
assert(++bigint === 2n);
|
||||
assert(bigint === 2n);
|
||||
assert(--bigint === 1n);
|
||||
assert(bigint === 1n);
|
||||
|
||||
|
||||
assert((1n == 1n) === true);
|
||||
assert((1n == 1) === true);
|
||||
assert((1 == 1n) === true);
|
||||
assert((1n == 1.23) === false);
|
||||
assert((1.23 == 1n) === false);
|
||||
|
||||
assert((1n != 1n) === false);
|
||||
assert((1n != 1) === false);
|
||||
assert((1 != 1n) === false);
|
||||
assert((1n != 1.23) === true);
|
||||
assert((1.23 != 1n) === true);
|
||||
|
||||
assert((1n === 1n) === true);
|
||||
assert((1n === 1) == false);
|
||||
assert((1 === 1n) === false);
|
||||
assert((1n === 1.23) === false);
|
||||
assert((1.23 === 1n) === false);
|
||||
|
||||
assert((1n !== 1n) === false);
|
||||
assert((1n !== 1) === true);
|
||||
assert((1 !== 1n) === true);
|
||||
assert((1n !== 1.23) === true);
|
||||
assert((1.23 !== 1n) === true);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
[1, null, undefined].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
1n + value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use addition operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n - value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use subtraction operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n * value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use multiplication operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n / value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use division operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n % value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use modulo operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n ** value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use exponentiation operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n | value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use bitwise OR operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n & value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use bitwise AND operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n ^ value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use bitwise XOR operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n << value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use left-shift operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n >> value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use right-shift operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n >>> value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Cannot use unsigned right-shift operator with BigInt"
|
||||
});
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue