summaryrefslogtreecommitdiff
path: root/test/parallel/test-error-format-list.js
blob: 54ae4e0aee714dca24e88d93b777456c68cdec15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 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'];
  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));
  }
}