mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 16:34:27 +02:00
Temporal: Some more tests for PlainDateTime#with. (#3481)
This commit is contained in:
parent
d9616ed91f
commit
c35ae2099d
22
test/built-ins/Temporal/PlainDateTime/prototype/with/argument-not-object.js
vendored
Normal file
22
test/built-ins/Temporal/PlainDateTime/prototype/with/argument-not-object.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindatetime.prototype.with
|
||||||
|
description: Non-object arguments throw.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||||
|
const args = [
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"2020-01-12T10:20:30",
|
||||||
|
Symbol(),
|
||||||
|
2020,
|
||||||
|
2020n,
|
||||||
|
];
|
||||||
|
for (const argument of args) {
|
||||||
|
assert.throws(TypeError, () => instance.with(argument), `Does not support ${typeof argument}`);
|
||||||
|
}
|
27
test/built-ins/Temporal/PlainDateTime/prototype/with/calendar-options.js
vendored
Normal file
27
test/built-ins/Temporal/PlainDateTime/prototype/with/calendar-options.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindatetime.prototype.with
|
||||||
|
description: The options argument is passed through to Calendar#dateFromFields as-is.
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const options = {};
|
||||||
|
let calledDateFromFields = 0;
|
||||||
|
class Calendar extends Temporal.Calendar {
|
||||||
|
constructor() {
|
||||||
|
super("iso8601");
|
||||||
|
}
|
||||||
|
dateFromFields(fields, optionsArg) {
|
||||||
|
++calledDateFromFields;
|
||||||
|
assert.sameValue(optionsArg, options, "should pass options object through");
|
||||||
|
return super.dateFromFields(fields, optionsArg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const calendar = new Calendar();
|
||||||
|
const plaindatetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
||||||
|
const result = plaindatetime.with({ year: 2005 }, options);
|
||||||
|
TemporalHelpers.assertPlainDateTime(result, 2005, 5, "M05", 2, 12, 34, 56, 987, 654, 321);
|
||||||
|
assert.sameValue(calledDateFromFields, 1, "should have called overridden dateFromFields once");
|
33
test/built-ins/Temporal/PlainDateTime/prototype/with/calendar-temporal-object-throws.js
vendored
Normal file
33
test/built-ins/Temporal/PlainDateTime/prototype/with/calendar-temporal-object-throws.js
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Throws if a Temporal object with a calendar is supplied
|
||||||
|
esid: sec-temporal.plaindatetime.prototype.with
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const datetime = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789);
|
||||||
|
|
||||||
|
const values = [
|
||||||
|
Temporal.PlainDate.from("2022-04-12"),
|
||||||
|
Temporal.PlainDateTime.from("2022-04-12T15:19:45"),
|
||||||
|
Temporal.PlainMonthDay.from("04-12"),
|
||||||
|
Temporal.PlainTime.from("15:19:45"),
|
||||||
|
Temporal.PlainYearMonth.from("2022-04"),
|
||||||
|
Temporal.ZonedDateTime.from("2022-04-12T15:19:45[UTC]"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const value of values) {
|
||||||
|
Object.defineProperty(value, "calendar", {
|
||||||
|
get() { throw new Test262Error("should not get calendar property") }
|
||||||
|
});
|
||||||
|
Object.defineProperty(value, "timeZone", {
|
||||||
|
get() { throw new Test262Error("should not get timeZone property") }
|
||||||
|
});
|
||||||
|
assert.throws(
|
||||||
|
TypeError,
|
||||||
|
() => datetime.with(value),
|
||||||
|
"throws with temporal object"
|
||||||
|
);
|
||||||
|
}
|
@ -42,6 +42,12 @@ const expected = [
|
|||||||
"get year",
|
"get year",
|
||||||
"get year.valueOf",
|
"get year.valueOf",
|
||||||
"call year.valueOf",
|
"call year.valueOf",
|
||||||
|
"get options.overflow",
|
||||||
|
"get options.overflow.toString",
|
||||||
|
"call options.overflow.toString",
|
||||||
|
"get options.overflow",
|
||||||
|
"get options.overflow.toString",
|
||||||
|
"call options.overflow.toString",
|
||||||
];
|
];
|
||||||
const actual = [];
|
const actual = [];
|
||||||
const fields = {
|
const fields = {
|
||||||
@ -70,7 +76,13 @@ const argument = new Proxy(fields, {
|
|||||||
return key in target;
|
return key in target;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const result = instance.with(argument);
|
const options = {
|
||||||
|
get overflow() {
|
||||||
|
actual.push("get options.overflow");
|
||||||
|
return TemporalHelpers.toPrimitiveObserver(actual, "constrain", "options.overflow");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const result = instance.with(argument, options);
|
||||||
TemporalHelpers.assertPlainDateTime(result, 1, 1, "M01", 1, 1, 1, 1, 1, 1, 1);
|
TemporalHelpers.assertPlainDateTime(result, 1, 1, "M01", 1, 1, 1, 1, 1, 1, 1);
|
||||||
assert.sameValue(result.calendar.id, "iso8601", "calendar result");
|
assert.sameValue(result.calendar.id, "iso8601", "calendar result");
|
||||||
assert.compareArray(actual, expected, "order of operations");
|
assert.compareArray(actual, expected, "order of operations");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user