1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:47:35 +00:00

LibJS: Implement RegExp.prototype [ @@match ] with UTF-16 code units

This commit is contained in:
Timothy Flynn 2021-07-22 10:19:27 -04:00 committed by Linus Groh
parent b1ea9c20b0
commit 2c023157e9
6 changed files with 103 additions and 16 deletions

View file

@ -45,3 +45,13 @@ test("override exec with non-function", () => {
re.exec = 3;
expect("test".match(re)).not.toBeNull();
});
test("UTF-16", () => {
expect("😀".match("foo")).toBeNull();
expect("😀".match("\ud83d")).toEqual(["\ud83d"]);
expect("😀".match("\ude00")).toEqual(["\ude00"]);
expect("😀😀".match("\ud83d")).toEqual(["\ud83d"]);
expect("😀😀".match("\ude00")).toEqual(["\ude00"]);
expect("😀😀".match(/\ud83d/g)).toEqual(["\ud83d", "\ud83d"]);
expect("😀😀".match(/\ude00/g)).toEqual(["\ude00", "\ude00"]);
});

View file

@ -76,3 +76,63 @@ test("basic functionality", () => {
expect(next.value).toBeUndefined();
}
});
test("UTF-16", () => {
{
var iterator = "😀".matchAll("foo");
var next = iterator.next();
expect(next.done).toBeTrue();
expect(next.value).toBeUndefined();
next = iterator.next();
expect(next.done).toBeTrue();
expect(next.value).toBeUndefined();
}
{
var iterator = "😀".matchAll("\ud83d");
var next = iterator.next();
expect(next.done).toBeFalse();
expect(next.value).toEqual(["\ud83d"]);
expect(next.value.index).toBe(0);
next = iterator.next();
expect(next.done).toBeTrue();
expect(next.value).toBeUndefined();
}
{
var iterator = "😀😀".matchAll("\ud83d");
var next = iterator.next();
expect(next.done).toBeFalse();
expect(next.value).toEqual(["\ud83d"]);
expect(next.value.index).toBe(0);
next = iterator.next();
expect(next.done).toBeFalse();
expect(next.value).toEqual(["\ud83d"]);
expect(next.value.index).toBe(2);
next = iterator.next();
expect(next.done).toBeTrue();
expect(next.value).toBeUndefined();
}
{
var iterator = "😀😀".matchAll("\ude00");
var next = iterator.next();
expect(next.done).toBeFalse();
expect(next.value).toEqual(["\ude00"]);
expect(next.value.index).toBe(1);
next = iterator.next();
expect(next.done).toBeFalse();
expect(next.value).toEqual(["\ude00"]);
expect(next.value.index).toBe(3);
next = iterator.next();
expect(next.done).toBeTrue();
expect(next.value).toBeUndefined();
}
});