Skip to content

Commit ca69873

Browse files
committed
bring test coverage up to 100%
1 parent 2ad741b commit ca69873

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

ini.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
exports.parse = exports.decode = decode
2+
23
exports.stringify = exports.encode = encode
34

45
exports.safe = safe
56
exports.unsafe = unsafe
67

7-
var eol = typeof process !== 'undefined' && process.platform === 'win32' ? '\r\n' : '\n'
8+
var eol = typeof process !== 'undefined' &&
9+
process.platform === 'win32' ? '\r\n' : '\n'
810

911
function encode (obj, opt) {
1012
var children = []
@@ -82,7 +84,7 @@ function decode (str) {
8284
return
8385
}
8486
var key = unsafe(match[2])
85-
var value = match[3] ? unsafe((match[4] || '')) : true
87+
var value = match[3] ? unsafe(match[4]) : true
8688
switch (value) {
8789
case 'true':
8890
case 'false':
@@ -186,7 +188,7 @@ function unsafe (val, doUnesc) {
186188
if (esc) {
187189
unesc += '\\'
188190
}
189-
return unesc
191+
return unesc.trim()
190192
}
191193
return val
192194
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"main": "ini.js",
1111
"scripts": {
1212
"pretest": "standard ini.js",
13-
"test": "tap test/*.js"
13+
"test": "tap test/*.js --100"
1414
},
1515
"engines": {
1616
"node": "*"

test/win32.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var t = require('tap')
2+
Object.defineProperty(process, 'platform', { value: 'win32' })
3+
const ini = require('../ini.js')
4+
5+
const res = ini.encode({foo: { bar: 'baz' }})
6+
t.equal(res, "[foo]\r\nbar=baz\r\n")
7+
8+
t.equal(ini.encode({bar: 'baz'}, 'foo'), '[foo]\r\nbar=baz\r\n')
9+
10+
t.same(ini.decode('=just junk!\r\n[foo]\r\nbar\r\n'),
11+
{ foo: { bar: true }})
12+
13+
t.same(ini.decode('[x]\r\ny=1\r\ny[]=2\r\n'), {
14+
x: {
15+
y: [1, 2]
16+
}
17+
})
18+
19+
t.equal(ini.unsafe(''), '')
20+
t.equal(ini.unsafe('x;y'), 'x')
21+
t.equal(ini.unsafe('x # y'), 'x')
22+
t.equal(ini.unsafe('x "\\'), 'x "\\')

0 commit comments

Comments
 (0)