mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 22:52:22 +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 ✅
48
Tests/LibJS/Runtime/iterators/string-iterator.js
Normal file
48
Tests/LibJS/Runtime/iterators/string-iterator.js
Normal file
@@ -0,0 +1,48 @@
|
||||
test("length", () => {
|
||||
expect(String.prototype[Symbol.iterator]).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const s = "abcd";
|
||||
const it = s[Symbol.iterator]();
|
||||
expect(it.next()).toEqual({ value: "a", done: false });
|
||||
expect(it.next()).toEqual({ value: "b", done: false });
|
||||
expect(it.next()).toEqual({ value: "c", done: false });
|
||||
expect(it.next()).toEqual({ value: "d", done: false });
|
||||
expect(it.next()).toEqual({ value: undefined, done: true });
|
||||
expect(it.next()).toEqual({ value: undefined, done: true });
|
||||
expect(it.next()).toEqual({ value: undefined, done: true });
|
||||
});
|
||||
|
||||
test("casts |this| to string", () => {
|
||||
let it = String.prototype[Symbol.iterator].call(45);
|
||||
expect(it.next()).toEqual({ value: "4", done: false });
|
||||
expect(it.next()).toEqual({ value: "5", done: false });
|
||||
expect(it.next()).toEqual({ value: undefined, done: true });
|
||||
|
||||
it = String.prototype[Symbol.iterator].call(false);
|
||||
expect(it.next()).toEqual({ value: "f", done: false });
|
||||
expect(it.next()).toEqual({ value: "a", done: false });
|
||||
expect(it.next()).toEqual({ value: "l", done: false });
|
||||
expect(it.next()).toEqual({ value: "s", done: false });
|
||||
expect(it.next()).toEqual({ value: "e", done: false });
|
||||
expect(it.next()).toEqual({ value: undefined, done: true });
|
||||
|
||||
expect(() => {
|
||||
String.prototype[Symbol.iterator].call(null);
|
||||
}).toThrowWithMessage(TypeError, "null cannot be converted to an object");
|
||||
expect(() => {
|
||||
String.prototype[Symbol.iterator].call(undefined);
|
||||
}).toThrowWithMessage(TypeError, "undefined cannot be converted to an object");
|
||||
});
|
||||
|
||||
test("utf8 compatible", () => {
|
||||
const it = "ab\u{1f41e}cde"[Symbol.iterator]();
|
||||
expect(it.next()).toEqual({ value: "a", done: false });
|
||||
expect(it.next()).toEqual({ value: "b", done: false });
|
||||
expect(it.next()).toEqual({ value: "🐞", done: false });
|
||||
expect(it.next()).toEqual({ value: "c", done: false });
|
||||
expect(it.next()).toEqual({ value: "d", done: false });
|
||||
expect(it.next()).toEqual({ value: "e", done: false });
|
||||
expect(it.next()).toEqual({ value: undefined, done: true });
|
||||
});
|
||||
Reference in New Issue
Block a user