Skip to content

Commit

Permalink
Add Temporal tests
Browse files Browse the repository at this point in the history
This copies over the tests that previously existed in the
tc39/proposal-temporal repository.

For context, see thread starting at:
tc39#3002 (comment)

In service of tc39#3002
  • Loading branch information
ptomato committed Sep 29, 2021
1 parent 10ad4c1 commit 56fafab
Show file tree
Hide file tree
Showing 2,765 changed files with 67,828 additions and 3 deletions.
1,175 changes: 1,173 additions & 2 deletions harness/temporalHelpers.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions test/built-ins/Temporal/Calendar/builtin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar
description: Tests that Temporal.Calendar meets the requirements for built-in objects
info: |
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/

assert.sameValue(Object.isExtensible(Temporal.Calendar),
true, "Built-in objects must be extensible.");

assert.sameValue(Object.prototype.toString.call(Temporal.Calendar),
"[object Function]", "Object.prototype.toString");

assert.sameValue(Object.getPrototypeOf(Temporal.Calendar),
Function.prototype, "prototype");

assert.sameValue(typeof Temporal.Calendar.prototype,
"object", "prototype property");
12 changes: 12 additions & 0 deletions test/built-ins/Temporal/Calendar/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar
description: Temporal.Calendar constructor cannot be called as a function
info: |
1. If NewTarget is undefined, throw a TypeError exception.
features: [Temporal]
---*/

assert.throws(TypeError, () => Temporal.Calendar());
30 changes: 30 additions & 0 deletions test/built-ins/Temporal/Calendar/from/builtin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Tests that Temporal.Calendar.from meets the requirements for built-in objects
info: |
Built-in functions that are not constructors do not have a "prototype" property unless
otherwise specified in the description of a particular function.
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/

assert.sameValue(Object.isExtensible(Temporal.Calendar.from),
true, "Built-in objects must be extensible.");

assert.sameValue(Object.prototype.toString.call(Temporal.Calendar.from),
"[object Function]", "Object.prototype.toString");

assert.sameValue(Object.getPrototypeOf(Temporal.Calendar.from),
Function.prototype, "prototype");

assert.sameValue(Temporal.Calendar.from.hasOwnProperty("prototype"),
false, "prototype property");
11 changes: 11 additions & 0 deletions test/built-ins/Temporal/Calendar/from/calendar-object-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Converting objects to Temporal.Calendar
features: [Temporal]
---*/

assert.throws(RangeError, () => Temporal.Calendar.from({ calendar: "local" }));
assert.throws(RangeError, () => Temporal.Calendar.from({ calendar: { calendar: "iso8601" } }));
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Converting objects to Temporal.Calendar
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
"has outer.calendar",
"get outer.calendar",
"has inner.calendar",
"get inner.toString",
"call inner.toString",
];
const actual = [];
const calendar = new Proxy({}, {
has(t, p) {
actual.push(`has outer.${p}`);
return true;
},
get(t, p) {
actual.push(`get outer.${p}`);
return new Proxy(TemporalHelpers.toPrimitiveObserver(actual, "iso8601", "inner"), {
has(t, p) {
actual.push(`has inner.${p}`);
return true;
},
get(t, p) {
return t[p];
},
});
},
});
const result = Temporal.Calendar.from(calendar);
assert.sameValue(result.id, "iso8601");
assert.compareArray(actual, expected);
21 changes: 21 additions & 0 deletions test/built-ins/Temporal/Calendar/from/calendar-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Converting objects to Temporal.Calendar
features: [Temporal]
---*/

const cal = new Temporal.Calendar("iso8601");
const calFromObject = Temporal.Calendar.from({ calendar: cal });
assert(calFromObject instanceof Temporal.Calendar);
assert.sameValue(calFromObject.id, "iso8601");

const calFromString = Temporal.Calendar.from({ calendar: "iso8601" });
assert(calFromString instanceof Temporal.Calendar);
assert.sameValue(calFromString.id, "iso8601");

