diff options
Diffstat (limited to 'node_modules/utile/test')
-rw-r--r-- | node_modules/utile/test/file-test.js | 31 | ||||
-rw-r--r-- | node_modules/utile/test/fixtures/read-json-file/config.json | 9 | ||||
-rw-r--r-- | node_modules/utile/test/fixtures/require-directory/directory/index.js | 2 | ||||
-rw-r--r-- | node_modules/utile/test/fixtures/require-directory/helloWorld.js | 2 | ||||
-rw-r--r-- | node_modules/utile/test/format-test.js | 31 | ||||
-rw-r--r-- | node_modules/utile/test/function-args-test.js | 104 | ||||
-rw-r--r-- | node_modules/utile/test/helpers/macros.js | 37 | ||||
-rw-r--r-- | node_modules/utile/test/random-string-test.js | 39 | ||||
-rw-r--r-- | node_modules/utile/test/require-directory-test.js | 35 | ||||
-rw-r--r-- | node_modules/utile/test/utile-test.js | 126 |
10 files changed, 416 insertions, 0 deletions
diff --git a/node_modules/utile/test/file-test.js b/node_modules/utile/test/file-test.js new file mode 100644 index 0000000..99b2217 --- /dev/null +++ b/node_modules/utile/test/file-test.js @@ -0,0 +1,31 @@ +/* + * file-test.js: Tests for `utile.file` module. + * + * (C) 2011, Charlie Robbins & the Contributors + * MIT LICENSE + * + */ + +var assert = require('assert'), + path = require('path'), + vows = require('vows'), + macros = require('./helpers/macros'), + utile = require('../'); + +var fixture = path.join(__dirname, 'fixtures', 'read-json-file', 'config.json'); + +vows.describe('utile/file').addBatch({ + 'When using utile': { + 'the `.file.readJson()` function': { + topic: function () { + utile.file.readJson(fixture, this.callback); + }, + 'should return correct JSON structure': macros.assertReadCorrectJson + }, + 'the `.file.readJsonSync()` function': { + topic: utile.file.readJsonSync(fixture), + 'should return correct JSON structure': macros.assertReadCorrectJson + } + } +}).export(module); + diff --git a/node_modules/utile/test/fixtures/read-json-file/config.json b/node_modules/utile/test/fixtures/read-json-file/config.json new file mode 100644 index 0000000..e12a106 --- /dev/null +++ b/node_modules/utile/test/fixtures/read-json-file/config.json @@ -0,0 +1,9 @@ +{ + "hello": "World", + "I am": ["the utile module"], + "thisMakesMe": { + "really": 1337, + "right?": true + } +} + diff --git a/node_modules/utile/test/fixtures/require-directory/directory/index.js b/node_modules/utile/test/fixtures/require-directory/directory/index.js new file mode 100644 index 0000000..1afb489 --- /dev/null +++ b/node_modules/utile/test/fixtures/require-directory/directory/index.js @@ -0,0 +1,2 @@ +exports.me = 'directory/index.js'; + diff --git a/node_modules/utile/test/fixtures/require-directory/helloWorld.js b/node_modules/utile/test/fixtures/require-directory/helloWorld.js new file mode 100644 index 0000000..1c842ec --- /dev/null +++ b/node_modules/utile/test/fixtures/require-directory/helloWorld.js @@ -0,0 +1,2 @@ +exports.me = 'helloWorld.js'; + diff --git a/node_modules/utile/test/format-test.js b/node_modules/utile/test/format-test.js new file mode 100644 index 0000000..0648f5a --- /dev/null +++ b/node_modules/utile/test/format-test.js @@ -0,0 +1,31 @@ +/* + * format-test.js: Tests for `utile.format` module. + * + * (C) 2011, Charlie Robbins & the Contributors + * MIT LICENSE + * + */ + +var vows = require('vows'), + assert = require('assert'), + utile = require('../lib'); + +vows.describe('utile/format').addBatch({ + + 'Should use the original `util.format` if there are no custom parameters to replace.': function() { + assert.equal(utile.format('%s %s %s', 'test', 'test2', 'test3'), 'test test2 test3'); + }, + + 'Should use `utile.format` if custom parameters are provided.': function() { + assert.equal(utile.format('%a %b %c', [ + '%a', + '%b', + '%c' + ], [ + 'test', + 'test2', + 'test3' + ]), 'test test2 test3'); + } + +}).export(module); diff --git a/node_modules/utile/test/function-args-test.js b/node_modules/utile/test/function-args-test.js new file mode 100644 index 0000000..e78c4b2 --- /dev/null +++ b/node_modules/utile/test/function-args-test.js @@ -0,0 +1,104 @@ +/* + * function-args-test.js: Tests for `args` method + * + * (C) 2011, Charlie Robbins & the Contributors + * MIT LICENSE + * + */ + +var assert = require('assert'), + path = require('path'), + vows = require('vows'), + macros = require('./helpers/macros'), + utile = require('../'); + +vows.describe('utile/args').addBatch({ + 'When using utile': { + 'the `args` function': { + topic: utile, + 'should be a function': function (_utile) { + assert.isFunction(_utile.args); + }, + } + }, + 'utile.rargs()': { + 'with no arguments': { + topic: utile.rargs(), + 'should return an empty object': function (result) { + assert.isArray(result); + assert.lengthOf(result, 0); + } + }, + 'with simple arguments': { + topic: function () { + return (function () { + return utile.rargs(arguments); + })('a', 'b', 'c'); + }, + 'should return an array with three items': function (result) { + assert.isArray(result); + assert.equal(3, result.length); + assert.equal(result[0], 'a'); + assert.equal(result[1], 'b'); + assert.equal(result[2], 'c'); + } + }, + 'with a simple slice': { + topic: function () { + return (function () { + return utile.rargs(arguments, 1); + })('a', 'b', 'c'); + }, + 'should return an array with three items': function (result) { + assert.isArray(result); + assert.equal(2, result.length); + assert.equal(result[0], 'b'); + assert.equal(result[1], 'c'); + } + } + }, + 'utile.args()': { + 'with no arguments': { + topic: utile.args(), + 'should return an empty Array': function (result) { + assert.isUndefined(result.callback); + assert.isArray(result); + assert.lengthOf(result, 0); + } + }, + 'with simple arguments': { + topic: function () { + return (function () { + return utile.args(arguments); + })('a', 'b', 'c', function () { + return 'ok'; + }); + }, + 'should return an array with three items': function (result) { + assert.isArray(result); + assert.equal(3, result.length); + assert.equal(result[0], 'a'); + assert.equal(result[1], 'b'); + assert.equal(result[2], 'c'); + + // + // Ensure that the Array returned + // by `utile.args()` enumerates correctly + // + var length = 0; + result.forEach(function (item) { + length++; + }); + + assert.equal(length, 3); + }, + 'should return lookup helpers': function (result) { + assert.isArray(result); + assert.equal(result.first, 'a'); + assert.equal(result.last, 'c'); + assert.isFunction(result.callback); + assert.isFunction(result.cb); + } + } + } +}).export(module); diff --git a/node_modules/utile/test/helpers/macros.js b/node_modules/utile/test/helpers/macros.js new file mode 100644 index 0000000..f86fcc6 --- /dev/null +++ b/node_modules/utile/test/helpers/macros.js @@ -0,0 +1,37 @@ +/* + * macros.js: Test macros for `utile` module. + * + * (C) 2011, Charlie Robbins & the Contributors + * MIT LICENSE + * + */ + +var assert = require('assert'), + utile = require('../../lib'); + +var macros = exports; + +macros.assertReadCorrectJson = function (obj) { + assert.isObject(obj); + utile.deepEqual(obj, { + hello: 'World', + 'I am': ['the utile module'], + thisMakesMe: { + really: 1337, + 'right?': true + } + }); +}; + +macros.assertDirectoryRequired = function (obj) { + assert.isObject(obj); + utile.deepEqual(obj, { + directory: { + me: 'directory/index.js' + }, + helloWorld: { + me: 'helloWorld.js' + } + }); +}; + diff --git a/node_modules/utile/test/random-string-test.js b/node_modules/utile/test/random-string-test.js new file mode 100644 index 0000000..84e9c8b --- /dev/null +++ b/node_modules/utile/test/random-string-test.js @@ -0,0 +1,39 @@ +/* + * common-test.js : testing common.js for expected functionality + * + * (C) 2011, Charlie Robbins & the Contributors + * + */ + +var assert = require('assert'), + vows = require('vows'), + utile = require('../lib'); + +vows.describe('utile/randomString').addBatch({ + "When using utile": { + "the randomString() function": { + topic: function () { + return utile.randomString(); + }, + "should return 16 characters that are actually random by default": function (random) { + assert.isString(random); + assert.lengthOf(random, 16); + assert.notEqual(random, utile.randomString()); + }, + "when you can asked for different length strings": { + topic: function () { + return [utile.randomString(4), utile.randomString(128)]; + }, + "where they actually are of length 4, 128": function (strings) { + assert.isArray(strings); + assert.lengthOf(strings,2); + assert.isString(strings[0]); + assert.isString(strings[1]); + assert.lengthOf(strings[0], 4); + assert.lengthOf(strings[1], 128); + assert.notEqual(strings[0], strings[1].substr(0,4)); + } + } + } + } +}).export(module); diff --git a/node_modules/utile/test/require-directory-test.js b/node_modules/utile/test/require-directory-test.js new file mode 100644 index 0000000..4664db8 --- /dev/null +++ b/node_modules/utile/test/require-directory-test.js @@ -0,0 +1,35 @@ +/* + * require-directory-test.js: Tests for `requireDir` and `requireDirLazy` + * methods. + * + * (C) 2011, Charlie Robbins & the Contributors + * MIT LICENSE + * + */ + +var assert = require('assert'), + path = require('path'), + vows = require('vows'), + macros = require('./helpers/macros'), + utile = require('../'); + +var requireFixtures = path.join(__dirname, 'fixtures', 'require-directory'); + +vows.describe('utile/require-directory').addBatch({ + 'When using utile': { + 'the `requireDir()` function': { + topic: utile.requireDir(requireFixtures), + 'should contain all wanted modules': macros.assertDirectoryRequired + }, + 'the `requireDirLazy()` function': { + topic: utile.requireDirLazy(requireFixtures), + 'all properties should be getters': function (obj) { + assert.isObject(obj); + assert.isTrue(!!Object.getOwnPropertyDescriptor(obj, 'directory').get); + assert.isTrue(!!Object.getOwnPropertyDescriptor(obj, 'helloWorld').get); + }, + 'should contain all wanted modules': macros.assertDirectoryRequired + } + } +}).export(module); + diff --git a/node_modules/utile/test/utile-test.js b/node_modules/utile/test/utile-test.js new file mode 100644 index 0000000..0cecc34 --- /dev/null +++ b/node_modules/utile/test/utile-test.js @@ -0,0 +1,126 @@ +/* + * utile-test.js: Tests for `utile` module. + * + * (C) 2011, Charlie Robbins & the Contributors + * MIT LICENSE + * + */ + +var assert = require('assert'), + vows = require('vows'), + utile = require('../lib'); + +var obj1, obj2; + +obj1 = { + foo: true, + bar: { + bar1: true, + bar2: 'bar2' + } +}; + +obj2 = { + baz: true, + buzz: 'buzz' +}; + +Object.defineProperties(obj2, { + + 'bazz': { + get: function() { + return 'bazz'; + }, + + set: function() { + return 'bazz'; + } + }, + + 'wat': { + set: function() { + return 'wat'; + } + } + +}); + +vows.describe('utile').addBatch({ + "When using utile": { + "it should have the same methods as the `util` module": function () { + Object.keys(require('util')).forEach(function (fn) { + assert.isFunction(utile[fn]); + }); + }, + "it should have the correct methods defined": function () { + assert.isFunction(utile.mixin); + assert.isFunction(utile.clone); + assert.isFunction(utile.rimraf); + assert.isFunction(utile.mkdirp); + assert.isFunction(utile.cpr); + }, + "the mixin() method": function () { + var mixed = utile.mixin({}, obj1, obj2); + assert.isTrue(mixed.foo); + assert.isObject(mixed.bar); + assert.isTrue(mixed.baz); + assert.isString(mixed.buzz); + assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').get); + assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').set); + assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'wat').set); + assert.isString(mixed.bazz); + }, + "the clone() method": function () { + var clone = utile.clone(obj1); + assert.isTrue(clone.foo); + assert.isObject(clone.bar); + assert.notStrictEqual(obj1, clone); + }, + "the createPath() method": function () { + var x = {}, + r = Math.random(); + + utile.createPath(x, ['a','b','c'], r) + assert.equal(x.a.b.c, r) + }, + "the capitalize() method": function () { + assert.isFunction(utile.capitalize); + assert.equal(utile.capitalize('bullet'), 'Bullet'); + assert.equal(utile.capitalize('bullet_train'), 'BulletTrain'); + }, + "the escapeRegExp() method": function () { + var ans = "\\/path\\/to\\/resource\\.html\\?search=query"; + assert.isFunction(utile.escapeRegExp); + assert.equal(utile.escapeRegExp('/path/to/resource.html?search=query'), ans); + }, + "the underscoreToCamel() method": function () { + var obj = utile.underscoreToCamel({ + key_with_underscore: { + andNested: 'values', + several: [1, 2, 3], + nested_underscores: true + }, + just_one: 'underscore' + }); + + assert.isObject(obj.keyWithUnderscore); + assert.isString(obj.justOne); + assert.isTrue(obj.keyWithUnderscore.nestedUnderscores); + }, + "the camelToUnderscore() method": function () { + var obj = utile.camelToUnderscore({ + keyWithCamel: { + andNested: 'values', + several: [1, 2, 3], + nestedCamel: true + }, + justOne: 'camel' + }); + + assert.isObject(obj.key_with_camel); + assert.isString(obj.just_one); + assert.isTrue(obj.key_with_camel.nested_camel); + } + } +}).export(module); + |