mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibJS: Add String Iterator tests
This commit is contained in:
parent
c831fb17bf
commit
4c3a415dc3
Notes:
sideshowbarker
2024-07-19 04:51:45 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/4c3a415dc32 Pull-request: https://github.com/SerenityOS/serenity/pull/2780
2 changed files with 49 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
test("length", () => {
|
||||
expect(Array.prototype[Symbol.iterator].length).toBe(0);
|
||||
expect(Array.prototype[Symbol.iterator]).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("@@toStringTag", () => {
|
||||
|
|
48
Libraries/LibJS/Tests/iterators/string-iterator.js
Normal file
48
Libraries/LibJS/Tests/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", () => {
|
||||
const 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 });
|
||||
|
||||
const 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, "ToObject on null or undefined");
|
||||
expect(() => {
|
||||
String.prototype[Symbol.iterator].call(undefined);
|
||||
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
|
||||
});
|
||||
|
||||
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 });
|
||||
});
|
Loading…
Add table
Reference in a new issue