forked from eemeli/prettier-plugin-properties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
32 lines (29 loc) · 1.09 KB
/
index.test.js
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
const prettier = require('prettier')
const format = (src, opt) =>
prettier.format(
src,
Object.assign({ parser: 'dot-properties', plugins: ['.'] }, opt)
)
const cases = [
['foo', 'foo =\n'],
['foo bar', 'foo = bar\n'],
['foo=bar', 'foo = bar\n'],
['foo=foo\r\nbar=bar\r\n', 'foo = foo\nbar = bar\n'],
['foo\\ bar baz', 'foo\\ bar = baz\n'],
['😀=💚', '😀 = 💚\n'],
['😀=💚', '\\ud83d\\ude00 = \\ud83d\\udc9a\n', { escapeNonLatin1: true }],
['foo=bar', 'foo: bar\n', { keySeparator: ': ' }],
['foo=bar', 'foo = \\\n bar\n', { printWidth: 6 }],
['foo=bar', 'foo = \\\n\tbar\n', { printWidth: 6, useTabs: true }],
['foo=bar', '# @format\nfoo = bar\n', { insertPragma: true }],
['# @format\nfoo=bar', '# @format\nfoo = bar\n', { insertPragma: true }],
[
'foo=foo\n# prettier-ignore\nbar:bar\n',
'foo = foo\n# prettier-ignore\nbar:bar'
]
]
for (const [src, exp, opt] of cases) {
let name = src.replace(/\n/g, '\\n').replace(/\r/g, '\\r')
if (opt) name += ` { ${Object.keys(opt)} }`
test(name, async () => expect(await format(src, opt)).toBe(exp))
}