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

LibJS: Implement Temporal.Duration.prototype.negated()

This commit is contained in:
Linus Groh 2021-07-16 19:41:37 +01:00
parent 9aa1e4b885
commit 7df47bf3fb
4 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,42 @@
const DURATION_PROPERTIES = [
"years",
"months",
"weeks",
"days",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
];
describe("correct behavior", () => {
test("length is 0", () => {
expect(Temporal.Duration.prototype.negated).toHaveLength(0);
});
test("basic functionality", () => {
const negativeDuration = new Temporal.Duration(123).negated();
expect(negativeDuration.years).toBe(-123);
const positiveDuration = new Temporal.Duration(-123).negated();
expect(positiveDuration.years).toBe(123);
});
test("each property is negated", () => {
const values = Array(DURATION_PROPERTIES.length).fill(1);
const duration = new Temporal.Duration(...values).negated();
for (const property of DURATION_PROPERTIES) {
expect(duration[property]).toBe(-1);
}
});
});
test("errors", () => {
test("this value must be a Temporal.Duration object", () => {
expect(() => {
Temporal.Duration.prototype.negated.call("foo");
}).toThrowWithMessage(TypeError, "Not a Temporal.Duration");
});
});