mirror of https://github.com/tc39/test262.git
Temporal: Coverage for Temporal.PlainMonthDay
This commit is contained in:
parent
122912d54b
commit
6d69685a48
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday
|
||||
description: PlainMonthDay constructor with invalid iso dates
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[2020, 0, 24],
|
||||
[2020, 13, 24],
|
||||
[2020, -3, 24],
|
||||
[2020, 12, 32],
|
||||
[2020, 2, 30],
|
||||
[2019, 2, 29],
|
||||
[2019, 2, 0],
|
||||
[2019, 2, -20],
|
||||
];
|
||||
|
||||
for (const [year, month, day] of tests) {
|
||||
assert.throws(RangeError, () => new Temporal.PlainMonthDay(month, day, undefined, year),
|
||||
`year=${year}, month=${month}, day=${day}`);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday
|
||||
description: >
|
||||
OrdinaryCreateFromConstructor returns with an abrupt completion.
|
||||
info: |
|
||||
CreateTemporalMonthDay ( isoDate, calendar [ , newTarget ] )
|
||||
|
||||
...
|
||||
3. Let object be ? OrdinaryCreateFromConstructor(newTarget,
|
||||
"%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]],
|
||||
[[ISODate]], [[Calendar]] »).
|
||||
...
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
...
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
2. Let proto be ? Get(constructor, "prototype").
|
||||
...
|
||||
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.construct(Temporal.PlainMonthDay, [1, 1], newTarget)
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday.prototype.tojson
|
||||
description: Basic behavior for toJSON
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const tests = [
|
||||
[new Temporal.PlainMonthDay(1, 1), "01-01"],
|
||||
[new Temporal.PlainMonthDay(12, 31), "12-31"],
|
||||
];
|
||||
|
||||
const options = new Proxy({}, {
|
||||
get() { throw new Test262Error("should not get properties off argument") }
|
||||
});
|
||||
|
||||
for (const [monthDay, expected] of tests) {
|
||||
assert.sameValue(monthDay.toJSON(), expected, "toJSON without argument");
|
||||
assert.sameValue(monthDay.toJSON(options), expected, "toJSON with argument");
|
||||
}
|
15
test/built-ins/Temporal/PlainMonthDay/prototype/toLocaleString/return-string.js
vendored
Normal file
15
test/built-ins/Temporal/PlainMonthDay/prototype/toLocaleString/return-string.js
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday.prototype.tolocalestring
|
||||
description: toLocaleString returns a string.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const pmd = new Temporal.PlainMonthDay(1, 1);
|
||||
|
||||
assert.sameValue(
|
||||
typeof pmd.toLocaleString(undefined, {calendar: "iso8601"}),
|
||||
"string"
|
||||
);
|
58
test/built-ins/Temporal/PlainMonthDay/prototype/with/monthdaylike-invalid.js
vendored
Normal file
58
test/built-ins/Temporal/PlainMonthDay/prototype/with/monthdaylike-invalid.js
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday.prototype.with
|
||||
description: >
|
||||
Throws TypeError on an argument that is not a PlainMonthDay-like property bag
|
||||
info: |
|
||||
Temporal.PlainMonthDay.prototype.with ( temporalMonthDayLike [ , options ] )
|
||||
|
||||
...
|
||||
3. If ? IsPartialTemporalObject(temporalMonthDayLike) is false, throw a TypeError exception.
|
||||
...
|
||||
6. Let partialMonthDay be ? PrepareCalendarFields(calendar, temporalMonthDayLike, « year, month, month-code, day », « », partial).
|
||||
...
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(1, 1);
|
||||
|
||||
const tests = [
|
||||
// Step 3.
|
||||
// IsPartialTemporalObject, step 1.
|
||||
[undefined],
|
||||
[null],
|
||||
[true],
|
||||
["2019-05-17"],
|
||||
["2019-05-17T12:34"],
|
||||
["2019-05-17T12:34Z"],
|
||||
["18:05:42.577"],
|
||||
["42"],
|
||||
[Symbol(), "symbol"],
|
||||
[42, "number"],
|
||||
[42n, "bigint"],
|
||||
|
||||
// IsPartialTemporalObject, step 2.
|
||||
[Temporal.PlainDate.from("2019-05-17"), "PlainDate"],
|
||||
[Temporal.PlainDateTime.from("2019-05-17T12:34"), "PlainDateTime"],
|
||||
[Temporal.PlainMonthDay.from("2019-05-17"), "PlainMonthDay"],
|
||||
[Temporal.PlainTime.from("12:34"), "PlainTime"],
|
||||
[Temporal.PlainYearMonth.from("2019-05-17"), "PlainYearMonth"],
|
||||
[Temporal.ZonedDateTime.from("2019-05-17T12:34Z[UTC]"), "ZonedDateTime"],
|
||||
|
||||
// IsPartialTemporalObject, step 3.
|
||||
[{ year: 2021, calendar: "iso8601" }, "calendar"],
|
||||
|
||||
// IsPartialTemporalObject, step 4.
|
||||
[{ year: 2021, timeZone: "UTC" }, "timeZone"],
|
||||
|
||||
// Step 6.
|
||||
// PrepareCalendarFields, step 10.
|
||||
[{}, "empty object"],
|
||||
[{ months: 12 }, "only plural property"],
|
||||
];
|
||||
|
||||
for (const [value, message = String(value)] of tests) {
|
||||
assert.throws(TypeError, () => plainMonthDay.with(value), message);
|
||||
}
|
Loading…
Reference in New Issue