Skip to content

Commit

Permalink
Temporal: Add tests for multiple time zone annotations
Browse files Browse the repository at this point in the history
See tc39/proposal-temporal#2397
Adds tests for ISO strings with more than one time zone annotation. These
are not syntactically correct according to the grammar and should be
rejected.
  • Loading branch information
ptomato committed Oct 7, 2022
1 parent 3aba1d1 commit 149c5e6
Show file tree
Hide file tree
Showing 63 changed files with 1,599 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.dateadd
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.calendar.prototype.dateuntil
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
`reject more than one time zone annotation: ${arg} (first argument)`
);
assert.throws(
RangeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
`reject more than one time zone annotation: ${arg} (second argument)`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.day
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.day(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.dayofweek
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dayOfWeek(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.dayofyear
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dayOfYear(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.daysinmonth
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.daysInMonth(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.daysinweek
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.daysInWeek(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.daysinyear
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.daysInYear(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.inleapyear
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.inLeapYear(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.month
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.month(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.monthcode
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.monthCode(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.monthsinyear
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.monthsInYear(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.weekofyear
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.weekOfYear(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.year
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/

const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.year(arg),
`reject more than one time zone annotation: ${arg}`
);
});
Loading

0 comments on commit 149c5e6

Please sign in to comment.