-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* also move ini.js to lib in preparation for template-oss * also fix tests to work in windows
- Loading branch information
Showing
8 changed files
with
2,985 additions
and
2,722 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,113 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`test/foo.js TAP decode from file > must match snapshot 1`] = ` | ||
Null Object { | ||
" xa n p ": String( | ||
"\\r | ||
yoyoyo\\r\\r | ||
), | ||
"[disturbing]": "hey you never know", | ||
"a": Null Object { | ||
"[]": "a square?", | ||
"av": "a val", | ||
"b": Null Object { | ||
"c": Null Object { | ||
"e": "1", | ||
"j": "2", | ||
}, | ||
}, | ||
"cr": Array [ | ||
"four", | ||
"eight", | ||
], | ||
"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 with spaces": "b c", | ||
"ar": Array [ | ||
"one", | ||
"three", | ||
"this is included", | ||
], | ||
"br": "warm", | ||
"eq": "eq=eq", | ||
"o": "p", | ||
"s": "something", | ||
"s1": "\\"something'", | ||
"s2": "something else", | ||
"x.y.z": Null Object { | ||
"a.b.c": Null Object { | ||
"a.b.c": "abc", | ||
"nocomment": "this; this is not a comment", | ||
"noHashComment": "this# this is not a comment", | ||
}, | ||
"x.y.z": "xyz", | ||
}, | ||
"zr": Array [ | ||
"deedee", | ||
], | ||
} | ||
` | ||
|
||
exports[`test/foo.js TAP encode from data > must match snapshot 1`] = ` | ||
o=p | ||
a with spaces=b c | ||
" xa n p "="\\"\\r\\nyoyoyo\\r\\r\\n" | ||
"[disturbing]"=hey you never know | ||
s=something | ||
s1="something' | ||
s2=something else | ||
zr[]=deedee | ||
ar[]=one | ||
ar[]=three | ||
ar[]=this is included | ||
br=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 | ||
cr[]=eight | ||
[a.b.c] | ||
e=1 | ||
j=2 | ||
[x\\.y\\.z] | ||
x.y.z=xyz | ||
[x\\.y\\.z.a\\.b\\.c] | ||
a.b.c=abc | ||
nocomment=this\\; this is not a comment | ||
noHashComment=this\\# this is not a comment | ||
` | ||
|
||
exports[`test/foo.js TAP encode with option > must match snapshot 1`] = ` | ||
[prefix.log] | ||
type=file | ||
[prefix.log.level] | ||
label=debug | ||
value=10 | ||
` | ||
|
||
exports[`test/foo.js TAP encode with whitespace > must match snapshot 1`] = ` | ||
[log] | ||
type = file | ||
[log.level] | ||
label = debug | ||
value = 10 | ||
` |
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
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 |
---|---|---|
@@ -1,106 +1,46 @@ | ||
var i = require('../') | ||
var tap = require('tap') | ||
var test = tap.test | ||
var fs = require('fs') | ||
var path = require('path') | ||
var fixture = path.resolve(__dirname, './fixtures/foo.ini') | ||
var data = fs.readFileSync(fixture, 'utf8') | ||
var 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' | ||
var expectD = | ||
{ o: 'p', | ||
'a with spaces': 'b c', | ||
' xa n p ': '"\r\nyoyoyo\r\r\n', | ||
'[disturbing]': 'hey you never know', | ||
s: 'something', | ||
s1: '"something\'', | ||
s2: 'something else', | ||
zr: ['deedee'], | ||
ar: ['one', 'three', 'this is included'], | ||
br: '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' } } }, | ||
'x.y.z': { | ||
'x.y.z': 'xyz', | ||
'a.b.c': { | ||
'a.b.c': 'abc', | ||
nocomment: 'this; this is not a comment', | ||
noHashComment: 'this# this is not a comment', | ||
}, | ||
}, | ||
} | ||
var expectF = '[prefix.log]\n' | ||
+ 'type=file\n\n' | ||
+ '[prefix.log.level]\n' | ||
+ 'label=debug\n' | ||
+ 'value=10\n' | ||
var expectG = '[log]\n' | ||
+ 'type = file\n\n' | ||
+ '[log.level]\n' | ||
+ 'label = debug\n' | ||
+ 'value = 10\n' | ||
const i = require('../') | ||
const tap = require('tap') | ||
const test = tap.test | ||
const fs = require('fs') | ||
const path = require('path') | ||
const fixture = path.resolve(__dirname, './fixtures/foo.ini') | ||
const data = fs.readFileSync(fixture, 'utf8') | ||
|
||
tap.cleanSnapshot = s => s.replace(/\r\n/g, '\n') | ||
|
||
test('decode from file', function (t) { | ||
var d = i.decode(data) | ||
t.deepEqual(d, expectD) | ||
const d = i.decode(data) | ||
t.matchSnapshot(d) | ||
t.end() | ||
}) | ||
|
||
test('encode from data', function (t) { | ||
var e = i.encode(expectD) | ||
t.deepEqual(e, expectE) | ||
|
||
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') | ||
const d = i.decode(data) | ||
const e = i.encode(d) | ||
t.matchSnapshot(e) | ||
t.end() | ||
}) | ||
|
||
test('never a blank first or last line', function (t) { | ||
const obj = {log: { type: 'file', level: {label: 'debug', value: 10} } } | ||
const e = i.encode(obj) | ||
t.not(e.slice(0, 1), '\n', 'Never a blank first line') | ||
t.not(e.slice(-2), '\n\n', 'Never a blank final line') | ||
t.end() | ||
}) | ||
|
||
test('encode with option', function (t) { | ||
var obj = {log: { type: 'file', level: {label: 'debug', value: 10} } } | ||
var e = i.encode(obj, {section: 'prefix'}) | ||
const obj = {log: { type: 'file', level: {label: 'debug', value: 10} } } | ||
const e = i.encode(obj, {section: 'prefix'}) | ||
|
||
t.equal(e, expectF) | ||
t.matchSnapshot(e) | ||
t.end() | ||
}) | ||
|
||
test('encode with whitespace', function (t) { | ||
var obj = {log: { type: 'file', level: {label: 'debug', value: 10} } } | ||
var e = i.encode(obj, {whitespace: true}) | ||
const obj = {log: { type: 'file', level: {label: 'debug', value: 10} } } | ||
const e = i.encode(obj, {whitespace: true}) | ||
|
||
t.equal(e, expectG) | ||
t.matchSnapshot(e) | ||
t.end() | ||
}) |
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
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