mirror of
https://gitlab.silvrtree.co.uk/martind2000/md-utils.git
synced 2025-01-10 21:05:09 +00:00
0.0.3
Added tests
This commit is contained in:
parent
d7b028a786
commit
a6b91770ae
@ -1,3 +1,4 @@
|
|||||||
|
'uses strict';
|
||||||
/**
|
/**
|
||||||
* *
|
* *
|
||||||
* User: Martin Donnelly
|
* User: Martin Donnelly
|
||||||
@ -20,7 +21,7 @@ module.exports = {
|
|||||||
var rObj = {};
|
var rObj = {};
|
||||||
for (var item in source) {
|
for (var item in source) {
|
||||||
if (source.hasOwnProperty(item)) {
|
if (source.hasOwnProperty(item)) {
|
||||||
let newName = item.replace('_', '-');
|
var newName = item.replace('_', '-');
|
||||||
rObj[newName] = source[item];
|
rObj[newName] = source[item];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,7 +31,7 @@ module.exports = {
|
|||||||
var rObj = {};
|
var rObj = {};
|
||||||
for (var item in source) {
|
for (var item in source) {
|
||||||
if (source.hasOwnProperty(item)) {
|
if (source.hasOwnProperty(item)) {
|
||||||
let newName = item.replace('-', '_');
|
var newName = item.replace('-', '_');
|
||||||
rObj[newName] = source[item];
|
rObj[newName] = source[item];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
test/md-utils.js
Normal file
56
test/md-utils.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
var $U = require('../lib/md-utils');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var dashedObj = {
|
||||||
|
notdashed: 0,
|
||||||
|
'is-dashed': 1,
|
||||||
|
'also-dashed': 2
|
||||||
|
};
|
||||||
|
|
||||||
|
var notdashedObj = {
|
||||||
|
notdashed: 0,
|
||||||
|
isnotdashed: 1,
|
||||||
|
alsonotdashed: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
var underScoredObj = {
|
||||||
|
notdashed: 0,
|
||||||
|
is_dashed: 1,
|
||||||
|
also_dashed: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('unDashObject', function() {
|
||||||
|
it('converts an object with dashes to underscores ', function(done) {
|
||||||
|
|
||||||
|
var updateData = $U.unDashObject(dashedObj);
|
||||||
|
|
||||||
|
assert.deepEqual(updateData, underScoredObj);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts an object with no dashes correctly', function(done) {
|
||||||
|
|
||||||
|
var updateData = $U.unDashObject(notdashedObj);
|
||||||
|
|
||||||
|
assert.deepEqual(updateData, notdashedObj);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('reDashObject', function() {
|
||||||
|
it('converts an object with underscores to dashes ', function(done) {
|
||||||
|
|
||||||
|
var updateData = $U.reDashObject(underScoredObj);
|
||||||
|
|
||||||
|
assert.deepEqual(updateData, dashedObj);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts an object with no underscores correctly', function(done) {
|
||||||
|
|
||||||
|
var updateData = $U.reDashObject(notdashedObj);
|
||||||
|
|
||||||
|
assert.deepEqual(updateData, notdashedObj);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user