Skip to content

Commit 9888f2a

Browse files
committed
Make tests compatible with cldr-engine v1.13
1 parent 02129d4 commit 9888f2a

File tree

10 files changed

+47
-36
lines changed

10 files changed

+47
-36
lines changed

__tests__/context.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test('too many pops', () => {
160160
const ctx = new Context({ a: 1 });
161161
ctx.pushSection(['a']);
162162
ctx.pop();
163-
expect(() => ctx.pop()).toThrowError(Error);
163+
expect(() => ctx.pop()).toThrow(Error);
164164
});
165165

166166
test('resolve missing', () => {

__tests__/parser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const parser = (str: string) => {
3030

3131
test('initialization failures', () => {
3232
const matcher = undefined as unknown as Matcher;
33-
expect(() => new Parser('hello', {} as Sink, matcher)).toThrowError();
33+
expect(() => new Parser('hello', {} as Sink, matcher)).toThrow();
3434
});
3535

3636
test('degenerate cases', () => {

__tests__/plugins/formatters.i18n.test.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ test('datetime', () => {
135135
expect(formatDatetime(DE, d, ZONE_NY, args)).toEqual('12. März 2018');
136136

137137
args = ['date:full', 'time:full'];
138-
expect(formatDatetime(EN, d, ZONE_NY, args)).toEqual('Monday, March 12, 2018 at 1:48:54 PM Eastern Daylight Time');
138+
expect(formatDatetime(EN, d, ZONE_NY, args)).toEqual('Monday, March 12, 2018 at 1:48:54PM Eastern Daylight Time');
139139
expect(formatDatetime(DE, d, ZONE_NY, args)).toEqual(
140140
'Montag, 12. März 2018 um 13:48:54 Nordamerikanische Ostküsten-Sommerzeit',
141141
);
142142

143143
args = ['time:medium'];
144-
expect(formatDatetime(EN, d, ZONE_LON, args)).toEqual('5:48:54 PM');
145-
expect(formatDatetime(EN, d, ZONE_NY, args)).toEqual('1:48:54 PM');
146-
expect(formatDatetime(EN, d, ZONE_LA, args)).toEqual('10:48:54 AM');
144+
expect(formatDatetime(EN, d, ZONE_LON, args)).toEqual('5:48:54PM');
145+
expect(formatDatetime(EN, d, ZONE_NY, args)).toEqual('1:48:54PM');
146+
expect(formatDatetime(EN, d, ZONE_LA, args)).toEqual('10:48:54AM');
147147

148148
// Mixed date/time and skeleton
149149
args = ['date:medium', 'time:Bh'];
@@ -188,9 +188,9 @@ test('datetime-interval', () => {
188188
// March 12, 2018 5:48:54 PM UTC
189189
const start = 1520876934000;
190190
const args: string[] = [];
191-
expect(formatInterval(EN, start, start + 2000, ZONE_NY, args)).toEqual('1:48:54 PM');
192-
expect(formatInterval(EN, start, start + 12000, ZONE_NY, args)).toEqual('1:481:49 PM');
193-
expect(formatInterval(EN, start, start + ONE_DAY_MS, ZONE_NY, args)).toEqual('Mar 1213, 2018');
191+
expect(formatInterval(EN, start, start + 2000, ZONE_NY, args)).toEqual('1:48PM');
192+
expect(formatInterval(EN, start, start + 12000, ZONE_NY, args)).toEqual('1:48 – 1:49PM');
193+
expect(formatInterval(EN, start, start + ONE_DAY_MS, ZONE_NY, args)).toEqual('Mar 12 – 13, 2018');
194194

195195
// Undefined cldr produces empty output
196196
expect(formatInterval(undefined, start, start + 2000, ZONE_NY, args)).toEqual('');
@@ -229,15 +229,15 @@ test('message', () => {
229229

230230
ctx = { website: { timeZone: 'America/Los_Angeles' }, epoch: 1582648395000 };
231231
args = ['epoch'];
232-
expect(formatMessage(EN, 'date {0 datetime time:full}', args, ctx)).toEqual('date 8:33:15 AM Pacific Standard Time');
232+
expect(formatMessage(EN, 'date {0 datetime time:full}', args, ctx)).toEqual('date 8:33:15AM Pacific Standard Time');
233233

234234
ctx = { n: '123456.789' };
235235
args = ['n'];
236236
expect(formatMessage(EN, 'num {0 decimal maximumFractionDigits:1}', args, ctx)).toEqual('num 123,456.8');
237237

238238
ctx = { s: 1582648395000, e: 1583748395000 };
239239
args = ['s', 'e'];
240-
expect(formatMessage(EN, 'inv {0;1 datetime-interval}', args, ctx)).toEqual('inv Feb 25Mar 9, 2020');
240+
expect(formatMessage(EN, 'inv {0;1 datetime-interval}', args, ctx)).toEqual('inv Feb 25 – Mar 9, 2020');
241241

242242
// Undefined cldr produces empty output
243243
expect(formatMessage(undefined, '{0}', args, ctx)).toEqual('');
@@ -269,7 +269,7 @@ test('relative time', () => {
269269
e = start.add({ millis: -100 }).unixEpoch();
270270
expect(formatRelativeTime(EN, base, variables(e), ['numericOnly:true'])).toEqual('0 seconds ago');
271271

272-
e = start.add({ year: -1.6 }).unixEpoch();
272+
e = start.add({ year: -2 }).unixEpoch();
273273
expect(formatRelativeTime(EN, base, variables(e), args)).toEqual('2 years ago');
274274
expect(formatRelativeTime(DE, base, variables(e), args)).toEqual('Vor 2 Jahren');
275275
expect(formatRelativeTime(ES, base, variables(e), args)).toEqual('Hace 2 años');
@@ -284,11 +284,16 @@ test('relative time', () => {
284284
expect(formatRelativeTime(EN, undefined, variables(base, e), args)).toEqual('6 months ago');
285285

286286
e = start.add({ day: -27 }).unixEpoch();
287-
expect(formatRelativeTime(EN, base, variables(e), args)).toEqual('4 weeks ago');
288-
expect(formatRelativeTime(DE, base, variables(e), args)).toEqual('Vor 4 Wochen');
289-
expect(formatRelativeTime(ES, base, variables(e), args)).toEqual('Hace 4 semanas');
290-
291-
expect(formatRelativeTime(EN, undefined, variables(base, e), args)).toEqual('4 weeks ago');
287+
const weekargs = [...args, 'allowWeeks:true'];
288+
expect(formatRelativeTime(EN, base, variables(e), weekargs)).toEqual('4 weeks ago');
289+
expect(formatRelativeTime(DE, base, variables(e), weekargs)).toEqual('Vor 4 Wochen');
290+
expect(formatRelativeTime(ES, base, variables(e), weekargs)).toEqual('Hace 4 semanas');
291+
expect(formatRelativeTime(EN, undefined, variables(base, e), weekargs)).toEqual('4 weeks ago');
292+
293+
expect(formatRelativeTime(EN, base, variables(e), args)).toEqual('27 days ago');
294+
expect(formatRelativeTime(DE, base, variables(e), args)).toEqual('Vor 27 Tagen');
295+
expect(formatRelativeTime(ES, base, variables(e), args)).toEqual('Hace 27 días');
296+
expect(formatRelativeTime(EN, undefined, variables(base, e), args)).toEqual('27 days ago');
292297

293298
e = start.add({ hour: -27 }).unixEpoch();
294299
expect(formatRelativeTime(EN, base, variables(e), args)).toEqual('Yesterday');

__tests__/plugins/messages.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('message formats', () => {
3737

3838
expect(f['datetime-interval']([], [])).toEqual('');
3939
expect(f['datetime-interval'](undefined as any, [])).toEqual('');
40-
expect(f['datetime-interval']([date1, date2], [])).toEqual('Mar 3Apr 3, 2021');
40+
expect(f['datetime-interval']([date1, date2], [])).toEqual('Mar 3 – Apr 3, 2021');
4141
});
4242

4343
test('custom converter', () => {

__tests__/plugins/resources/f-datetime-1.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222

2323
:OUTPUT
2424
February 24, 2020
25-
2/24/20, 2:04 PM
26-
Feb 24, 2020, 2:04:40 PM
27-
February 24, 2020 at 2:04:40 PM EST
28-
Monday, February 24, 2020 at 2:04:40 PM Eastern Standard Time
25+
2/24/20, 2:04PM
26+
Feb 24, 2020, 2:04:40PM
27+
February 24, 2020 at 2:04:40PM EST
28+
Monday, February 24, 2020 at 2:04:40PM Eastern Standard Time
2929

30-
2/24/20, 2:04:40 PM
31-
Monday, February 24, 2020 at 2:04 PM
30+
2/24/20, 2:04:40PM
31+
Monday, February 24, 2020 at 2:04PM
3232

3333
Mon, Feb 24, 2020
3434
Monday, February 24, 2020
3535
2 in the afternoon
36-
2/24/2020, 2:04 PM
37-
Feb 24, 2020 at 2:04 PM
36+
2/24/2020, 2:04PM
37+
Feb 24, 2020 at 2:04PM

__tests__/plugins/resources/f-datetime-interval-1.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
{s,e3|datetime-interval yMMM}
1515

1616
:OUTPUT
17-
2:047:38 PM
18-
Feb 24Jun 19, 2020
19-
Feb 24, 2020Aug 21, 2023
17+
2:04 – 7:38PM
18+
Feb 24 – Jun 19, 2020
19+
Feb 24, 2020 – Aug 21, 2023
2020

21-
Feb 2020Aug 2023
21+
Feb 2020 – Aug 2023
2222

__tests__/plugins/resources/f-message-6.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
:OUTPUT
1414
February 25, 2020
15-
Tuesday, February 25, 2020 at 12:51:50 PM Pacific Standard Time
16-
2/25/20, 12:51:50 PM Pacific Standard Time
15+
Tuesday, February 25, 2020 at 12:51:50PM Pacific Standard Time
16+
2/25/20, 12:51:50PM Pacific Standard Time

__tests__/plugins/resources/f-message-7.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
{msg|message s e}
1010

1111
:OUTPUT
12-
Feb 25Mar 9, 2020
13-
Tuesday, February 25Monday, March 9, 2020
14-
Tue, 2/25 – Mon, 3/9
12+
Feb 25 – Mar 9, 2020
13+
Tuesday, February 25 – Monday, March 9, 2020
14+
Tue, 3:51 PM – Mon, 10:25 AM

__tests__/plugins/resources/f-relative-time-1.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
:TEMPLATE
2020
{.repeated section dates}
21-
{start, end|relative-time}{.end}
21+
{start, end|relative-time}
22+
{start, end|relative-time allowWeeks:true}{.end}
2223
{.repeated section timestamps}
2324
{@|relative-time context:begin-sentence}{.end}
2425

2526
:OUTPUT
27+
in 12 days
2628
in 2 weeks
2729
in 2 hours
30+
in 2 hours
2831

2932
In 2 hours
3033
11 hours ago

src/plugins/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ const relativetimeOption = (arg: string, val: string, options: RelativeTimeForma
336336
case 'numericOnly':
337337
options.numericOnly = val === 'true';
338338
break;
339+
case 'allowWeeks':
340+
options.allowWeeks = val === 'true';
341+
break;
339342
case 'alwaysNow':
340343
options.alwaysNow = val === 'true';
341344
break;

0 commit comments

Comments
 (0)