LibJS: Implement Temporal.PlainDate.prototype.add/subtract/equals

This commit is contained in:
Timothy Flynn 2024-11-22 10:54:15 -05:00 committed by Andreas Kling
commit c2ead84bd9
Notes: github-actions[bot] 2024-11-23 13:48:09 +00:00
7 changed files with 133 additions and 0 deletions

View file

@ -0,0 +1,19 @@
describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.PlainDate.prototype.add).toHaveLength(1);
});
test("basic functionality", () => {
const plainDate = new Temporal.PlainDate(1970, 1, 1);
const result = plainDate.add(new Temporal.Duration(51, 6, 0, 5));
expect(result.equals(new Temporal.PlainDate(2021, 7, 6))).toBeTrue();
});
});
describe("errors", () => {
test("this value must be a Temporal.PlainDate object", () => {
expect(() => {
Temporal.PlainDate.prototype.add.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
});
});

View file

@ -0,0 +1,12 @@
describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.PlainDate.prototype.equals).toHaveLength(1);
});
test("basic functionality", () => {
const firstPlainDate = new Temporal.PlainDate(1, 1, 1, "gregory");
const secondPlainDate = new Temporal.PlainDate(0, 1, 1, "gregory");
expect(firstPlainDate.equals(firstPlainDate)).toBeTrue();
expect(firstPlainDate.equals(secondPlainDate)).toBeFalse();
});
});

View file

@ -0,0 +1,19 @@
describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.PlainDate.prototype.subtract).toHaveLength(1);
});
test("basic functionality", () => {
const plainDate = new Temporal.PlainDate(2021, 7, 6);
const result = plainDate.subtract(new Temporal.Duration(51, 6, 0, 5));
expect(result.equals(new Temporal.PlainDate(1970, 1, 1))).toBeTrue();
});
});
describe("errors", () => {
test("this value must be a Temporal.PlainDate object", () => {
expect(() => {
Temporal.PlainDate.prototype.subtract.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate");
});
});