0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-error-format-list.js
Aras Abbasi 4f84a3d200
errors: improve formatList in errors.js
PR-URL: https://github.com/nodejs/node/pull/49642
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-09-29 11:04:38 +00:00

21 lines
682 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const { strictEqual } = require('node:assert');
const { formatList } = require('internal/errors');
if (!common.hasIntl) common.skip('missing Intl');
{
const and = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
const or = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' });
const input = ['apple', 'banana', 'orange', 'pear'];
for (let i = 0; i < input.length; i++) {
const slicedInput = input.slice(0, i);
strictEqual(formatList(slicedInput), and.format(slicedInput));
strictEqual(formatList(slicedInput, 'or'), or.format(slicedInput));
}
}