Skip to content

Commit

Permalink
the test
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 7, 2011
1 parent 415442d commit 4e803f1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/fixtures/foo.ini
@@ -0,0 +1,18 @@
o = p

a with spaces = b c

; wrap in quotes to JSON-decode and preserve spaces
" xa n p " = "\"\r\nyoyoyo\r\r\n"
; a section
[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" } } } }"
; nested child without middle parent
; should create otherwise-empty a.b
[a.b.c]
e = 1
j = 2
40 changes: 40 additions & 0 deletions test/foo.js
@@ -0,0 +1,40 @@
var i = require("../")
, tap = require("tap")
, test = tap.test
, fs = require("fs")
, path = require("path")
, fixture = path.resolve(__dirname, "./fixtures/foo.ini")
, 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'
+ '[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.b.c]\ne = 1\nj = 2\n'
, expectD =
{ o: 'p',
'a with spaces': 'b c',
" xa n p ":'"\r\nyoyoyo\r\r\n',
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" } } } }"',
b: { c: { e: '1', j: '2' } } }
}

test("decode from file", function (t) {
d = i.decode(data)
t.deepEqual(d, expectD)
t.end()
})

test("encode from data", function (t) {
e = i.encode(expectD)
t.deepEqual(e, expectE)
t.end()
})

0 comments on commit 4e803f1

Please sign in to comment.