1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:47:45 +00:00

LibJS/Temporal: Fix inconsistency in order of observable operations

This is a normative change in the Temporal spec.

See: a3a8237
This commit is contained in:
Luke Wilde 2022-10-14 16:10:04 +01:00 committed by Linus Groh
parent 7394316818
commit d5d1146cc3
4 changed files with 135 additions and 12 deletions

View file

@ -8,4 +8,47 @@ describe("correct behavior", () => {
const date = calendar.dateFromFields({ year: 2000, month: 5, day: 2 });
expect(date.calendar).toBe(calendar);
});
test("gets overflow after temporal fields", () => {
const operations = [];
const calendar = new Temporal.Calendar("iso8601");
const fields = {
get day() {
operations.push("get day");
return 3;
},
get month() {
operations.push("get month");
return 10;
},
get monthCode() {
operations.push("get monthCode");
return "M10";
},
get year() {
operations.push("get year");
return 2022;
},
};
const options = {
get overflow() {
operations.push("get overflow");
return "constrain";
},
};
expect(operations).toHaveLength(0);
calendar.dateFromFields(fields, options);
expect(operations).toHaveLength(5);
expect(operations[0]).toBe("get day");
expect(operations[1]).toBe("get month");
expect(operations[2]).toBe("get monthCode");
expect(operations[3]).toBe("get year");
expect(operations[4]).toBe("get overflow");
});
});

View file

@ -24,6 +24,49 @@ describe("correct behavior", () => {
const fields = plainMonthDay.getISOFields();
expect(fields.isoYear).toBe(1972);
});
test("gets overflow after temporal fields", () => {
const operations = [];
const calendar = new Temporal.Calendar("iso8601");
const fields = {
get day() {
operations.push("get day");
return 3;
},
get month() {
operations.push("get month");
return 10;
},
get monthCode() {
operations.push("get monthCode");
return "M10";
},
get year() {
operations.push("get year");
return 2022;
},
};
const options = {
get overflow() {
operations.push("get overflow");
return "constrain";
},
};
expect(operations).toHaveLength(0);
calendar.monthDayFromFields(fields, options);
expect(operations).toHaveLength(5);
expect(operations[0]).toBe("get day");
expect(operations[1]).toBe("get month");
expect(operations[2]).toBe("get monthCode");
expect(operations[3]).toBe("get year");
expect(operations[4]).toBe("get overflow");
});
});
describe("errors", () => {

View file

@ -18,6 +18,43 @@ describe("correct behavior", () => {
expect(plainYearMonth.year).toBe(2021);
expect(plainYearMonth.month).toBe(7);
});
test("gets overflow after temporal fields", () => {
const operations = [];
const calendar = new Temporal.Calendar("iso8601");
const fields = {
get month() {
operations.push("get month");
return 10;
},
get monthCode() {
operations.push("get monthCode");
return "M10";
},
get year() {
operations.push("get year");
return 2022;
},
};
const options = {
get overflow() {
operations.push("get overflow");
return "constrain";
},
};
expect(operations).toHaveLength(0);
calendar.yearMonthFromFields(fields, options);
expect(operations).toHaveLength(4);
expect(operations[0]).toBe("get month");
expect(operations[1]).toBe("get monthCode");
expect(operations[2]).toBe("get year");
expect(operations[3]).toBe("get overflow");
});
});
describe("errors", () => {