Skip to content

Commit bd31585

Browse files
Ms2ger12wrigja
authored andcommitted
Drop Duration tests ported to test262.
UPSTREAM_COMMIT=621ed406ba25d753861d89cadf3732094495cb4b
1 parent 789306b commit bd31585

File tree

2 files changed

+1
-184
lines changed

2 files changed

+1
-184
lines changed

test/duration.mjs

Lines changed: 0 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ describe('Duration', () => {
2828
equal(d4.toString({ fractionalSecondDigits: 8, roundingMode: 'halfExpand' }), 'P1Y1M1W1DT23H59M60.00000000S');
2929
});
3030
});
31-
describe('toJSON()', () => {
32-
it('is like toString but always with auto precision', () => {
33-
const d = Duration.from({ hours: 1 });
34-
equal(d.toJSON(), d.toString({ fractionalSecondDigits: 'auto' }));
35-
});
36-
});
37-
describe('toLocaleString()', () => {
38-
it('produces an implementation-defined string', () => {
39-
const duration = Duration.from({ hours: 12, minutes: 30 });
40-
equal(typeof duration.toLocaleString(), 'string');
41-
});
42-
});
4331
describe('min/max values', () => {
4432
const units = [
4533
'years',
@@ -118,65 +106,6 @@ describe('Duration', () => {
118106
test(9, 'PT', 'S', '.');
119107
});
120108
});
121-
describe('Duration.with()', () => {
122-
const duration = new Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5);
123-
it('duration.with({ years: 1 } works', () => {
124-
equal(`${duration.with({ years: 1 })}`, 'P1Y5M5W5DT5H5M5.005005005S');
125-
});
126-
it('duration.with({ months: 1 } works', () => {
127-
equal(`${duration.with({ months: 1 })}`, 'P5Y1M5W5DT5H5M5.005005005S');
128-
});
129-
it('duration.with({ weeks: 1 } works', () => {
130-
equal(`${duration.with({ weeks: 1 })}`, 'P5Y5M1W5DT5H5M5.005005005S');
131-
});
132-
it('duration.with({ days: 1 } works', () => {
133-
equal(`${duration.with({ days: 1 })}`, 'P5Y5M5W1DT5H5M5.005005005S');
134-
});
135-
it('duration.with({ hours: 1 } works', () => {
136-
equal(`${duration.with({ hours: 1 })}`, 'P5Y5M5W5DT1H5M5.005005005S');
137-
});
138-
it('duration.with({ minutes: 1 } works', () => {
139-
equal(`${duration.with({ minutes: 1 })}`, 'P5Y5M5W5DT5H1M5.005005005S');
140-
});
141-
it('duration.with({ seconds: 1 } works', () => {
142-
equal(`${duration.with({ seconds: 1 })}`, 'P5Y5M5W5DT5H5M1.005005005S');
143-
});
144-
it('duration.with({ milliseconds: 1 } works', () => {
145-
equal(`${duration.with({ milliseconds: 1 })}`, 'P5Y5M5W5DT5H5M5.001005005S');
146-
});
147-
it('duration.with({ microseconds: 1 } works', () => {
148-
equal(`${duration.with({ microseconds: 1 })}`, 'P5Y5M5W5DT5H5M5.005001005S');
149-
});
150-
it('duration.with({ nanoseconds: 1 } works', () => {
151-
equal(`${duration.with({ nanoseconds: 1 })}`, 'P5Y5M5W5DT5H5M5.005005001S');
152-
});
153-
it('duration.with({ months: 1, seconds: 15 } works', () => {
154-
equal(`${duration.with({ months: 1, seconds: 15 })}`, 'P5Y1M5W5DT5H5M15.005005005S');
155-
});
156-
it('mixed positive and negative values throw', () => {
157-
throws(() => duration.with({ hours: 1, minutes: -1 }), RangeError);
158-
});
159-
it('can reverse the sign if all the fields are replaced', () => {
160-
const d = Duration.from({ years: 5, days: 1 });
161-
const d2 = d.with({ years: -1, days: -1, minutes: 0 });
162-
equal(`${d2}`, '-P1Y1D');
163-
notEqual(d.sign, d2.sign);
164-
});
165-
it('throws if new fields have a different sign from the old fields', () => {
166-
const d = Duration.from({ years: 5, days: 1 });
167-
throws(() => d.with({ months: -5, minutes: 0 }), RangeError);
168-
});
169-
it('sign cannot be manipulated independently', () => {
170-
throws(() => duration.with({ sign: -1 }), TypeError);
171-
});
172-
it('object must contain at least one correctly-spelled property', () => {
173-
throws(() => duration.with({}), TypeError);
174-
throws(() => duration.with({ month: 12 }), TypeError);
175-
});
176-
it('incorrectly-spelled properties are ignored', () => {
177-
equal(`${duration.with({ month: 1, days: 1 })}`, 'P5Y5M5W1DT5H5M5.005005005S');
178-
});
179-
});
180109
describe('Duration.add()', () => {
181110
const duration = Duration.from({ days: 1, minutes: 5 });
182111
it('adds same units', () => {
@@ -232,9 +161,6 @@ describe('Duration', () => {
232161
equal(`${dm.add(d, { relativeTo })}`, 'P1MT1H');
233162
equal(`${dw.add(d, { relativeTo })}`, 'P1WT1H');
234163
});
235-
it('options may be an object', () => {
236-
[{}, () => {}].forEach((options) => equal(duration.add({ hours: 1 }, options).hours, 1));
237-
});
238164
it('object must contain at least one correctly-spelled property', () => {
239165
throws(() => duration.add({}), TypeError);
240166
throws(() => duration.add({ month: 12 }), TypeError);
@@ -465,9 +391,6 @@ describe('Duration', () => {
465391
equal(`${dm.subtract(d, { relativeTo })}`, 'P1M');
466392
equal(`${dw.subtract(d, { relativeTo })}`, 'P1W');
467393
});
468-
it('options may be an object', () => {
469-
[{}, () => {}].forEach((options) => equal(duration.subtract({ hours: 1 }, options).hours, 0));
470-
});
471394
it('object must contain at least one correctly-spelled property', () => {
472395
throws(() => duration.subtract({}), TypeError);
473396
throws(() => duration.subtract({ month: 12 }), TypeError);
@@ -580,48 +503,6 @@ describe('Duration', () => {
580503
throws(() => oneDay.subtract(hours24, { relativeTo: { year: 2019, month: 11 } }), TypeError);
581504
throws(() => oneDay.subtract(hours24, { relativeTo: { year: 2019, day: 3 } }), TypeError);
582505
});
583-
});
584-
describe("Comparison operators don't work", () => {
585-
const d1 = Duration.from('P3DT1H');
586-
const d1again = Duration.from('P3DT1H');
587-
const d2 = Duration.from('PT2H20M30S');
588-
it('=== is object equality', () => equal(d1, d1));
589-
it('!== is object equality', () => notEqual(d1, d1again));
590-
it('<', () => throws(() => d1 < d2));
591-
it('>', () => throws(() => d1 > d2));
592-
it('<=', () => throws(() => d1 <= d2));
593-
it('>=', () => throws(() => d1 >= d2));
594-
});
595-
describe('Duration.negated()', () => {
596-
it('makes a positive duration negative', () => {
597-
const pos = Duration.from('P3DT1H');
598-
const neg = pos.negated();
599-
equal(`${neg}`, '-P3DT1H');
600-
equal(neg.sign, -1);
601-
});
602-
it('makes a negative duration positive', () => {
603-
const neg = Duration.from('-PT2H20M30S');
604-
const pos = neg.negated();
605-
equal(`${pos}`, 'PT2H20M30S');
606-
equal(pos.sign, 1);
607-
});
608-
it('makes a copy of a zero duration', () => {
609-
const zero = Duration.from('PT0S');
610-
const zero2 = zero.negated();
611-
equal(`${zero}`, `${zero2}`);
612-
notEqual(zero, zero2);
613-
equal(zero2.sign, 0);
614-
equal(zero2.years, 0);
615-
equal(zero2.months, 0);
616-
equal(zero2.weeks, 0);
617-
equal(zero2.days, 0);
618-
equal(zero2.hours, 0);
619-
equal(zero2.minutes, 0);
620-
equal(zero2.seconds, 0);
621-
equal(zero2.milliseconds, 0);
622-
equal(zero2.microseconds, 0);
623-
equal(zero2.nanoseconds, 0);
624-
});
625506
it('throws with invalid offset in relativeTo', () => {
626507
throws(
627508
() =>
@@ -632,57 +513,10 @@ describe('Duration', () => {
632513
);
633514
});
634515
});
635-
describe('Duration.abs()', () => {
636-
it('makes a copy of a positive duration', () => {
637-
const pos = Duration.from('P3DT1H');
638-
const pos2 = pos.abs();
639-
equal(`${pos}`, `${pos2}`);
640-
notEqual(pos, pos2);
641-
equal(pos2.sign, 1);
642-
});
643-
it('makes a negative duration positive', () => {
644-
const neg = Duration.from('-PT2H20M30S');
645-
const pos = neg.abs();
646-
equal(`${pos}`, 'PT2H20M30S');
647-
equal(pos.sign, 1);
648-
});
649-
it('makes a copy of a zero duration', () => {
650-
const zero = Duration.from('PT0S');
651-
const zero2 = zero.abs();
652-
equal(`${zero}`, `${zero2}`);
653-
notEqual(zero, zero2);
654-
equal(zero2.sign, 0);
655-
});
656-
});
657-
describe('Duration.blank', () => {
658-
it('works', () => {
659-
assert(!Duration.from('P3DT1H').blank);
660-
assert(!Duration.from('-PT2H20M30S').blank);
661-
assert(Duration.from('PT0S').blank);
662-
});
663-
it('zero regardless of how many fields are in the duration', () => {
664-
const zero = Duration.from({
665-
years: 0,
666-
months: 0,
667-
weeks: 0,
668-
days: 0,
669-
hours: 0,
670-
minutes: 0,
671-
seconds: 0,
672-
milliseconds: 0,
673-
microseconds: 0,
674-
nanoseconds: 0
675-
});
676-
assert(zero.blank);
677-
});
678-
});
679516
describe('Duration.round()', () => {
680517
const d = new Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5);
681518
const d2 = new Duration(0, 0, 0, 5, 5, 5, 5, 5, 5, 5);
682519
const relativeTo = Temporal.PlainDate.from('2020-01-01');
683-
it('parameter may only be an object or string', () => {
684-
[null, 1, true, Symbol('foo'), 1n].forEach((badOptions) => throws(() => d.round(badOptions), TypeError));
685-
});
686520
it('throws without parameter', () => {
687521
throws(() => d.round(), TypeError);
688522
});
@@ -692,11 +526,6 @@ describe('Duration', () => {
692526
it("succeeds with largestUnit: 'auto'", () => {
693527
equal(`${Duration.from({ hours: 25 }).round({ largestUnit: 'auto' })}`, 'PT25H');
694528
});
695-
it('throws on disallowed or invalid smallestUnit (string param)', () => {
696-
['era', 'nonsense'].forEach((smallestUnit) => {
697-
throws(() => d.round(smallestUnit), RangeError);
698-
});
699-
});
700529
it('throws if smallestUnit is larger than largestUnit', () => {
701530
const units = [
702531
'years',
@@ -1531,18 +1360,6 @@ describe('Duration', () => {
15311360
const twoYears = Duration.from({ months: -11, days: -396 });
15321361
equal(twoYears.total({ unit: 'years', relativeTo: '2017-01-01' }), -2);
15331362
});
1534-
it('accepts singular units', () => {
1535-
equal(d.total({ unit: 'year', relativeTo }), d.total({ unit: 'years', relativeTo }));
1536-
equal(d.total({ unit: 'month', relativeTo }), d.total({ unit: 'months', relativeTo }));
1537-
equal(d.total({ unit: 'day', relativeTo }), d.total({ unit: 'days', relativeTo }));
1538-
equal(d.total({ unit: 'hour', relativeTo }), d.total({ unit: 'hours', relativeTo }));
1539-
equal(d.total({ unit: 'minute', relativeTo }), d.total({ unit: 'minutes', relativeTo }));
1540-
equal(d.total({ unit: 'second', relativeTo }), d.total({ unit: 'seconds', relativeTo }));
1541-
equal(d.total({ unit: 'second', relativeTo }), d.total({ unit: 'seconds', relativeTo }));
1542-
equal(d.total({ unit: 'millisecond', relativeTo }), d.total({ unit: 'milliseconds', relativeTo }));
1543-
equal(d.total({ unit: 'microsecond', relativeTo }), d.total({ unit: 'microseconds', relativeTo }));
1544-
equal(d.total({ unit: 'nanosecond', relativeTo }), d.total({ unit: 'nanoseconds', relativeTo }));
1545-
});
15461363
it('throws with invalid offset in relativeTo', () => {
15471364
throws(
15481365
() =>

0 commit comments

Comments
 (0)