mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:07:46 +00:00
Libraries: Move to Userland/Libraries/
This commit is contained in:
parent
dc28c07fa5
commit
13d7c09125
1857 changed files with 266 additions and 274 deletions
23
Userland/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js
Normal file
23
Userland/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
test("basic functionality", () => {
|
||||
const localSym = Symbol("foo");
|
||||
const globalSym = Symbol.for("foo");
|
||||
|
||||
expect(localSym).not.toBe(globalSym);
|
||||
expect(localSym).not.toBe(Symbol("foo"));
|
||||
expect(globalSym).not.toBe(Symbol("foo"));
|
||||
expect(globalSym).toBe(Symbol.for("foo"));
|
||||
expect(localSym.toString()).toBe("Symbol(foo)");
|
||||
expect(globalSym.toString()).toBe("Symbol(foo)");
|
||||
|
||||
expect(Symbol.for(1).description).toBe("1");
|
||||
expect(Symbol.for(true).description).toBe("true");
|
||||
expect(Symbol.for({}).description).toBe("[object Object]");
|
||||
expect(Symbol.for().description).toBe("undefined");
|
||||
expect(Symbol.for(null).description).toBe("null");
|
||||
});
|
||||
|
||||
test("symbol argument throws an error", () => {
|
||||
expect(() => {
|
||||
Symbol.for(Symbol());
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||
});
|
19
Userland/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js
Normal file
19
Userland/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
test("basic functionality", () => {
|
||||
const s1 = Symbol("foo");
|
||||
const s2 = Symbol("foo");
|
||||
|
||||
expect(s1).not.toBe(s2);
|
||||
expect(s1.description).toBe("foo");
|
||||
expect(s2.description).toBe("foo");
|
||||
|
||||
s1.description = "bar";
|
||||
expect(s1.description).toBe("foo");
|
||||
|
||||
expect(typeof s1).toBe("symbol");
|
||||
});
|
||||
|
||||
test("constructing symbol from symbol is an error", () => {
|
||||
expect(() => {
|
||||
Symbol(Symbol("foo"));
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
test("basic functionality", () => {
|
||||
const localSym = Symbol("foo");
|
||||
const globalSym = Symbol.for("foo");
|
||||
|
||||
expect(Symbol.keyFor(localSym)).toBeUndefined();
|
||||
expect(Symbol.keyFor(globalSym)).toBe("foo");
|
||||
});
|
||||
|
||||
test("bad argument values", () => {
|
||||
[
|
||||
[1, "1"],
|
||||
[null, "null"],
|
||||
[undefined, "undefined"],
|
||||
[[], "[object Array]"],
|
||||
[{}, "[object Object]"],
|
||||
[true, "true"],
|
||||
["foobar", "foobar"],
|
||||
[function () {}, "[object ScriptFunction]"], // FIXME: Better function stringification
|
||||
].forEach(testCase => {
|
||||
expect(() => {
|
||||
Symbol.keyFor(testCase[0]);
|
||||
}).toThrowWithMessage(TypeError, `${testCase[1]} is not a symbol`);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Symbol.prototype[Symbol.toStringTag]).toBe("Symbol");
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const s1 = Symbol("baz");
|
||||
const s2 = Symbol.for("qux");
|
||||
|
||||
// Explicit conversions to string are fine, but implicit toString via concatenation throws.
|
||||
expect(s1.toString()).toBe("Symbol(baz)");
|
||||
expect(String(s1)).toBe("Symbol(baz)");
|
||||
expect(s2.toString()).toBe("Symbol(qux)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("convert to string", () => {
|
||||
expect(() => {
|
||||
Symbol() + "";
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||
});
|
||||
|
||||
test("convert to number", () => {
|
||||
expect(() => {
|
||||
Symbol() + 1;
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
test("basic functionality", () => {
|
||||
const local = Symbol("foo");
|
||||
// const global = Symbol.for("foo");
|
||||
expect(local.valueOf()).toBe(local);
|
||||
// expect(global.valueOf()).toBe(global);
|
||||
|
||||
expect(Symbol.prototype.valueOf.call(local)).toBe(local);
|
||||
// expect(Symbol.prototype.valueOf.call(global)).toBe(global);
|
||||
});
|
||||
|
||||
test("|this| must be a symbol", () => {
|
||||
expect(() => {
|
||||
Symbol.prototype.valueOf.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Symbol object");
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Symbol).toHaveProperty("iterator");
|
||||
expect(Symbol).toHaveProperty("asyncIterator");
|
||||
expect(Symbol).toHaveProperty("match");
|
||||
expect(Symbol).toHaveProperty("matchAll");
|
||||
expect(Symbol).toHaveProperty("replace");
|
||||
expect(Symbol).toHaveProperty("search");
|
||||
expect(Symbol).toHaveProperty("split");
|
||||
expect(Symbol).toHaveProperty("hasInstance");
|
||||
expect(Symbol).toHaveProperty("isConcatSpreadable");
|
||||
expect(Symbol).toHaveProperty("unscopables");
|
||||
expect(Symbol).toHaveProperty("species");
|
||||
expect(Symbol).toHaveProperty("toPrimitive");
|
||||
expect(Symbol).toHaveProperty("toStringTag");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue