Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions polyfill/test/thorough/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ cd $(dirname $0)
interpreter=${1-node}
there_were_errors=0
for test in \
dateaddition \
datedifference \
datetimeaddition \
datetimedifference \
durationaddition \
gregorian \
instantaddition \
instantdifference \
timeaddition \
timedifference \
yearmonthaddition \
yearmonthdifference \
zonedaddition \
zoneddifference
do
echo "== Running $test.mjs =="
Expand Down
37 changes: 37 additions & 0 deletions polyfill/test/thorough/dateaddition.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
assertTemporalEqual,
getProgressBar,
makeDateCases,
makeDurationCases,
time,
withSnapshotsFromFile
} from './support.mjs';

const interestingDates = makeDateCases();
const interestingDurations = makeDurationCases();
const total = interestingDates.length * interestingDurations.length;

await time(async (start) => {
const progress = getProgressBar(start, total);

await withSnapshotsFromFile('./dateaddition.snapshot.json', (matchSnapshot, matchSnapshotOrOutOfRange) => {
for (const [date, dateStr] of interestingDates) {
for (const [duration, durationStr] of interestingDurations) {
const testName = `${dateStr}+${durationStr}`;
progress.tick(1, { test: testName.slice(0, 45) });

const later = matchSnapshotOrOutOfRange(() => date.add(duration), testName);
if (later) {
assertTemporalEqual(date.subtract(duration.negated()), later, `${dateStr} - -${durationStr} = ${later}`);
}

const earlier = matchSnapshotOrOutOfRange(() => date.subtract(duration), `${dateStr}-${durationStr}`);
if (earlier) {
assertTemporalEqual(date.add(duration.negated()), earlier, `${dateStr} + -${durationStr} = ${earlier}`);
}
}
}
});

return total;
});
243,170 changes: 243,170 additions & 0 deletions polyfill/test/thorough/dateaddition.snapshot.json

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions polyfill/test/thorough/datedifference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import {
assertDurationsEqual,
assertTemporalEqual,
createDateSkippingInvalidCombinations,
getProgressBar,
interestingMonthDays,
interestingYears,
makeDateCases,
temporalImpl as T,
time,
withSnapshotsFromFile
Expand All @@ -26,17 +24,7 @@ const largestUnits = [
['days', reject]
];

const interestingCases = [];
for (const year of interestingYears) {
for (const [month, day] of interestingMonthDays) {
const date = createDateSkippingInvalidCombinations(year, month, day);
if (!date) continue;

// Pre-compute toString so it's not done repeatedly in each test
interestingCases.push([date, date.toString()]);
}
}

const interestingCases = makeDateCases();
const total = (interestingCases.length * (interestingCases.length - 1)) / 2;

await time(async (start) => {
Expand Down
45 changes: 45 additions & 0 deletions polyfill/test/thorough/datetimeaddition.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
assertTemporalEqual,
getProgressBar,
makeDateTimeCases,
makeDurationCases,
time,
withSnapshotsFromFile
} from './support.mjs';

const interestingDateTimeCases = makeDateTimeCases();
const interestingDurations = makeDurationCases();
const total = interestingDateTimeCases.length * interestingDurations.length;

await time(async (start) => {
const progress = getProgressBar(start, total);

await withSnapshotsFromFile('./datetimeaddition.snapshot.json', (matchSnapshot, matchSnapshotOrOutOfRange) => {
for (const [datetime, datetimeStr] of interestingDateTimeCases) {
for (const [duration, durationStr] of interestingDurations) {
const testName = `${datetimeStr}+${durationStr}`;
progress.tick(1, { test: testName.slice(0, 45) });

const later = matchSnapshotOrOutOfRange(() => datetime.add(duration), testName);
if (later) {
assertTemporalEqual(
datetime.subtract(duration.negated()),
later,
`${datetimeStr} - -${durationStr} = ${later}`
);
}

const earlier = matchSnapshotOrOutOfRange(() => datetime.subtract(duration), `${datetimeStr}-${durationStr}`);
if (earlier) {
assertTemporalEqual(
datetime.add(duration.negated()),
earlier,
`${datetimeStr} + -${durationStr} = ${earlier}`
);
}
}
}
});

return total;
});
250,514 changes: 250,514 additions & 0 deletions polyfill/test/thorough/datetimeaddition.snapshot.json

Large diffs are not rendered by default.

30 changes: 2 additions & 28 deletions polyfill/test/thorough/datetimedifference.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {
assertDurationsEqual,
assertTemporalEqual,
createDateSkippingInvalidCombinations,
getProgressBar,
interestingDateTimes,
interestingMonthDays,
interestingTimes,
interestingYears,
makeDateTimeCases,
temporalImpl as T,
time,
withSnapshotsFromFile
Expand All @@ -29,29 +25,7 @@ const largestUnits = [
['nanoseconds', reject]
];

// Every interesting date with every interesting time would take hours and hours
// to run. That would be interesting too, but too long for a CI job.
let timeIndex = 0;
const interestingCases = [];
for (const year of interestingYears) {
for (const [month, day] of interestingMonthDays) {
const date = createDateSkippingInvalidCombinations(year, month, day);
if (!date) continue;
const args = interestingTimes[timeIndex];
timeIndex++;
timeIndex %= interestingTimes.length;
const time = new T.PlainTime(...args);
if (date.toString() === '-271821-04-19' && time.toString() === '00:00:00') continue;
const datetime = date.toPlainDateTime(time);
// Pre-compute toString so it's not done repeatedly in each test
interestingCases.push([datetime, datetime.toString()]);
}
}
for (const args of interestingDateTimes) {
const datetime = new T.PlainDateTime(...args);
interestingCases.push([datetime, datetime.toString()]);
}

const interestingCases = makeDateTimeCases();
const total = (interestingCases.length * (interestingCases.length - 1)) / 2;

await time(async (start) => {
Expand Down
32 changes: 32 additions & 0 deletions polyfill/test/thorough/durationaddition.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { assertDurationsEqual, getProgressBar, makeDurationCases, time, withSnapshotsFromFile } from './support.mjs';

const interestingCases = makeDurationCases().filter(
// Only days and smaller
([d]) => !d.blank && d.years === 0 && d.months === 0 && d.weeks === 0
);
const total = (interestingCases.length * (interestingCases.length - 1)) / 2;

await time(async (start) => {
const progress = getProgressBar(start, total);

await withSnapshotsFromFile('./durationaddition.snapshot.json', (matchSnapshot, matchSnapshotOrOutOfRange) => {
for (const [d1, str1] of interestingCases) {
for (const [d2, str2] of interestingCases) {
const testName = `${str1}+${str2}`;
progress.tick(1, { test: testName.slice(0, 45) });

const added = matchSnapshotOrOutOfRange(() => d1.add(d2), testName);
if (added) {
assertDurationsEqual(d1.subtract(d2.negated()), added, `${str1} - -${str2} = ${added}`);
}

const subtracted = matchSnapshotOrOutOfRange(() => d1.subtract(d2), `${str1}-${str2}`);
if (subtracted) {
assertDurationsEqual(d1.add(d2.negated()), subtracted, `${str1} + -${str2} = ${subtracted}`);
}
}
}
});

return total;
});
Loading