Temporal: Improve various assertion messages

Some of these were overlooked in a recent big refactor.
This commit is contained in:
Philip Chimento 2023-06-07 01:51:52 -07:00 committed by Philip Chimento
parent 1a0b9d23f2
commit ce92940645
34 changed files with 42 additions and 39 deletions

View File

@ -22,6 +22,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}

View File

@ -21,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}

View File

@ -60,7 +60,8 @@ assert.throws(RangeError, () =>
// Adding day to day sets largestUnit to 'day', avoids having any week/month/year components in differences
dayDuration.add(dayDuration, {
relativeTo: zdt,
})
}),
"days < 0 and sign = 1"
);
// NanosecondsToDays.20: days > 0 and sign = -1
@ -87,7 +88,8 @@ assert.throws(RangeError, () =>
// Adding day to day sets largestUnit to 'day', avoids having any week/month/year components in differences
dayDuration.add(dayDuration, {
relativeTo: zdt,
})
}),
"days > 0 and sign = -1"
);
// NanosecondsToDays.22: nanoseconds > 0 and sign = -1
@ -115,5 +117,6 @@ assert.throws(RangeError, () =>
// Adding day to day sets largestUnit to 'day', avoids having any week/month/year components in differences
dayDuration.add(dayDuration, {
relativeTo: zdt,
})
}),
"nanoseconds > 0 and sign = -1"
);

View File

@ -22,6 +22,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}

View File

@ -21,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}

View File

@ -22,6 +22,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}

View File

@ -23,6 +23,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}

View File

@ -22,6 +22,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.total({ unit: "days", relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}

View File

@ -21,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.total({ unit: "days", relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.toPlainDateTime(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -18,11 +18,11 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
"A number is not a valid ISO string for PlainDateTime (first argument)"
`A number (${arg}) is not a valid ISO string for PlainDateTime (first argument)`
);
assert.throws(
TypeError,
() => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg),
"A number is not a valid ISO string for PlainDateTime (second argument)"
`A number (${arg}) is not a valid ISO string for PlainDateTime (second argument)`
);
}

View File

@ -18,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainDateTime.from(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.since(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.until(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.withPlainTime(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from(arg),
"A number is not a valid ISO string for PlainMonthDay"
`A number (${arg}) is not a valid ISO string for PlainMonthDay`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainMonthDay"
`A number (${arg}) is not a valid ISO string for PlainMonthDay`
);
}

View File

@ -18,11 +18,11 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)),
"A number is not a valid ISO string for PlainTime (first argument)"
`A number (${arg}) is not a valid ISO string for PlainTime (first argument)`
);
assert.throws(
TypeError,
() => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg),
"A number is not a valid ISO string for PlainTime (second argument)"
`A number (${arg}) is not a valid ISO string for PlainTime (second argument)`
);
}

View File

@ -18,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainTime.from(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.since(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.until(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}

View File

@ -20,11 +20,11 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
"A number is not a valid ISO string for PlainYearMonth (first argument)"
`A number (${arg}) is not a valid ISO string for PlainYearMonth (first argument)`
);
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
"A number is not a valid ISO string for PlainYearMonth (first argument)"
`A number (${arg}) is not a valid ISO string for PlainYearMonth (first argument)`
);
}

View File

@ -18,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.from(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.since(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.until(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.getInstantFor(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.getPossibleInstantsFor(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}

View File

@ -10,7 +10,7 @@ features: [Temporal]
let str = "1970-01-01T01:35:30+01:35:00.000000000[+01:35]";
const result = Temporal.ZonedDateTime.from(str);
assert.sameValue(result.timeZoneId, "+01:35", "Time zone determined from bracket name");
assert.sameValue(result.timeZoneId, "+01:35", "ISO offset, sub-minute offset trailing-zeroes");
str = "1970-01-01T01:35:30+01:35:00.000000000[+01:35:00.000000000]";
assert.throws(

View File

@ -12,7 +12,7 @@ const instance = new Temporal.ZonedDateTime(0n, timeZone);
let str = "1970-01-01T01:35:30+01:35:00.000000000[+01:35]";
const result = instance.equals(str);
assert.sameValue(result, false, "Time zone determined from bracket name");
assert.sameValue(result, false, "ISO offset, sub-minute offset trailing-zeroes");
str = "1970-01-01T01:35:30+01:35:00.000000000[+01:35:00.000000000]";
assert.throws(

View File

@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.withPlainTime(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}