mirror of https://github.com/tc39/test262.git
Test PlainYearMonth.prototype.with.
This commit is contained in:
parent
7215b9387f
commit
6ba72412ab
11
test/built-ins/Temporal/PlainYearMonth/prototype/with/argument-calendar-field.js
vendored
Normal file
11
test/built-ins/Temporal/PlainYearMonth/prototype/with/argument-calendar-field.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// 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.plainyearmonth.prototype.with
|
||||
description: Throw if the argument has a calendar field
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-10");
|
||||
assert.throws(TypeError, () => ym.with({ year: 2021, calendar: "iso8601" }));
|
12
test/built-ins/Temporal/PlainYearMonth/prototype/with/argument-missing-fields.js
vendored
Normal file
12
test/built-ins/Temporal/PlainYearMonth/prototype/with/argument-missing-fields.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
// 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.plainyearmonth.prototype.with
|
||||
description: TypeError thrown when argument doesn't contain any of the supported properties
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-10");
|
||||
assert.throws(TypeError, () => ym.with({}), "No properties");
|
||||
assert.throws(TypeError, () => ym.with({ months: 12 }), "Only plural 'months' property");
|
11
test/built-ins/Temporal/PlainYearMonth/prototype/with/argument-timezone-field.js
vendored
Normal file
11
test/built-ins/Temporal/PlainYearMonth/prototype/with/argument-timezone-field.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// 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.plainyearmonth.prototype.with
|
||||
description: Throw if the argument has a timeZone field
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-10");
|
||||
assert.throws(TypeError, () => ym.with({ year: 2021, timeZone: "UTC" }));
|
|
@ -0,0 +1,23 @@
|
|||
// 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.plainyearmonth.prototype.with
|
||||
description: Basic tests for with
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-10");
|
||||
|
||||
TemporalHelpers.assertPlainYearMonth(ym.with({ year: 2020 }), 2020, 10, "M10", "year");
|
||||
TemporalHelpers.assertPlainYearMonth(ym.with({ month: 9 }), 2019, 9, "M09", "month");
|
||||
TemporalHelpers.assertPlainYearMonth(ym.with({ monthCode: "M09" }), 2019, 9, "M09", "monthCode");
|
||||
|
||||
assert.throws(RangeError, () => ym.with({ month: 9, monthCode: "M10" }), "month/monthCode mismatch");
|
||||
TemporalHelpers.assertPlainYearMonth(ym.with({ month: 1, years: 2020 }), 2019, 1, "M01", "plural 'years'");
|
||||
|
||||
const withDay = ym.with({ year: 2019, get day() { throw new Test262Error("should not read the day property") } });
|
||||
TemporalHelpers.assertPlainYearMonth(withDay, 2019, 10, "M10", "day property");
|
||||
assert.sameValue(withDay.getISOFields().isoDay, 1);
|
||||
|
|
@ -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.plainyearmonth.prototype.with
|
||||
description: TypeError thrown when options argument is a primitive
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const values = [
|
||||
null,
|
||||
true,
|
||||
"2021-01",
|
||||
Symbol(),
|
||||
1,
|
||||
2n,
|
||||
];
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-10");
|
||||
values.forEach((value) => {
|
||||
assert.throws(TypeError, () => ym.with({ year: 2020 }, value), `TypeError on wrong argument type ${typeof value}`);
|
||||
});
|
|
@ -17,4 +17,6 @@ features: [Temporal]
|
|||
---*/
|
||||
|
||||
const yearmonth = new Temporal.PlainYearMonth(2000, 5);
|
||||
assert.throws(RangeError, () => yearmonth.with({ month: 8 }, { overflow: "other string" }));
|
||||
for (const overflow of ["", "CONSTRAIN", "balance", "other string", "constra\u0131n"]) {
|
||||
assert.throws(RangeError, () => yearmonth.with({ month: 8 }, { overflow }));
|
||||
}
|
||||
|
|
|
@ -22,3 +22,5 @@ const explicit = yearmonth.with({ month: 15 }, { overflow: undefined });
|
|||
TemporalHelpers.assertPlainYearMonth(explicit, 2000, 12, "M12", "default overflow is constrain");
|
||||
const implicit = yearmonth.with({ month: 15 }, {});
|
||||
TemporalHelpers.assertPlainYearMonth(implicit, 2000, 12, "M12", "default overflow is constrain");
|
||||
const lambda = yearmonth.with({ month: 15 }, () => {});
|
||||
TemporalHelpers.assertPlainYearMonth(lambda, 2000, 12, "M12", "default overflow is constrain");
|
||||
|
|
Loading…
Reference in New Issue