-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexternal.tests.js
More file actions
66 lines (58 loc) · 1.62 KB
/
external.tests.js
File metadata and controls
66 lines (58 loc) · 1.62 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const fs = require('fs')
const path = require('path')
const { parse, parseLines, stringify } = require('../lib/index')
function testCase({
name,
root,
srcPath,
tgtPath,
options: { parsePath = false } = {}
}) {
test(name, () => {
const src = fs.readFileSync(path.resolve(root, srcPath), 'utf8')
const tgt = fs.readFileSync(path.resolve(root, tgtPath), 'utf8')
const exp = JSON.parse(tgt)
// parse(string): object
const res = parse(src, parsePath)
expect(res).toMatchObject(exp)
// stringify(object): string
const src2 = stringify(res)
const res2 = parse(src2, parsePath)
expect(res2).toMatchObject(exp)
// parseLines(string, true): Node[]
const ast = parseLines(src, true)
const res3 = parse(ast, parsePath)
expect(res3).toMatchObject(exp)
// stringify(Node[])
const src3 = stringify(ast)
const res4 = parse(src3, parsePath)
expect(res4).toMatchObject(exp)
})
}
describe('@js.properties', () => {
const root = path.resolve(__dirname, '@js.properties')
const tests = fs.readdirSync(root).filter(name => /\.properties$/.test(name))
tests.forEach(name => {
testCase({
name,
root,
srcPath: name,
tgtPath: name + '.json'
})
})
testCase({
name: 'namespaced properties with path',
root,
srcPath: 'namespaced.properties',
tgtPath: 'namespaced.properties.namespaced.json',
options: { parsePath: true }
})
})
describe('node-properties-parser', () => {
testCase({
name: 'test',
root: path.resolve(__dirname, 'node-properties-parser'),
srcPath: 'test.properties',
tgtPath: 'test.json'
})
})