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

Libraries: Move to Userland/Libraries/

This commit is contained in:
Andreas Kling 2021-01-12 12:17:30 +01:00
parent dc28c07fa5
commit 13d7c09125
1857 changed files with 266 additions and 274 deletions

View file

@ -0,0 +1,8 @@
test("basic functionality", () => {
expect(RegExp().toString()).toBe("/(?:)/");
expect(RegExp(undefined).toString()).toBe("/(?:)/");
expect(RegExp("foo").toString()).toBe("/foo/");
expect(RegExp("foo", undefined).toString()).toBe("/foo/");
expect(RegExp("foo", "g").toString()).toBe("/foo/g");
expect(RegExp(undefined, "g").toString()).toBe("/(?:)/g");
});

View file

@ -0,0 +1,58 @@
test("basic functionality", () => {
let re = /foo/;
expect(re.exec.length).toBe(1);
let res = re.exec("foo");
expect(res.length).toBe(1);
expect(res[0]).toBe("foo");
expect(res.groups).toBe(undefined);
expect(res.index).toBe(0);
});
test("basic unnamed captures", () => {
let re = /f(o.*)/;
let res = re.exec("fooooo");
expect(res.length).toBe(2);
expect(res[0]).toBe("fooooo");
expect(res[1]).toBe("ooooo");
expect(res.groups).toBe(undefined);
expect(res.index).toBe(0);
});
test("basic named captures", () => {
let re = /f(?<os>o.*)/;
let res = re.exec("fooooo");
expect(res.length).toBe(1);
expect(res.index).toBe(0);
expect(res[0]).toBe("fooooo");
expect(res.groups).not.toBe(undefined);
expect(res.groups.os).toBe("ooooo");
});
test("basic index", () => {
let re = /foo/;
let res = re.exec("abcfoo");
expect(res.length).toBe(1);
expect(res.index).toBe(3);
expect(res[0]).toBe("foo");
});
test("basic index with global and initial offset", () => {
let re = /foo/g;
re.lastIndex = 2;
let res = re.exec("abcfoo");
expect(res.length).toBe(1);
expect(res.index).toBe(3);
expect(res[0]).toBe("foo");
});
test("not matching", () => {
let re = /foo/;
let res = re.exec("bar");
expect(res).toBe(null);
});

View file

@ -0,0 +1,11 @@
test("basic functionality", () => {
expect(/foo/.flags).toBe("");
expect(/foo/g.flags).toBe("g");
expect(/foo/i.flags).toBe("i");
expect(/foo/m.flags).toBe("m");
expect(/foo/s.flags).toBe("s");
expect(/foo/u.flags).toBe("u");
expect(/foo/y.flags).toBe("y");
// prettier-ignore
expect(/foo/sgimyu.flags).toBe("gimsuy");
});

View file

@ -0,0 +1,8 @@
test("basic functionality", () => {
expect(RegExp.prototype.source).toBe("(?:)");
expect(RegExp().source).toBe("(?:)");
expect(/test/.source).toBe("test");
expect(/\n/.source).toBe("\\n");
// FIXME: RegExp parse doesn't parse \/ :(
// expect(/foo\/bar/.source).toBe("foo\\/bar");
});

View file

@ -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'");
});

View file

@ -0,0 +1,6 @@
test("basic functionality", () => {
expect(RegExp.prototype.toString).toHaveLength(0);
expect(/test/g.toString()).toBe("/test/g");
expect(RegExp.prototype.toString.call({ source: "test", flags: "g" })).toBe("/test/g");
});