mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:27:35 +00:00
LibJS: Hook up Regex<ECMA262> to RegExpObject and implement `test()'
This makes RegExpObject compile and store a Regex<ECMA262>, adds all flag-related properties, and implements `RegExpPrototype.test()` (complete with 'lastIndex' support) :^) It should be noted that this only implements `test()' using the builtin `exec()'.
This commit is contained in:
parent
75081b2bdd
commit
8ba273a2f3
13 changed files with 396 additions and 12 deletions
|
@ -0,0 +1,58 @@
|
|||
test("basic functionality", () => {
|
||||
expect(RegExp.prototype.test).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("simple test", () => {
|
||||
let re = /test/;
|
||||
expect(re.test("test")).toBe(true);
|
||||
expect(re.test("test")).toBe(true);
|
||||
});
|
||||
|
||||
test("simple global test", () => {
|
||||
let re = /test/g;
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
expect(re.test("testtest")).toBe(false);
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
});
|
||||
|
||||
test("global test with offset lastIndex", () => {
|
||||
let re = /test/g;
|
||||
re.lastIndex = 2;
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
expect(re.test("testtest")).toBe(false);
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
expect(re.test("testtest")).toBe(true);
|
||||
expect(re.test("testtest")).toBe(false);
|
||||
});
|
||||
|
||||
test("sticky test with offset lastIndex", () => {
|
||||
let re = /test/y;
|
||||
re.lastIndex = 2;
|
||||
expect(re.test("aatest")).toBe(true);
|
||||
expect(re.test("aatest")).toBe(false);
|
||||
expect(re.test("aatest")).toBe(false);
|
||||
});
|
||||
|
||||
test("flag and options", () => {
|
||||
expect(/foo/gi.flags).toBe("gi");
|
||||
expect(/foo/mu.flags).toBe("mu");
|
||||
expect(/foo/gimsuy.flags).toBe("gimsuy");
|
||||
|
||||
let re = /foo/gim;
|
||||
expect(re.dotAll).toBe(false);
|
||||
expect(re.global).toBe(true);
|
||||
expect(re.ignoreCase).toBe(true);
|
||||
expect(re.multiline).toBe(true);
|
||||
expect(re.sticky).toBe(false);
|
||||
expect(re.unicode).toBe(false);
|
||||
|
||||
expect(() => {
|
||||
/foo/gg;
|
||||
}).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'");
|
||||
|
||||
expect(() => {
|
||||
/foo/x;
|
||||
}).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue