fixed white spacing and added (embarrassing absent) variable declarations

This commit is contained in:
midknight41 2013-10-26 20:40:12 +01:00
parent ccd609c1c3
commit 6c1eb5e917
2 changed files with 49 additions and 49 deletions

View file

@ -97,11 +97,11 @@ File.prototype.load = function (callback) {
} }
try { try {
//deals with string that include BOM //deals with string that include BOM
stringData = data.toString(); var stringData = data.toString();
if (stringData.charAt(0) === '\uFEFF') stringData = stringData.substr(1); if (stringData.charAt(0) === '\uFEFF') stringData = stringData.substr(1);
self.store = self.format.parse(stringData); self.store = self.format.parse(stringData);
} }
catch (ex) { catch (ex) {
@ -130,12 +130,12 @@ File.prototype.loadSync = function () {
// Else, the path exists, read it from disk // Else, the path exists, read it from disk
// //
try { try {
//deals with file that include BOM //deals with file that include BOM
fileData = fs.readFileSync(this.file, 'utf8'); var fileData = fs.readFileSync(this.file, 'utf8');
if (fileData.charAt(0) === '\uFEFF') fileData = fileData.substr(1); if (fileData.charAt(0) === '\uFEFF') fileData = fileData.substr(1);
data = this.format.parse(fileData); data = this.format.parse(fileData);
this.store = data; this.store = data;
} }
catch (ex) { catch (ex) {
throw new Error("Error parsing your JSON configuration file: [" + self.file + '].'); throw new Error("Error parsing your JSON configuration file: [" + self.file + '].');

View file

@ -49,54 +49,54 @@ vows.describe('nconf/stores/file').addBatch({
} }
}, },
"with a valid UTF8 JSON file that contains a BOM": { "with a valid UTF8 JSON file that contains a BOM": {
topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'bom.json');
this.store = store = new nconf.File({ file: filePath });
return null;
},
"the load() method": {
topic: function () { topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'bom.json'); this.store.load(this.callback);
this.store = store = new nconf.File({ file: filePath });
return null;
}, },
"the load() method": { "should load the data correctly": function (err, data) {
topic: function () { assert.isNull(err);
this.store.load(this.callback); assert.deepEqual(data, this.store.store);
},
"should load the data correctly": function (err, data) {
assert.isNull(err);
assert.deepEqual(data, this.store.store);
}
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
} }
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
}
}, },
"with a valid UTF8 JSON file that contains no BOM": { "with a valid UTF8 JSON file that contains no BOM": {
topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'no-bom.json');
this.store = store = new nconf.File({ file: filePath });
return null;
},
"the load() method": {
topic: function () { topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'no-bom.json'); this.store.load(this.callback);
this.store = store = new nconf.File({ file: filePath });
return null;
}, },
"the load() method": { "should load the data correctly": function (err, data) {
topic: function () { assert.isNull(err);
this.store.load(this.callback); assert.deepEqual(data, this.store.store);
},
"should load the data correctly": function (err, data) {
assert.isNull(err);
assert.deepEqual(data, this.store.store)
}
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
} }
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
}
} }
} }
}).addBatch({ }).addBatch({