Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) |