const custom = { id: "custom-calendar" };
assert.sameValue(Temporal.Calendar.from({ calendar: custom }), custom);
assert.sameValue(Temporal.Calendar.from(custom), custom);
19 changes: 19 additions & 0 deletions test/built-ins/Temporal/Calendar/from/calendar-string-builtin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Calendar.from should support iso8601.
features: [Temporal]
---*/

const tests = [
"iso8601",
"1994-11-05T08:15:30-05:00",
];

for (const item of tests) {
const calendar = Temporal.Calendar.from(item);
assert(calendar instanceof Temporal.Calendar);
assert.sameValue(calendar.id, "iso8601");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: from() throws if the argument is not a built-in calendar name.
features: [Temporal]
---*/

const tests = [
"local",
"iso-8601",
"[u-ca=iso8601]",
"invalid-calendar",
];

for (const item of tests) {
assert.throws(RangeError, () => Temporal.Calendar.from(item));
}
20 changes: 20 additions & 0 deletions test/built-ins/Temporal/Calendar/from/calendar-temporal-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal.calendar.from step 1:
1. Return ? ToTemporalCalendar(_item_).
sec-temporal-totemporalcalendar step 1.a:
a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
const newCalendar = Temporal.Calendar.from(temporalObject);
assert.sameValue(newCalendar, calendar, "calendar object retrieved from internal slot");
});
25 changes: 25 additions & 0 deletions test/built-ins/Temporal/Calendar/from/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Temporal.Calendar.from.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Calendar.from, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});
23 changes: 23 additions & 0 deletions test/built-ins/Temporal/Calendar/from/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Temporal.Calendar.from.name is "from"
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Calendar.from, "name", {
value: "from",
writable: false,
enumerable: false,
configurable: true,
});
20 changes: 20 additions & 0 deletions test/built-ins/Temporal/Calendar/from/not-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: Temporal.Calendar.from does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Temporal]
---*/

assert.throws(TypeError, () => {
new Temporal.Calendar.from();
}, "Calling as constructor");

assert.sameValue(isConstructor(Temporal.Calendar.from), false,
"isConstructor(Temporal.Calendar.from)");
21 changes: 21 additions & 0 deletions test/built-ins/Temporal/Calendar/from/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: The "from" property of Temporal.Calendar
includes: [propertyHelper.js]
features: [Temporal]
---*/

assert.sameValue(
typeof Temporal.Calendar.from,
"function",
"`typeof Calendar.from` is `function`"
);

verifyProperty(Temporal.Calendar, "from", {
writable: true,
enumerable: false,
configurable: true,
});
19 changes: 19 additions & 0 deletions test/built-ins/Temporal/Calendar/from/subclassing-ignored.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.from
description: The receiver is never called when calling from()
includes: [temporalHelpers.js]
features: [Temporal]
---*/

TemporalHelpers.checkSubclassingIgnoredStatic(
Temporal.Calendar,
"from",
["iso8601"],
(result) => {
assert.sameValue(result.id, "iso8601", "id property of result");
assert.sameValue(result.toString(), "iso8601", "toString() of result");
},
);
25 changes: 25 additions & 0 deletions test/built-ins/Temporal/Calendar/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar
description: Temporal.Calendar.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Calendar, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});
11 changes: 11 additions & 0 deletions test/built-ins/Temporal/Calendar/missing-arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar
description: RangeError thrown when constructor invoked with no argument
features: [Temporal]
---*/

assert.throws(RangeError, () => new Temporal.Calendar());
assert.throws(RangeError, () => new Temporal.Calendar(undefined));
23 changes: 23 additions & 0 deletions test/built-ins/Temporal/Calendar/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar
description: Temporal.Calendar.name is "Calendar"
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Calendar, "name", {
value: "Calendar",
writable: false,
enumerable: false,
configurable: true,
});
Loading

0 comments on commit 56fafab

Please sign in to comment.