|
# Some unit tests written for mocha and should.js. |
|
# $ mocha spec.coffee --compilers coffee:coffee-script |
|
|
|
should = require 'should' |
|
type = require('./type.js').type |
|
|
|
describe 'type', -> |
|
it 'should return a string when directly called', -> |
|
type('string').should.be.a 'string' |
|
|
|
it 'should match booleans correctly', -> |
|
[true, false, new Boolean].forEach (value) -> |
|
type(value).should.equal('boolean') |
|
type.isBoolean(value).should.be.true |
|
|
|
it 'should match strings correctly', -> |
|
['string', new String].forEach (value) -> |
|
type(value).should.equal('string') |
|
type.isString(value).should.be.true |
|
|
|
it 'should match numbers correctly', -> |
|
[42, new Number].forEach (value) -> |
|
type(value).should.equal('number') |
|
type.isNumber(value).should.be.true |
|
|
|
it 'should match numeric values correctly', -> |
|
type.isNumeric(value).should.be.true for value in [42, 42.5, '42', '42.5', '-42', '42e5', '0xff'] |
|
type.isNumeric(value).should.be.false for value in [Infinity] |
|
|
|
it 'should match regular expressions correctly', -> |
|
[/regexp/, new RegExp].forEach (value) -> |
|
type(value).should.equal('regexp') |
|
type.isRegExp(value).should.be.true |
|
|
|
it 'should match functions correctly', -> |
|
[new Function, ->].forEach (value) -> |
|
type(value).should.equal('function') |
|
type.isFunction(value).should.be.true |
|
|
|
it 'should match arrays correctly', -> |
|
[[], new Array].forEach (value) -> |
|
type(value).should.equal('array') |
|
type.isArray(value).should.be.true |
|
|
|
it 'should match plain objects correctly', -> |
|
[{}, new Object].forEach (value) -> |
|
type(value).should.equal('object') |
|
type.isPlainObj(value).should.be.true |