Skip to content

Commit

Permalink
bring test coverage up to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Nov 21, 2017
1 parent 2ad741b commit ca69873
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 5 additions & 3 deletions ini.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
exports.parse = exports.decode = decode

exports.stringify = exports.encode = encode

exports.safe = safe
exports.unsafe = unsafe

var eol = typeof process !== 'undefined' && process.platform === 'win32' ? '\r\n' : '\n'
var eol = typeof process !== 'undefined' &&
process.platform === 'win32' ? '\r\n' : '\n'

function encode (obj, opt) {
var children = []
Expand Down Expand Up @@ -82,7 +84,7 @@ function decode (str) {
return
}
var key = unsafe(match[2])
var value = match[3] ? unsafe((match[4] || '')) : true
var value = match[3] ? unsafe(match[4]) : true
switch (value) {
case 'true':
case 'false':
Expand Down Expand Up @@ -186,7 +188,7 @@ function unsafe (val, doUnesc) {
if (esc) {
unesc += '\\'
}
return unesc
return unesc.trim()
}
return val
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"main": "ini.js",
"scripts": {
"pretest": "standard ini.js",
"test": "tap test/*.js"
"test": "tap test/*.js --100"
},
"engines": {
"node": "*"
Expand Down
22 changes: 22 additions & 0 deletions test/win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var t = require('tap')
Object.defineProperty(process, 'platform', { value: 'win32' })
const ini = require('../ini.js')

const res = ini.encode({foo: { bar: 'baz' }})
t.equal(res, "[foo]\r\nbar=baz\r\n")

t.equal(ini.encode({bar: 'baz'}, 'foo'), '[foo]\r\nbar=baz\r\n')

t.same(ini.decode('=just junk!\r\n[foo]\r\nbar\r\n'),
{ foo: { bar: true }})

t.same(ini.decode('[x]\r\ny=1\r\ny[]=2\r\n'), {
x: {
y: [1, 2]
}
})

t.equal(ini.unsafe(''), '')
t.equal(ini.unsafe('x;y'), 'x')
t.equal(ini.unsafe('x # y'), 'x')
t.equal(ini.unsafe('x "\\'), 'x "\\')

0 comments on commit ca69873

Please sign in to comment.