forked from npm/ini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo.js
96 lines (75 loc) · 2.26 KB
/
foo.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const i = require('../')
const tap = require('tap')
const test = tap.test
const fs = require('fs')
const path = require('path')
const fixture = path.resolve(__dirname, './fixtures/foo.ini')
const data = fs.readFileSync(fixture, 'utf8')
tap.cleanSnapshot = s => s.replace(/\r\n/g, '\n')
test('decode from file', function (t) {
const d = i.decode(data)
t.matchSnapshot(d)
t.end()
})
test('encode from data', function (t) {
const d = i.decode(data)
const e = i.encode(d)
t.matchSnapshot(e)
t.end()
})
test('never a blank first or last line', function (t) {
const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj)
t.not(e.slice(0, 1), '\n', 'Never a blank first line')
t.not(e.slice(-2), '\n\n', 'Never a blank final line')
t.end()
})
test('encode with option', function (t) {
const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj, { section: 'prefix' })
t.matchSnapshot(e)
t.end()
})
test('encode with whitespace', function (t) {
const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj, { whitespace: true })
t.matchSnapshot(e)
t.end()
})
test('encode with newline', function (t) {
const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj, { newline: true })
t.matchSnapshot(e)
t.end()
})
test('encode with platform=win32', function (t) {
const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj, { platform: 'win32' })
t.matchSnapshot(e.split('\r\n'))
t.end()
})
test('encode with align', function (t) {
const d = i.decode(data)
const e = i.encode(d, { align: true })
t.matchSnapshot(e)
t.end()
})
test('encode with sort', function (t) {
const d = i.decode(data)
const e = i.encode(d, { sort: true })
t.matchSnapshot(e)
t.end()
})
test('encode with align and sort', function (t) {
const d = i.decode(data)
const e = i.encode(d, { align: true, sort: true })
t.matchSnapshot(e)
t.end()
})
test('encode within browser context', function (t) {
process = undefined
const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj)
t.matchSnapshot(e)
t.end()
})