-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathformat-generator.test.js
More file actions
49 lines (44 loc) · 1.54 KB
/
format-generator.test.js
File metadata and controls
49 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
const format = require('util').format
const { test } = require('node:test')
const formatGenerator = require('../lib/format-generator')
const circular = {}
circular.circular = circular
const testCases = [
['%%', [], '%%'],
['%% %s', [], '%% %s'],
['%% %d', [2], '% 2'],
['no specifier', [], 'no specifier'],
['string %s', [0], 'string 0'],
['string %s', [-0], 'string -0'],
['string %s', [0n], 'string 0n'],
['string %s', [Infinity], 'string Infinity'],
['string %s', [-Infinity], 'string -Infinity'],
['string %s', [-NaN], 'string NaN'],
['string %s', [undefined], 'string undefined'],
['%s', [{ toString: () => 'Foo' }], 'Foo'],
['integer %i', [0n], 'integer 0n'],
['integer %i', [Infinity], 'integer NaN'],
['integer %i', [-Infinity], 'integer NaN'],
['integer %i', [NaN], 'integer NaN'],
['string %s', ['yes'], 'string yes'],
['float %f', [0], 'float 0'],
['float %f', [-0], 'float 0'],
['float %f', [0.0000001], 'float 1e-7'],
['float %f', [0.000001], 'float 0.000001'],
['float %f', ['a'], 'float NaN'],
['float %f', [{}], 'float NaN'],
['json %j', [{}], 'json {}'],
['json %j', [circular], 'json [Circular]'],
['%s:%s', ['foo'], 'foo:%s'],
['%s:%c', ['foo', 'bar'], 'foo:'],
['%o', [{}], '{}'],
['%O', [{}], '{}']
]
test('formatGenerator', t => {
t.plan(testCases.length * 2)
for (const [testCase, args, expected] of testCases) {
t.assert.strictEqual(formatGenerator(testCase)(args), expected)
t.assert.strictEqual(formatGenerator(testCase)(args), format(testCase, ...args))
}
})