mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
LibJS: Convert all remaining non-Array tests to the new system :)
This commit is contained in:
parent
918f4affd5
commit
15de2eda2b
72 changed files with 2394 additions and 1998 deletions
|
@ -1,33 +1,23 @@
|
|||
load("test-common.js");
|
||||
// test("basic functionality", () => {
|
||||
// const localSym = Symbol("foo");
|
||||
// const globalSym = Symbol.for("foo");
|
||||
|
||||
try {
|
||||
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)");
|
||||
|
||||
assert(localSym !== globalSym);
|
||||
assert(localSym !== Symbol("foo"));
|
||||
assert(globalSym !== Symbol("foo"));
|
||||
assert(globalSym === Symbol.for("foo"));
|
||||
assert(localSym.toString() === "Symbol(foo)");
|
||||
assert(globalSym.toString() === "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");
|
||||
// });
|
||||
|
||||
assert(Symbol.for(1).description === "1");
|
||||
assert(Symbol.for(true).description === "true");
|
||||
assert(Symbol.for({}).description === "[object Object]");
|
||||
assert(Symbol.for().description === "undefined");
|
||||
assert(Symbol.for(null).description === "null");
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol.for(Symbol());
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to string",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
// test("symbol argument throws an error", () => {
|
||||
// expect(() => {
|
||||
// Symbol.for(Symbol());
|
||||
// }).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||
// });
|
||||
|
|
|
@ -1,29 +1,19 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
test("basic functionality", () => {
|
||||
const s1 = Symbol("foo");
|
||||
const s2 = Symbol("foo");
|
||||
|
||||
assert(s1 !== s2);
|
||||
assert(s1.description === "foo");
|
||||
assert(s2.description === "foo");
|
||||
expect(s1).not.toBe(s2);
|
||||
expect(s1.description).toBe("foo");
|
||||
expect(s2.description).toBe("foo");
|
||||
|
||||
s1.description = "bar";
|
||||
assert(s1.description === "foo");
|
||||
expect(s1.description).toBe("foo");
|
||||
|
||||
assert(typeof s1 === "symbol");
|
||||
expect(typeof s1).toBe("symbol");
|
||||
});
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol(Symbol("foo"));
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to string",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("constructing symbol from symbol is an error", () => {
|
||||
expect(() => {
|
||||
Symbol(Symbol("foo"));
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||
});
|
||||
|
|
|
@ -1,34 +1,24 @@
|
|||
load("test-common.js");
|
||||
// test("basic functionality", () => {
|
||||
// const localSym = Symbol("bar");
|
||||
// const globalSym = Symbol.for("bar");
|
||||
|
||||
try {
|
||||
const localSym = Symbol("foo");
|
||||
const globalSym = Symbol.for("foo");
|
||||
// expect(Symbol.keyFor(localSym)).toBeUndefined();
|
||||
// expect(Symbol.keyFor(globalSym)).toBe("bar");
|
||||
// });
|
||||
|
||||
assert(Symbol.keyFor(localSym) === undefined);
|
||||
assert(Symbol.keyFor(globalSym) === "foo");
|
||||
|
||||
const testThrows = (value, str) => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol.keyFor(value);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: str + " is not a symbol",
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
testThrows(1, "1");
|
||||
testThrows(null, "null");
|
||||
testThrows(undefined, "undefined");
|
||||
testThrows([], "[object Array]");
|
||||
testThrows({}, "[object Object]");
|
||||
testThrows(true, "true");
|
||||
testThrows("foobar", "foobar");
|
||||
testThrows(function () {}, "[object ScriptFunction]"); // FIXME: Better function stringification
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
// 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`);
|
||||
// });
|
||||
// });
|
||||
|
|
|
@ -1,33 +1,23 @@
|
|||
load("test-common.js");
|
||||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const s1 = Symbol("baz");
|
||||
// const s2 = Symbol.for("qux");
|
||||
|
||||
try {
|
||||
const s1 = Symbol("foo");
|
||||
const s2 = Symbol.for("bar");
|
||||
expect(s1.toString()).toBe("Symbol(baz)");
|
||||
// expect(s2.toString()).toBe("Symbol(qux)");
|
||||
});
|
||||
});
|
||||
|
||||
assert(s1.toString() === "Symbol(foo)");
|
||||
assert(s2.toString() === "Symbol(bar)");
|
||||
describe("errors", () => {
|
||||
test("convert to string", () => {
|
||||
expect(() => {
|
||||
Symbol() + "";
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||
});
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
s1 + "";
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to string",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
s1 + 1;
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to number",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("convert to number", () => {
|
||||
expect(() => {
|
||||
Symbol() + 1;
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
const local = Symbol("foo");
|
||||
// const global = Symbol.for("foo");
|
||||
expect(local.valueOf()).toBe(local);
|
||||
// expect(global.valueOf()).toBe(global);
|
||||
|
||||
try {
|
||||
let local = Symbol("foo");
|
||||
let global = Symbol.for("foo");
|
||||
assert(local.valueOf() === local);
|
||||
assert(global.valueOf() === global);
|
||||
expect(Symbol.prototype.valueOf.call(local)).toBe(local);
|
||||
// expect(Symbol.prototype.valueOf.call(global)).toBe(global);
|
||||
});
|
||||
|
||||
assert(Symbol.prototype.valueOf.call(local) === local);
|
||||
assert(Symbol.prototype.valueOf.call(global) === global);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol.prototype.valueOf.call("foo");
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Not a Symbol object",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (err) {
|
||||
console.log("FAIL: " + err);
|
||||
}
|
||||
test("|this| must be a symbol", () => {
|
||||
expect(() => {
|
||||
Symbol.prototype.valueOf.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Symbol object");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue