-
Notifications
You must be signed in to change notification settings - Fork 13
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
6 changed files
with
309 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
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,42 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
|
||
var _set_up = function (done) { | ||
this.bin = require('../../readers/binary'); | ||
done(); | ||
}; | ||
|
||
exports.load = { | ||
setUp : _set_up, | ||
'module is required' : function (test) { | ||
test.expect(1); | ||
test.ok(this.bin); | ||
test.done(); | ||
}, | ||
'has a load function': function(test) { | ||
test.expect(1); | ||
test.ok(typeof this.bin.load === 'function'); | ||
test.done(); | ||
}, | ||
'throws when file is non-existent': function(test) { | ||
test.expect(2); | ||
try { | ||
this.bin.load('test/config/non-existent.bin'); | ||
} | ||
catch (e) { | ||
test.equal(e.code, 'ENOENT'); | ||
test.ok(/no such file or dir/.test(e.message)); | ||
} | ||
test.done(); | ||
}, | ||
'loads the test binary file': function(test) { | ||
test.expect(3); | ||
var testBin = 'test/config/test.binary'; | ||
var result = this.bin.load(testBin); | ||
test.ok(Buffer.isBuffer(result)); | ||
test.equal(result.length, 120); | ||
test.deepEqual(result, fs.readFileSync(testBin)); | ||
test.done(); | ||
}, | ||
}; |
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,47 @@ | ||
'use strict'; | ||
|
||
var regex = require('../../configfile').regex; | ||
|
||
var _set_up = function (done) { | ||
this.flat = require('../../readers/flat'); | ||
done(); | ||
}; | ||
|
||
exports.load = { | ||
setUp: _set_up, | ||
'module is required' : function (test) { | ||
test.expect(1); | ||
test.ok(this.flat); | ||
test.done(); | ||
}, | ||
'has a load function': function(test) { | ||
test.expect(1); | ||
test.ok(typeof this.flat.load === 'function'); | ||
test.done(); | ||
}, | ||
'throws when file is non-existent': function(test) { | ||
test.expect(2); | ||
try { | ||
this.flat.load('test/config/non-existent.flat'); | ||
} | ||
catch (e) { | ||
test.equal(e.code, 'ENOENT'); | ||
test.ok(/no such file or dir/.test(e.message)); | ||
} | ||
test.done(); | ||
}, | ||
'loads the test flat file, as list': function(test) { | ||
test.expect(1); | ||
var result = this.flat.load( | ||
'test/config/test.flat', 'list', null, regex); | ||
test.deepEqual(result, [ 'line1', 'line2', 'line3', 'line5' ]); | ||
test.done(); | ||
}, | ||
'loads the test flat file, unspecified type': function(test) { | ||
test.expect(1); | ||
var result = this.flat.load( | ||
'test/config/test.flat', null, null, regex); | ||
test.deepEqual(result, 'line1'); | ||
test.done(); | ||
}, | ||
}; |
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,138 @@ | ||
'use strict'; | ||
|
||
var regex = require('../../configfile').regex; | ||
|
||
var _set_up = function (done) { | ||
this.ini = require('../../readers/ini'); | ||
this.opts = { booleans: ['main.bool_true','main.bool_false'] }; | ||
done(); | ||
}; | ||
|
||
exports.load = { | ||
setUp: _set_up, | ||
'module is required' : function (test) { | ||
test.expect(1); | ||
test.ok(this.ini); | ||
test.done(); | ||
}, | ||
'has a load function': function(test) { | ||
test.expect(1); | ||
test.ok(typeof this.ini.load === 'function'); | ||
test.done(); | ||
}, | ||
'loads the test ini file': function(test) { | ||
test.expect(1); | ||
var result = this.ini.load('test/config/test.ini', {}, regex); | ||
// console.log(result); | ||
test.deepEqual(result.main, | ||
{ bool_true: 'true', bool_false: 'false', | ||
str_true: 'true', str_false: 'false' | ||
} | ||
); | ||
test.done(); | ||
}, | ||
'test.ini, no opts' : function (test) { | ||
test.expect(4); | ||
var r = this.ini.load('test/config/test.ini', {}, regex); | ||
test.strictEqual(r.main.bool_true, 'true'); | ||
test.strictEqual(r.main.bool_false, 'false'); | ||
test.strictEqual(r.main.str_true, 'true'); | ||
test.strictEqual(r.main.str_false, 'false'); | ||
test.done(); | ||
}, | ||
'test.ini, opts' : function (test) { | ||
test.expect(4); | ||
var r = this.ini.load('test/config/test.ini', this.opts, regex).main; | ||
test.strictEqual(r.bool_true, true); | ||
test.strictEqual(r.bool_false, false); | ||
test.strictEqual(r.str_true, 'true'); | ||
test.strictEqual(r.str_false, 'false'); | ||
test.done(); | ||
}, | ||
'test.ini, sect1, opts' : function (test) { | ||
test.expect(4); | ||
var r = this.ini.load('test/config/test.ini', { | ||
booleans: ['sect1.bool_true','sect1.bool_false'] | ||
}, regex); | ||
test.strictEqual(r.sect1.bool_true, true); | ||
test.strictEqual(r.sect1.bool_false, false); | ||
test.strictEqual(r.sect1.str_true, 'true'); | ||
test.strictEqual(r.sect1.str_false, 'false'); | ||
test.done(); | ||
}, | ||
'test.ini, sect1, opts, w/defaults' : function (test) { | ||
test.expect(6); | ||
var r = this.ini.load('test/config/test.ini', { | ||
booleans: ['+sect1.bool_true','-sect1.bool_false', | ||
'+sect1.bool_true_default', 'sect1.-bool_false_default'] | ||
}, regex); | ||
test.strictEqual(r.sect1.bool_true, true); | ||
test.strictEqual(r.sect1.bool_false, false); | ||
test.strictEqual(r.sect1.str_true, 'true'); | ||
test.strictEqual(r.sect1.str_false, 'false'); | ||
test.strictEqual(r.sect1.bool_true_default, true); | ||
test.strictEqual(r.sect1.bool_false_default, false); | ||
test.done(); | ||
}, | ||
}; | ||
|
||
exports.empty = { | ||
setUp: _set_up, | ||
'non-exist.ini is template' : function (test) { | ||
test.expect(1); | ||
test.deepEqual(this.ini.empty(), { main: { } } ); | ||
test.done(); | ||
}, | ||
'non-exist.ini boolean' : function (test) { | ||
test.expect(1); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['reject']}), | ||
{ main: { reject: false } } | ||
); | ||
test.done(); | ||
}, | ||
'non-exist.ini boolean true default' : function (test) { | ||
test.expect(3); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['+reject']}), | ||
{ main: { reject: true } } | ||
); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['+main.reject']}), | ||
{ main: { reject: true } } | ||
); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['main.+reject']}), | ||
{ main: { reject: true } } | ||
); | ||
test.done(); | ||
}, | ||
'non-exist.ini boolean false default' : function (test) { | ||
test.expect(3); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['-reject']}), | ||
{ main: { reject: false } } | ||
); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['-main.reject']}), | ||
{ main: { reject: false } } | ||
); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['main.-reject']}), | ||
{ main: { reject: false } } | ||
); | ||
test.done(); | ||
}, | ||
'non-exist.ini boolean false default, section' : function (test) { | ||
test.expect(2); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['-reject.boolf']}), | ||
{ main: { }, reject: {boolf: false} } | ||
); | ||
test.deepEqual( | ||
this.ini.empty({ booleans: ['+reject.boolt']}), | ||
{ main: { }, reject: {boolt: true} } | ||
); | ||
test.done(); | ||
}, | ||
}; |
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 @@ | ||
'use strict'; | ||
|
||
var _set_up = function (done) { | ||
this.json = require('../../readers/json'); | ||
done(); | ||
}; | ||
|
||
exports.load = { | ||
setUp : _set_up, | ||
'module is required' : function (test) { | ||
test.expect(1); | ||
test.ok(this.json); | ||
test.done(); | ||
}, | ||
'has a load function': function(test) { | ||
test.expect(1); | ||
test.ok(typeof this.json.load === 'function'); | ||
test.done(); | ||
}, | ||
'throws when file is non-existent': function(test) { | ||
test.expect(2); | ||
try { | ||
this.json.load('test/config/non-existent.json'); | ||
} | ||
catch (e) { | ||
test.equal(e.code, 'ENOENT'); | ||
test.ok(/no such file or dir/.test(e.message)); | ||
} | ||
test.done(); | ||
}, | ||
'loads the test JSON file': function(test) { | ||
test.expect(3); | ||
var result = this.json.load('test/config/test.json'); | ||
// console.log(result); | ||
test.equal(result.matt, 'waz here'); | ||
test.ok(result.array.length); | ||
test.ok(result.objecty['has a property']); | ||
test.done(); | ||
}, | ||
}; |
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,41 @@ | ||
'use strict'; | ||
|
||
var _set_up = function (done) { | ||
this.yaml = require('../../readers/yaml'); | ||
done(); | ||
}; | ||
|
||
exports.load = { | ||
setUp : _set_up, | ||
'module is required' : function (test) { | ||
test.expect(1); | ||
test.ok(this.yaml); | ||
test.done(); | ||
}, | ||
'has a load function': function(test) { | ||
test.expect(1); | ||
test.ok(typeof this.yaml.load === 'function'); | ||
test.done(); | ||
}, | ||
'throws when file is non-existent': function(test) { | ||
test.expect(2); | ||
try { | ||
this.yaml.load('test/config/non-existent.haml'); | ||
} | ||
catch (e) { | ||
test.equal(e.code, 'ENOENT'); | ||
test.ok(/no such file or dir/.test(e.message)); | ||
} | ||
test.done(); | ||
}, | ||
'loads the test yaml file': function(test) { | ||
test.expect(4); | ||
var result = this.yaml.load('test/config/test.yaml'); | ||
// console.log(result); | ||
test.strictEqual(result.main.bool_true, true); | ||
test.equal(result.matt, 'waz here'); | ||
test.ok(result.array.length); | ||
test.ok(result.objecty['has a property']); | ||
test.done(); | ||
}, | ||
}; |