Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
working on passing tests
  • Loading branch information
Stephan Huber committed Mar 20, 2018
commit 70d29c547b44a441ffea867ecdae45c4ab0b7c7a
2 changes: 1 addition & 1 deletion test/fixtures/foo.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ar[] = three
; This should be included in the array
ar = this is included

; Test resetting of a value (and not turn it into an array)
; Turn this into an array
br = cold
br = warm

Expand Down
96 changes: 49 additions & 47 deletions test/foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,54 @@ var i = require("../")
, data = fs.readFileSync(fixture, "utf8")
, d
, expectE = 'o=p\n'
+ 'a with spaces=b c\n'
+ '" xa n p "="\\"\\r\\nyoyoyo\\r\\r\\n"\n'
+ '"[disturbing]"=hey you never know\n'
+ 's=something\n'
+ 's1=\"something\'\n'
+ 's2=something else\n'
+ 'zr[]=deedee\n'
+ 'ar[]=one\n'
+ 'ar[]=three\n'
+ 'ar[]=this is included\n'
+ 'br=warm\n'
+ 'eq=\"eq=eq\"\n'
+ '\n'
+ '[a]\n'
+ 'av=a val\n'
+ 'e={ o: p, a: '
+ '{ av: a val, b: { c: { e: "this [value]" '
+ '} } } }\nj="\\"{ o: \\"p\\", a: { av:'
+ ' \\"a val\\", b: { c: { e: \\"this [value]'
+ '\\" } } } }\\""\n"[]"=a square?\n'
+ 'cr[]=four\ncr[]=eight\n\n'
+'[a.b.c]\ne=1\n'
+ 'j=2\n\n[x\\.y\\.z]\nx.y.z=xyz\n\n'
+ '[x\\.y\\.z.a\\.b\\.c]\na.b.c=abc\n'
+ 'nocomment=this\\; this is not a comment\n'
+ 'noHashComment=this\\# this is not a comment\n'
+ 'a with spaces=b c\n'
+ '" xa n p "="\\"\\r\\nyoyoyo\\r\\r\\n"\n'
+ '"[disturbing]"=hey you never know\n'
+ 's=something\n'
+ 's1=\"something\'\n'
+ 's2=something else\n'
+ 'zr[]=deedee\n'
+ 'ar[]=one\n'
+ 'ar[]=three\n'
+ 'ar[]=this is included\n'
+ 'br=warm\n'
+ 'eq=\"eq=eq\"\n'
+ '\n'
+ '[a]\n'
+ 'av=a val\n'
+ 'e={ o: p, a: '
+ '{ av: a val, b: { c: { e: "this [value]" '
+ '} } } }\nj="\\"{ o: \\"p\\", a: { av:'
+ ' \\"a val\\", b: { c: { e: \\"this [value]'
+ '\\" } } } }\\""\n"[]"=a square?\n'
+ 'cr[]=four\ncr[]=eight\n\n'
+ '[a.b.c]\ne=1\n'
+ 'j=2\n\n[x\\.y\\.z]\nx.y.z=xyz\n\n'
+ '[x\\.y\\.z.a\\.b\\.c]\na.b.c=abc\n'
+ 'nocomment=this\\; this is not a comment\n'
+ 'noHashComment=this\\# this is not a comment\n'
, expectD =
{ o: 'p',
{
o: 'p',
'a with spaces': 'b c',
" xa n p ":'"\r\nyoyoyo\r\r\n',
" xa n p ": '"\r\nyoyoyo\r\r\n',
'[disturbing]': 'hey you never know',
's': 'something',
's1' : '\"something\'',
's1': '\"something\'',
's2': 'something else',
'zr': ['deedee'],
'ar': ['one', 'three', 'this is included'],
'br': 'warm',
'br': ['cold', 'warm'],
'eq': 'eq=eq',
a:
{ av: 'a val',
e: '{ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }',
j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"',
"[]": "a square?",
cr: ['four', 'eight'],
b: { c: { e: '1', j: '2' } } },
{
av: 'a val',
e: '{ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }',
j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"',
"[]": "a square?",
cr: ['four', 'eight'],
b: { c: { e: '1', j: '2' } }
},
'x.y.z': {
'x.y.z': 'xyz',
'a.b.c': {
Expand All @@ -62,15 +65,15 @@ var i = require("../")
}
}
, expectF = '[prefix.log]\n'
+ 'type=file\n\n'
+ '[prefix.log.level]\n'
+ 'label=debug\n'
+ 'value=10\n'
+ 'type=file\n\n'
+ '[prefix.log.level]\n'
+ 'label=debug\n'
+ 'value=10\n'
, expectG = '[log]\n'
+ 'type = file\n\n'
+ '[log.level]\n'
+ 'label = debug\n'
+ 'value = 10\n'
+ 'type = file\n\n'
+ '[log.level]\n'
+ 'label = debug\n'
+ 'value = 10\n'

test("decode from file", function (t) {
var d = i.decode(data)
Expand All @@ -79,10 +82,10 @@ test("decode from file", function (t) {
})

test("encode from data", function (t) {
var e = i.encode(expectD)
var e = i.encode(i.decode(expectE), { isArray: true })
t.deepEqual(e, expectE)

var obj = {log: { type:'file', level: {label:'debug', value:10} } }
var obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
e = i.encode(obj)
t.notEqual(e.slice(0, 1), '\n', 'Never a blank first line')
t.notEqual(e.slice(-2), '\n\n', 'Never a blank final line')
Expand All @@ -93,7 +96,6 @@ test("encode from data", function (t) {
test("encode with option", function (t) {
var obj = {log: { type:'file', level: {label:'debug', value:10} } }
e = i.encode(obj, {section: 'prefix'})

t.equal(e, expectF)
t.end()
})
Expand Down