Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
Added testcases for the examples in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed May 3, 2015
1 parent c201740 commit 45633a7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Handles a string (file path), function, or object source and returns an object.
</table>
When passing a string, it is assumed it is the path to a file. When not absolute, the path will be used relative from `process.cwd()`.
A function will be executed and it's result will be used. This result can be one of the accepted values, `string`, `function` or `object`.
Objects are just returned the same as it came in.
Objects are just returned the same as they came in.


### confirge.read(file)
Expand Down
71 changes: 58 additions & 13 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getFixtureFile($file, $relative)

//------------------------------------------------------------------------------

describe('Confirge()', function()
describe('Confirge()', function confirgeTests()
{
it('should return the exact same object', function()
{
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Confirge()', function()
});
});

describe('Confirge.read()', function()
describe('Confirge.read()', function confirgeReadTests()
{
it('should read the yaml file and return an object', function()
{
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('Confirge.read()', function()
});
});

describe('Confirge.replace()', function()
describe('Confirge.replace()', function confirgeReplaceTests()
{
it('should replace a string var', function()
{
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('Confirge.replace()', function()
});
});

describe('Confirge.extend()', function()
describe('Confirge.extend()', function confirgeExtendTests()
{
// remove prototype added by Utils.replaceHandleObject() testcase
// otherwise, it will cause this test to fail
Expand Down Expand Up @@ -301,15 +301,15 @@ describe('Confirge.extend()', function()

//------------------------------------------------------------------------------

describe('Utils.noop()', function()
describe('Utils.noop()', function utilsNoopTests()
{
it('is only here to get 100% code coverage :P', function()
{
Assert.equal(Utils.noop(), null);
});
});

describe('Utils.findReplacements()', function()
describe('Utils.findReplacements()', function utilsFindReplacementsTests()
{
it('found replacement [1]', function()
{
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('Utils.findReplacements()', function()
});
});

describe('Utils.prepareVar()', function()
describe('Utils.prepareVar()', function utilsPrepareVarTests()
{
it('should return an object with regexp and replace value', function()
{
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('Utils.prepareVar()', function()
});
});

describe('Utils.prepareVars()', function()
describe('Utils.prepareVars()', function utilsPrepareVarsTests()
{
it('it should flatten a multilevel vars object', function()
{
Expand All @@ -428,7 +428,7 @@ describe('Utils.prepareVars()', function()
});
});

describe('Utils.prepareHandleVars()', function()
describe('Utils.prepareHandleVars()', function utilsPrepareHandleVarsTests()
{
it('should return an object with regexp and replace value [1]', function()
{
Expand Down Expand Up @@ -523,7 +523,7 @@ describe('Utils.prepareHandleVars()', function()
});
});

describe('Utils.replaceVars()', function()
describe('Utils.replaceVars()', function utilsReplaceVarsTests()
{
it('should replace the var [1]', function()
{
Expand Down Expand Up @@ -602,7 +602,7 @@ describe('Utils.replaceVars()', function()
});
});

describe('Utils.replaceHandleItem()', function()
describe('Utils.replaceHandleItem()', function utilsReplaceHandleItemTests()
{
it('should replace the var and return a string', function()
{
Expand Down Expand Up @@ -663,7 +663,7 @@ describe('Utils.replaceHandleItem()', function()
});
});

describe('Utils.replaceHandleArray()', function()
describe('Utils.replaceHandleArray()', function utilsReplaceHandleArrayTests()
{
it('should handle the array', function()
{
Expand All @@ -678,7 +678,7 @@ describe('Utils.replaceHandleArray()', function()
});
});

describe('Utils.replaceHandleObject()', function()
describe('Utils.replaceHandleObject()', function utilsReplaceHandleObjectTests()
{
it('should handle the object', function()
{
Expand Down Expand Up @@ -716,3 +716,48 @@ describe('Utils.replaceHandleObject()', function()
});
});
});

describe('readme examples', function readmeExamples()
{
it('should succeed the `How to use` example', function()
{
// extend objects
var $config = Confirge.extend({},
{
'example': '%var1% and %var2%'
});

// will replace vars inside the config obj, eg. %var1%, %var2%
// this will result in { 'example': 'value1 and value2' }
$config = Confirge.replace($config,
{
'var1': 'value1',
'var2': 'value2'
});

Assert.deepEqual($config, { 'example': 'value1 and value2' });
});

it('should succeed the `confirge.replace API` example', function()
{
var $source =
{
'config-option': '%some-var%',
'other-option': true,
'supported-types': ['object', '%types.a%']
};

var $vars =
{
'some-var': 'some-value', // %some-var%
'types': { 'a': 'array' } // %types.a%
};

Assert.deepEqual(Confirge.replace($source, $vars),
{
'config-option': 'some-value',
'other-option': true,
'supported-types': ['object', 'array']
});
});
});

0 comments on commit 45633a7

Please sign in to comment.