mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02:00
LibJS: Move tests to /Tests/LibJS
This commit is contained in:
committed by
Tim Flynn
parent
c059c6a2f5
commit
e3faa9b5ad
Notes:
github-actions[bot]
2026-02-06 11:17:48 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/e3faa9b5add Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7572 Reviewed-by: https://github.com/trflynn89 ✅
45
Tests/LibJS/Runtime/builtins/Array/array-spread.js
Normal file
45
Tests/LibJS/Runtime/builtins/Array/array-spread.js
Normal file
@@ -0,0 +1,45 @@
|
||||
describe("errors", () => {
|
||||
test("cannot spread number in array", () => {
|
||||
expect(() => {
|
||||
[...1];
|
||||
}).toThrowWithMessage(TypeError, "1 is not iterable");
|
||||
});
|
||||
|
||||
test("cannot spread object in array", () => {
|
||||
expect(() => {
|
||||
[...{}];
|
||||
}).toThrowWithMessage(TypeError, "[object Object] is not iterable");
|
||||
});
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect([1, ...[2, 3], 4]).toEqual([1, 2, 3, 4]);
|
||||
|
||||
let a = [2, 3];
|
||||
expect([1, ...a, 4]).toEqual([1, 2, 3, 4]);
|
||||
|
||||
let obj = { a: [2, 3] };
|
||||
expect([1, ...obj.a, 4]).toEqual([1, 2, 3, 4]);
|
||||
|
||||
expect([...[], ...[...[1, 2, 3]], 4]).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test("allows assignment expressions", () => {
|
||||
expect("([ ...a = { hello: 'world' } ])").toEval();
|
||||
expect("([ ...a += 'hello' ])").toEval();
|
||||
expect("([ ...a -= 'hello' ])").toEval();
|
||||
expect("([ ...a **= 'hello' ])").toEval();
|
||||
expect("([ ...a *= 'hello' ])").toEval();
|
||||
expect("([ ...a /= 'hello' ])").toEval();
|
||||
expect("([ ...a %= 'hello' ])").toEval();
|
||||
expect("([ ...a <<= 'hello' ])").toEval();
|
||||
expect("([ ...a >>= 'hello' ])").toEval();
|
||||
expect("([ ...a >>>= 'hello' ])").toEval();
|
||||
expect("([ ...a &= 'hello' ])").toEval();
|
||||
expect("([ ...a ^= 'hello' ])").toEval();
|
||||
expect("([ ...a |= 'hello' ])").toEval();
|
||||
expect("([ ...a &&= 'hello' ])").toEval();
|
||||
expect("([ ...a ||= 'hello' ])").toEval();
|
||||
expect("([ ...a ??= 'hello' ])").toEval();
|
||||
expect("function* test() { return ([ ...yield a ]); }").toEval();
|
||||
});
|
||||
Reference in New Issue
Block a user