Skip to content

Commit

Permalink
import reader tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Feb 21, 2016
1 parent e833af7 commit 9618afb
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 0 deletions.
1 change: 1 addition & 0 deletions run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if (process.argv[2]) {
else {
reporter.run([
'test',
'test/readers',
], undefined, function (err) {
process.exit(((err) ? 1 : 0));
});
Expand Down
42 changes: 42 additions & 0 deletions test/readers/binary.js
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();
},
};
47 changes: 47 additions & 0 deletions test/readers/flat.js
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();
},
};
138 changes: 138 additions & 0 deletions test/readers/ini.js
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();
},
};
40 changes: 40 additions & 0 deletions test/readers/json.js
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();
},
};
41 changes: 41 additions & 0 deletions test/readers/yaml.js
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();
},
};

0 comments on commit 9618afb

Please sign in to comment.