Skip to content

Commit

Permalink
move tests to test/
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Jun 30, 2015
1 parent 46c029f commit 4e2604b
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 164 deletions.
171 changes: 7 additions & 164 deletions test.js
Expand Up @@ -12,45 +12,9 @@
var test = require('assertit')
var is = require('./index')

var got = require('got')
var gotPromise = require('got-promise')
var gotHybrid = require('then-got')
var PluginError = require('plugin-error')

var generator = (function * () {yield 42})()
var generatorfn = function * () {yield 42}

test('is-kindof:', function () {
test('should return true when work as `kind-of` sugar - `is(val, type)`', function (done) {
test.equal(is(/regex/, 'regexp'), true)
test.equal(is({a: 'bcd'}, 'object'), true)
test.equal(is([1, 2, 3], 'array'), true)
test.equal(is(undefined, 'undefined'), true)
test.equal(is(function () {}, 'function'), true)
test.equal(is(generatorfn, 'generatorFunction'), true)
test.equal(is(generatorfn, 'generator function'), true)
test.equal(is(generatorfn, 'generator fn'), true)
test.equal(is(generatorfn, 'gen fn'), true)
test.equal(is(generatorfn, 'genfn'), true)
test.equal(is(generator, 'generator'), true)
test.equal(is(new Date(), 'date'), true)
test.equal(is(true, 'boolean'), true)
test.equal(is(123, 'number'), true)
test.equal(is(null, 'null'), true)
test.equal(is('foo', 'string'), true)
test.equal(is(new Set(), 'set'), true)
test.equal(is(new Map(), 'map'), true)
test.equal(is(new WeakSet(), 'weakset'), true)
test.equal(is(new WeakMap(), 'weakmap'), true)
test.equal(is(Symbol('foo'), 'symbol'), true)
test.equal(is(new Error('foo'), 'error'), true)
test.equal(is(new PluginError('foo', 'msg'), 'error'), true)
test.equal(is(new PluginError('foo', 'msg', {name: 'MyErr'}), 'error'), false)
test.equal(is(new TypeError('foo'), 'error'), true)
test.equal(is(new SyntaxError('foo'), 'error'), true)
test.equal(is(got('https://github.com'), 'stream'), true)
test.equal(is(gotHybrid('https://github.com'), 'hybrid'), true)
test.equal(is(gotPromise('https://github.com'), 'promise'), true)
require('./test/kind-of-sugar')
done()
})
test('should return false when `is(val, type)`', function (done) {
Expand All @@ -60,148 +24,27 @@ test('is-kindof:', function () {
done()
})
test('should be able `types` to be array - `is(val, [type, type, type])`', function (done) {
test.equal(is('foobar', ['string', 'array']), true)
test.equal(is([1, 2, 3], ['string', 'array']), true)
test.equal(is(12345, ['string', 'array']), false)
test.equal(is(null, ['string', 'array']), false)
test.equal(is(null, ['string', 'null']), true)
test.equal(is(null, ['string', 'undefined']), false)
test.equal(is(false, ['null', 'undefined']), false)
test.equal(is(undefined, ['string', 'array']), false)
test.equal(is(undefined, ['string', 'undefined']), true)
require('./test/array-types-support')
done()
})
test('should have static methods for all types - `is.method`', function (done) {
test.equal(typeof is.regexp, 'function')
test.equal(typeof is.object, 'function')
test.equal(typeof is.array, 'function')
test.equal(typeof is.undefined, 'function')
test.equal(typeof is.generator, 'function')
test.equal(typeof is.generator.fn, 'function')
test.equal(typeof is.generatorFn, 'function')
test.equal(typeof is.generatorFunction, 'function')
test.equal(typeof is.date, 'function')
test.equal(typeof is.boolean, 'function')
test.equal(typeof is.number, 'function')
test.equal(typeof is.null, 'function')
test.equal(typeof is.string, 'function')
test.equal(typeof is.set, 'function')
test.equal(typeof is.map, 'function')
test.equal(typeof is.weakset, 'function')
test.equal(typeof is.weakmap, 'function')
test.equal(typeof is.symbol, 'function')
test.equal(typeof is.error, 'function')
test.equal(typeof is.stream, 'function')
test.equal(typeof is.hybrid, 'function')
test.equal(typeof is.promise, 'function')
require('./test/static-methods')
done()
})
test('should have prototype methods for all types - `is().method`', function (done) {
test.equal(typeof is().regexp, 'function')
test.equal(typeof is().object, 'function')
test.equal(typeof is().array, 'function')
test.equal(typeof is().undefined, 'function')
test.equal(typeof is().generator, 'function')
test.equal(typeof is().generator.fn, 'function')
test.equal(typeof is().generatorFn, 'function')
test.equal(typeof is().generatorFunction, 'function')
test.equal(typeof is().date, 'function')
test.equal(typeof is().boolean, 'function')
test.equal(typeof is().number, 'function')
test.equal(typeof is().null, 'function')
test.equal(typeof is().string, 'function')
test.equal(typeof is().set, 'function')
test.equal(typeof is().map, 'function')
test.equal(typeof is().weakset, 'function')
test.equal(typeof is().weakmap, 'function')
test.equal(typeof is().symbol, 'function')
test.equal(typeof is().error, 'function')
test.equal(typeof is().stream, 'function')
test.equal(typeof is().hybrid, 'function')
test.equal(typeof is().promise, 'function')
require('./test/prototype-methods')
done()
})
test('should return true for `is(val).method()', function (done) {
test.equal(is(/regex/).regexp(), true)
test.equal(is({a: 'bcd'}).object(), true)
test.equal(is([1, 2, 3]).array(), true)
test.equal(is().undefined(), true)
test.equal(is(undefined).undefined(), true)
test.equal(is(generator).generator(), true)
test.equal(is(generatorfn).generatorFn(), true)
test.equal(is(generatorfn).generatorFunction(), true)
test.equal(is(new Date()).date(), true)
test.equal(is(true).boolean(), true)
test.equal(is(1234).number(), true)
test.equal(is(null).null(), true)
test.equal(is('foo').string(), true)
test.equal(is(new Set()).set(), true)
test.equal(is(new Map()).map(), true)
test.equal(is(new WeakSet()).weakset(), true)
test.equal(is(new WeakMap()).weakmap(), true)
test.equal(is(Symbol('foo')).symbol(), true)
test.equal(is(new Error('foo')).error(), true)
test.equal(is(new PluginError('foo', 'msg')).error(), true)
test.equal(is(new PluginError('foo', 'msg', {name: 'MyErr'})).error(), false)
test.equal(is(got('https://github.com')).stream(), true)
test.equal(is(gotHybrid('https://github.com')).hybrid(), true)
test.equal(is(gotPromise('https://github.com')).promise(), true)
require('./test/ctor-value-method')
done()
})
test('should return true for `is().method(val)', function (done) {
test.equal(is().regexp(/regex/), true)
test.equal(is().object({a: 'bcd'}), true)
test.equal(is().array([1, 2, 3]), true)
test.equal(is().undefined(), true)
test.equal(is().undefined(undefined), true)
test.equal(is().undefined(null), false)
test.equal(is().generator(generator), true)
test.equal(is().generatorFn(generatorfn), true)
test.equal(is().generatorFunction(generatorfn), true)
test.equal(is().date(new Date()), true)
test.equal(is().boolean(true), true)
test.equal(is().number(1234), true)
test.equal(is().null(null), true)
test.equal(is().string('foo'), true)
test.equal(is().set(new Set()), true)
test.equal(is().map(new Map()), true)
test.equal(is().weakset(new WeakSet()), true)
test.equal(is().weakmap(new WeakMap()), true)
test.equal(is().symbol(Symbol('foo')), true)
test.equal(is().error(new Error('foo')), true)
test.equal(is().error(new PluginError('foo', 'msg')), true)
test.equal(is().error(new PluginError('foo', 'msg', {name: 'MyErr'})), false)
test.equal(is().stream(got('https://github.com')), true)
test.equal(is().hybrid(gotHybrid('https://github.com')), true)
test.equal(is().promise(gotPromise('https://github.com')), true)
require('./test/ctor-method-value')
done()
})
test('should return true for `is.method(val)', function (done) {
test.equal(is.regexp(/regex/), true)
test.equal(is.object({a: 'bcd'}), true)
test.equal(is.array([1, 2, 3]), true)
test.equal(is.undefined(undefined), true)
test.equal(is.undefined(), false)
test.equal(is.undefined(null), false)
test.equal(is.generator(generator), true)
test.equal(is.generatorFn(generatorfn), true)
test.equal(is.generatorFunction(generatorfn), true)
test.equal(is.date(new Date()), true)
test.equal(is.boolean(true), true)
test.equal(is.number(1234), true)
test.equal(is.null(null), true)
test.equal(is.string('foo'), true)
test.equal(is.set(new Set()), true)
test.equal(is.map(new Map()), true)
test.equal(is.weakset(new WeakSet()), true)
test.equal(is.weakmap(new WeakMap()), true)
test.equal(is.symbol(Symbol('foo')), true)
test.equal(is.error(new Error('foo')), true)
test.equal(is.error(new PluginError('foo', 'msg')), true)
test.equal(is.error(new PluginError('foo', 'msg', {name: 'MyErr'})), false)
test.equal(is.stream(got('https://github.com')), true)
test.equal(is.hybrid(gotHybrid('https://github.com')), true)
test.equal(is.promise(gotPromise('https://github.com')), true)
require('./test/static-method-value')
done()
})
})
23 changes: 23 additions & 0 deletions test/array-types-support.js
@@ -0,0 +1,23 @@
/*!
* is-kindof <https://github.com/tunnckoCore/is-kindof>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

/* jshint asi:true */

'use strict'

var test = require('assertit')
var is = require('../index')

test.equal(is('foobar', ['string', 'array']), true)
test.equal(is([1, 2, 3], ['string', 'array']), true)
test.equal(is(12345, ['string', 'array']), false)
test.equal(is(null, ['string', 'array']), false)
test.equal(is(null, ['string', 'null']), true)
test.equal(is(null, ['string', 'undefined']), false)
test.equal(is(false, ['null', 'undefined']), false)
test.equal(is(undefined, ['string', 'array']), false)
test.equal(is(undefined, ['string', 'undefined']), true)
47 changes: 47 additions & 0 deletions test/ctor-method-value.js
@@ -0,0 +1,47 @@
/*!
* is-kindof <https://github.com/tunnckoCore/is-kindof>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

/* jshint asi:true */

'use strict'

var test = require('assertit')
var is = require('../index')

var got = require('got')
var gotPromise = require('got-promise')
var gotHybrid = require('then-got')
var PluginError = require('plugin-error')

var generator = (function * () {yield 42})()
var generatorfn = function * () {yield 42}

test.equal(is().regexp(/regex/), true)
test.equal(is().object({a: 'bcd'}), true)
test.equal(is().array([1, 2, 3]), true)
test.equal(is().undefined(), true)
test.equal(is().undefined(undefined), true)
test.equal(is().undefined(null), false)
test.equal(is().generator(generator), true)
test.equal(is().generatorFn(generatorfn), true)
test.equal(is().generatorFunction(generatorfn), true)
test.equal(is().date(new Date()), true)
test.equal(is().boolean(true), true)
test.equal(is().number(1234), true)
test.equal(is().null(null), true)
test.equal(is().string('foo'), true)
test.equal(is().set(new Set()), true)
test.equal(is().map(new Map()), true)
test.equal(is().weakset(new WeakSet()), true)
test.equal(is().weakmap(new WeakMap()), true)
test.equal(is().symbol(Symbol('foo')), true)
test.equal(is().error(new Error('foo')), true)
test.equal(is().error(new PluginError('foo', 'msg')), true)
test.equal(is().error(new PluginError('foo', 'msg', {name: 'MyErr'})), false)
test.equal(is().stream(got('https://github.com')), true)
test.equal(is().hybrid(gotHybrid('https://github.com')), true)
test.equal(is().promise(gotPromise('https://github.com')), true)
46 changes: 46 additions & 0 deletions test/ctor-value-method.js
@@ -0,0 +1,46 @@
/*!
* is-kindof <https://github.com/tunnckoCore/is-kindof>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

/* jshint asi:true */

'use strict'

var test = require('assertit')
var is = require('../index')

var got = require('got')
var gotPromise = require('got-promise')
var gotHybrid = require('then-got')
var PluginError = require('plugin-error')

var generator = (function * () {yield 42})()
var generatorfn = function * () {yield 42}

test.equal(is(/regex/).regexp(), true)
test.equal(is({a: 'bcd'}).object(), true)
test.equal(is([1, 2, 3]).array(), true)
test.equal(is().undefined(), true)
test.equal(is(undefined).undefined(), true)
test.equal(is(generator).generator(), true)
test.equal(is(generatorfn).generatorFn(), true)
test.equal(is(generatorfn).generatorFunction(), true)
test.equal(is(new Date()).date(), true)
test.equal(is(true).boolean(), true)
test.equal(is(1234).number(), true)
test.equal(is(null).null(), true)
test.equal(is('foo').string(), true)
test.equal(is(new Set()).set(), true)
test.equal(is(new Map()).map(), true)
test.equal(is(new WeakSet()).weakset(), true)
test.equal(is(new WeakMap()).weakmap(), true)
test.equal(is(Symbol('foo')).symbol(), true)
test.equal(is(new Error('foo')).error(), true)
test.equal(is(new PluginError('foo', 'msg')).error(), true)
test.equal(is(new PluginError('foo', 'msg', {name: 'MyErr'})).error(), false)
test.equal(is(got('https://github.com')).stream(), true)
test.equal(is(gotHybrid('https://github.com')).hybrid(), true)
test.equal(is(gotPromise('https://github.com')).promise(), true)
51 changes: 51 additions & 0 deletions test/kind-of-sugar.js
@@ -0,0 +1,51 @@
/*!
* is-kindof <https://github.com/tunnckoCore/is-kindof>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

/* jshint asi:true */

'use strict'

var test = require('assertit')
var is = require('../index')

var got = require('got')
var gotPromise = require('got-promise')
var gotHybrid = require('then-got')
var PluginError = require('plugin-error')

var generator = (function * () {yield 42})()
var generatorfn = function * () {yield 42}

test.equal(is(/regex/, 'regexp'), true)
test.equal(is({a: 'bcd'}, 'object'), true)
test.equal(is([1, 2, 3], 'array'), true)
test.equal(is(undefined, 'undefined'), true)
test.equal(is(function () {}, 'function'), true)
test.equal(is(generatorfn, 'generatorFunction'), true)
test.equal(is(generatorfn, 'generator function'), true)
test.equal(is(generatorfn, 'generator fn'), true)
test.equal(is(generatorfn, 'gen fn'), true)
test.equal(is(generatorfn, 'genfn'), true)
test.equal(is(generator, 'generator'), true)
test.equal(is(new Date(), 'date'), true)
test.equal(is(true, 'boolean'), true)
test.equal(is(123, 'number'), true)
test.equal(is(null, 'null'), true)
test.equal(is('foo', 'string'), true)
test.equal(is(new Set(), 'set'), true)
test.equal(is(new Map(), 'map'), true)
test.equal(is(new WeakSet(), 'weakset'), true)
test.equal(is(new WeakMap(), 'weakmap'), true)
test.equal(is(Symbol('foo'), 'symbol'), true)
test.equal(is(new Error('foo'), 'error'), true)
test.equal(is(new PluginError('foo', 'msg'), 'error'), true)
test.equal(is(new PluginError('foo', 'msg', {name: 'MyErr'}), 'error'), false)
test.equal(is(new TypeError('foo'), 'error'), true)
test.equal(is(new SyntaxError('foo'), 'error'), true)
test.equal(is(got('https://github.com'), 'stream'), true)
test.equal(is(gotHybrid('https://github.com'), 'hybrid'), true)
test.equal(is(gotPromise('https://github.com'), 'promise'), true)

0 comments on commit 4e2604b

Please sign in to comment.