mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-09 11:06:10 +00:00
LibJS: Implement RegExp.prototype.match with RegExpExec abstraction
This commit is contained in:
parent
ec898a3370
commit
b6b5adb47d
Notes:
sideshowbarker
2024-07-18 10:07:38 +09:00
Author: https://github.com/trflynn89
Commit: b6b5adb47d
Pull-request: https://github.com/SerenityOS/serenity/pull/8540
Reviewed-by: https://github.com/linusg ✅
2 changed files with 46 additions and 9 deletions
|
@ -4,3 +4,38 @@ test("basic functionality", () => {
|
|||
expect("hello friends".match(/hello/)).not.toBeNull();
|
||||
expect("hello friends".match(/enemies/)).toBeNull();
|
||||
});
|
||||
|
||||
test("override exec with function", () => {
|
||||
let calls = 0;
|
||||
|
||||
let re = /test/;
|
||||
let oldExec = re.exec.bind(re);
|
||||
re.exec = function (...args) {
|
||||
++calls;
|
||||
return oldExec(...args);
|
||||
};
|
||||
|
||||
expect("test".match(re)).not.toBeNull();
|
||||
expect(calls).toBe(1);
|
||||
});
|
||||
|
||||
test("override exec with bad function", () => {
|
||||
let calls = 0;
|
||||
|
||||
let re = /test/;
|
||||
re.exec = function (...args) {
|
||||
++calls;
|
||||
return 4;
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
"test".match(re);
|
||||
}).toThrow(TypeError);
|
||||
expect(calls).toBe(1);
|
||||
});
|
||||
|
||||
test("override exec with non-function", () => {
|
||||
let re = /test/;
|
||||
re.exec = 3;
|
||||
expect("test".match(re)).not.toBeNull();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue