mirror of https://github.com/tc39/test262.git
Add tests for with() copying defined properties of source object
https://github.com/tc39/proposal-temporal/issues/1910 found a bug in an indentation level of a line in the Temporal proposal, which affected the outcome of the PreparePartialTemporalFields abstract operation. This adds tests for all entry points that use that abstract operation, to make sure the behaviour is correct: only defined properties are copied in with() methods. This was a normative change that achieved consensus at the December 2021 TC39 meeting.
This commit is contained in:
parent
6322630064
commit
525313395b
23
test/built-ins/Temporal/Duration/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
23
test/built-ins/Temporal/Duration/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
|
@ -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.duration.prototype.with
|
||||
description: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const d = new Temporal.Duration(9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
TemporalHelpers.assertDuration(
|
||||
d.with({ minutes: 11, hours: 6, months: undefined }),
|
||||
9, 8, 7, 6, 6, 11, 3, 2, 1, 0,
|
||||
"only the properties that are present and defined in the plain object are copied"
|
||||
);
|
22
test/built-ins/Temporal/PlainDate/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
22
test/built-ins/Temporal/PlainDate/prototype/with/copy-properties-not-undefined.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.plaindate.prototype.with
|
||||
description: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainDate = new Temporal.PlainDate(2006, 1, 24);
|
||||
|
||||
TemporalHelpers.assertPlainDate(plainDate.with({ day: 1, year: undefined }),
|
||||
2006, 1, "M01", 1,
|
||||
"only the properties that are present and defined in the plain object are copied"
|
||||
);
|
22
test/built-ins/Temporal/PlainDateTime/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
22
test/built-ins/Temporal/PlainDateTime/prototype/with/copy-properties-not-undefined.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: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainDateTime = new Temporal.PlainDateTime(2006, 1, 24, 11, 42, 58);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(plainDateTime.with({ day: 8, hour: 10, year: undefined }),
|
||||
2006, 1, "M01", 8, 10, 42, 58, 0, 0, 0,
|
||||
"only the properties that are present and defined in the plain object are copied"
|
||||
);
|
22
test/built-ins/Temporal/PlainMonthDay/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
22
test/built-ins/Temporal/PlainMonthDay/prototype/with/copy-properties-not-undefined.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.plainmonthday.prototype.with
|
||||
description: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(10, 31);
|
||||
|
||||
TemporalHelpers.assertPlainMonthDay(plainMonthDay.with({ day: 1, monthCode: undefined }),
|
||||
"M10", 1,
|
||||
"only the properties that are present and defined in the plain object are copied"
|
||||
);
|
22
test/built-ins/Temporal/PlainTime/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
22
test/built-ins/Temporal/PlainTime/prototype/with/copy-properties-not-undefined.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.plaintime.prototype.with
|
||||
description: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainTime = new Temporal.PlainTime(9, 45, 55);
|
||||
|
||||
TemporalHelpers.assertPlainTime(plainTime.with({ hour: 8, second: undefined }),
|
||||
8, 45, 55, 0, 0, 0,
|
||||
"only the properties that are present and defined in the plain object are copied"
|
||||
);
|
22
test/built-ins/Temporal/PlainYearMonth/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
22
test/built-ins/Temporal/PlainYearMonth/prototype/with/copy-properties-not-undefined.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.plainyearmonth.prototype.with
|
||||
description: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2001, 9);
|
||||
|
||||
TemporalHelpers.assertPlainYearMonth(plainYearMonth.with({ month: 11, year: undefined }),
|
||||
2001, 11, "M11",
|
||||
"only the properties that are present and defined in the plain object are copied"
|
||||
);
|
49
test/built-ins/Temporal/ZonedDateTime/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
49
test/built-ins/Temporal/ZonedDateTime/prototype/with/copy-properties-not-undefined.js
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
// 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.zoneddatetime.prototype.with
|
||||
description: PreparePartialTemporalFields copies only defined properties of source object
|
||||
info: |
|
||||
4. For each value _property_ of _fieldNames_, do
|
||||
a. Let _value_ be ? Get(_fields_, _property_).
|
||||
b. If _value_ is not *undefined*, then
|
||||
...
|
||||
iii. Perform ! CreateDataPropertyOrThrow(_result_, _property_, _value_).
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const d1 = new Temporal.ZonedDateTime(1_000_000_000_000_000_789n, "UTC");
|
||||
|
||||
const d2 = d1.with({ day: 1, hour: 10, year: undefined });
|
||||
|
||||
assert.sameValue(d2.year, 2001,
|
||||
"only the properties that are present and defined in the plain object are copied (year value)"
|
||||
);
|
||||
|
||||
assert.sameValue(d2.month, 9,
|
||||
"only the properties that are present and defined in the plain object are copied (month value)"
|
||||
);
|
||||
|
||||
assert.sameValue(d2.day, 1,
|
||||
"only the properties that are present and defined in the plain object are copied (day value)"
|
||||
);
|
||||
|
||||
assert.sameValue(d2.hour, 10,
|
||||
"only the properties that are present and defined in the plain object are copied (hour value)"
|
||||
);
|
||||
assert.sameValue(d2.minute, 46,
|
||||
"only the properties that are present and defined in the plain object are copied (minute value)"
|
||||
);
|
||||
assert.sameValue(d2.second, 40,
|
||||
"only the properties that are present and defined in the plain object are copied (second value)"
|
||||
);
|
||||
assert.sameValue(d2.millisecond, 0,
|
||||
"only the properties that are present and defined in the plain object are copied (millisecond value)"
|
||||
);
|
||||
assert.sameValue(d2.microsecond, 0,
|
||||
"only the properties that are present and defined in the plain object are copied (microsecond value)"
|
||||
);
|
||||
assert.sameValue(d2.nanosecond, 789,
|
||||
"only the properties that are present and defined in the plain object are copied (nanosecond value)"
|
||||
);
|
Loading…
Reference in New Issue