2011-12-18 12:31:58 +00:00
|
|
|
!function (name, definition) {
|
|
|
|
if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
|
|
|
|
else this[name] = definition();
|
|
|
|
}('chai', function () {
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
// CommonJS require()
|
|
|
|
|
|
|
|
function require(p){
|
|
|
|
var path = require.resolve(p)
|
|
|
|
, mod = require.modules[path];
|
|
|
|
if (!mod) throw new Error('failed to require "' + p + '"');
|
|
|
|
if (!mod.exports) {
|
|
|
|
mod.exports = {};
|
|
|
|
mod.call(mod.exports, mod, mod.exports, require.relative(path));
|
|
|
|
}
|
|
|
|
return mod.exports;
|
|
|
|
}
|
|
|
|
|
|
|
|
require.modules = {};
|
|
|
|
|
|
|
|
require.resolve = function (path){
|
|
|
|
var orig = path
|
|
|
|
, reg = path + '.js'
|
|
|
|
, index = path + '/index.js';
|
|
|
|
return require.modules[reg] && reg
|
|
|
|
|| require.modules[index] && index
|
|
|
|
|| orig;
|
|
|
|
};
|
|
|
|
|
|
|
|
require.register = function (path, fn){
|
|
|
|
require.modules[path] = fn;
|
|
|
|
};
|
|
|
|
|
|
|
|
require.relative = function (parent) {
|
|
|
|
return function(p){
|
|
|
|
if ('.' != p[0]) return require(p);
|
|
|
|
|
|
|
|
var path = parent.split('/')
|
|
|
|
, segs = p.split('/');
|
|
|
|
path.pop();
|
|
|
|
|
|
|
|
for (var i = 0; i < segs.length; i++) {
|
|
|
|
var seg = segs[i];
|
|
|
|
if ('..' == seg) path.pop();
|
|
|
|
else if ('.' != seg) path.push(seg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return require(path.join('/'));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
require.register("assertion.js", function(module, exports, require){
|
2011-12-15 13:02:26 +00:00
|
|
|
/*!
|
|
|
|
* chai
|
|
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*
|
|
|
|
* Primarily a refactor of: should.js
|
|
|
|
* https://github.com/visionmedia/should.js
|
|
|
|
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-16 11:14:47 +00:00
|
|
|
/**
|
|
|
|
* ### BDD Style Introduction
|
|
|
|
*
|
|
|
|
* The BDD style is exposed through `expect` or `should` interfaces. In both
|
|
|
|
* scenarios, you chain together natural language assertions.
|
|
|
|
*
|
|
|
|
* // expect
|
|
|
|
* var expect = require('chai').expect;
|
|
|
|
* expect(foo).to.equal('bar');
|
|
|
|
*
|
|
|
|
* // should
|
|
|
|
* var should = require('chai').should();
|
|
|
|
* foo.should.equal('bar');
|
|
|
|
*
|
|
|
|
* #### Differences
|
|
|
|
*
|
|
|
|
* The `expect` interface provides a function as a starting point for chaining
|
|
|
|
* your language assertions. It works on both node.js and in the browser.
|
|
|
|
*
|
|
|
|
* The `should` interface extends `Object.prototype` to provide a single getter as
|
|
|
|
* the starting point for your language assertions. Most browser don't like
|
|
|
|
* extensions to `Object.prototype` so it is not recommended for browser use.
|
|
|
|
*/
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/*!
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
|
2011-12-14 20:58:24 +00:00
|
|
|
var AssertionError = require('./error')
|
2011-12-15 12:07:27 +00:00
|
|
|
, eql = require('./utils/eql')
|
2011-12-18 12:02:18 +00:00
|
|
|
, inspect = require('./utils/inspect')
|
|
|
|
, statusCodes = require('./utils/constants').STATUS_CODES;
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/*!
|
|
|
|
* Module export.
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
module.exports = Assertion;
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/*!
|
|
|
|
* # Assertion Constructor
|
|
|
|
*
|
|
|
|
* Creates object for chaining.
|
|
|
|
*
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
2011-12-18 14:04:51 +00:00
|
|
|
function Assertion (obj, msg, stack) {
|
|
|
|
this.ssfi = stack || arguments.callee;
|
2011-12-07 06:10:58 +00:00
|
|
|
this.obj = obj;
|
|
|
|
this.msg = msg;
|
|
|
|
}
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/*!
|
|
|
|
* # .assert(expression, message, negateMessage)
|
|
|
|
*
|
2011-12-18 14:04:51 +00:00
|
|
|
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* @name assert
|
|
|
|
* @param {Philosophical} expression to be tested
|
|
|
|
* @param {String} message to display if fails
|
|
|
|
* @param {String} negatedMessage to display if negated expression fails
|
|
|
|
* @api privage
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.assert = function (expr, msg, negateMsg) {
|
2011-12-18 14:04:51 +00:00
|
|
|
var msg = (this.negate ? negateMsg : msg)
|
2011-12-07 06:10:58 +00:00
|
|
|
, ok = this.negate ? !expr : expr;
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
throw new AssertionError({
|
2011-12-18 14:04:51 +00:00
|
|
|
operator: this.msg,
|
2011-12-07 06:10:58 +00:00
|
|
|
message: msg,
|
2011-12-18 14:04:51 +00:00
|
|
|
stackStartFunction: this.ssfi
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/*!
|
2011-12-18 09:51:36 +00:00
|
|
|
* # inspect
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* Returns the current object stringified.
|
|
|
|
*
|
|
|
|
* @name inspect
|
|
|
|
* @api private
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'inspect',
|
|
|
|
{ get: function () {
|
|
|
|
return inspect(this.obj);
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # to
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name to
|
|
|
|
* @api public
|
|
|
|
*/
|
2011-12-15 13:02:26 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'to',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # be
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name be
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'be',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # an
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name an
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'an',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # is
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name is
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'is',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # and
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name and
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'and',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # have
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name have
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'have',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # with
|
|
|
|
*
|
|
|
|
* Language chain.
|
|
|
|
*
|
|
|
|
* @name with
|
|
|
|
* @api public
|
|
|
|
*/
|
2011-12-15 12:07:27 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'with',
|
|
|
|
{ get: function () {
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .not
|
|
|
|
*
|
|
|
|
* Negates any of assertions following in the chain.
|
|
|
|
*
|
|
|
|
* @name not
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'not',
|
|
|
|
{ get: function () {
|
|
|
|
this.negate = true;
|
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .ok
|
|
|
|
*
|
|
|
|
* Assert object truthiness.
|
|
|
|
*
|
|
|
|
* expect('everthing').to.be.ok;
|
|
|
|
* expect(false).to.not.be.ok;
|
|
|
|
* expect(undefined).to.not.be.ok;
|
|
|
|
* expect(null).to.not.be.ok;
|
|
|
|
*
|
|
|
|
* @name ok
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'ok',
|
|
|
|
{ get: function () {
|
|
|
|
this.assert(
|
|
|
|
this.obj
|
|
|
|
, 'expected ' + this.inspect + ' to be truthy'
|
|
|
|
, 'expected ' + this.inspect + ' to be falsey');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .true
|
|
|
|
*
|
|
|
|
* Assert object is true
|
|
|
|
*
|
|
|
|
* @name true
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'true',
|
|
|
|
{ get: function () {
|
|
|
|
this.assert(
|
|
|
|
true === this.obj
|
|
|
|
, 'expected ' + this.inspect + ' to be true'
|
|
|
|
, 'expected ' + this.inspect + ' to be false');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .false
|
|
|
|
*
|
|
|
|
* Assert object is false
|
|
|
|
*
|
|
|
|
* @name false
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'false',
|
|
|
|
{ get: function () {
|
|
|
|
this.assert(
|
|
|
|
false === this.obj
|
|
|
|
, 'expected ' + this.inspect + ' to be false'
|
|
|
|
, 'expected ' + this.inspect + ' to be true');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .exist
|
|
|
|
*
|
|
|
|
* Assert object exists (null).
|
|
|
|
*
|
|
|
|
* var foo = 'hi'
|
|
|
|
* , bar;
|
|
|
|
* expect(foo).to.exist;
|
|
|
|
* expect(bar).to.not.exist;
|
|
|
|
*
|
|
|
|
* @name exist
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'exist',
|
|
|
|
{ get: function () {
|
|
|
|
this.assert(
|
|
|
|
null != this.obj
|
|
|
|
, 'expected ' + this.inspect + ' to exist'
|
|
|
|
, 'expected ' + this.inspect + ' to not exist');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .empty
|
|
|
|
*
|
|
|
|
* Assert object's length to be 0.
|
|
|
|
*
|
|
|
|
* expect([]).to.be.empty;
|
|
|
|
*
|
|
|
|
* @name empty
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'empty',
|
|
|
|
{ get: function () {
|
|
|
|
new Assertion(this.obj).to.have.property('length');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
this.assert(
|
|
|
|
0 === this.obj.length
|
|
|
|
, 'expected ' + this.inspect + ' to be empty'
|
|
|
|
, 'expected ' + this.inspect + ' not to be empty');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
});
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .arguments
|
|
|
|
*
|
|
|
|
* Assert object is an instanceof arguments.
|
|
|
|
*
|
|
|
|
* function test () {
|
|
|
|
* expect(arguments).to.be.arguments;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @name arguments
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'arguments',
|
|
|
|
{ get: function () {
|
|
|
|
this.assert(
|
|
|
|
'[object Arguments]' == Object.prototype.toString.call(this.obj)
|
|
|
|
, 'expected ' + this.inspect + ' to be arguments'
|
|
|
|
, 'expected ' + this.inspect + ' to not be arguments');
|
2011-12-15 22:50:28 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-15 22:50:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # .equal(value)
|
|
|
|
*
|
|
|
|
* Assert strict equality.
|
|
|
|
*
|
|
|
|
* expect('hello').to.equal('hello');
|
|
|
|
*
|
|
|
|
* @name equal
|
|
|
|
* @param {*} value
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.equal = function (val) {
|
|
|
|
this.assert(
|
|
|
|
val === this.obj
|
|
|
|
, 'expected ' + this.inspect + ' to equal ' + inspect(val)
|
|
|
|
, 'expected ' + this.inspect + ' to not equal ' + inspect(val));
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .eql(value)
|
|
|
|
*
|
|
|
|
* Assert deep equality.
|
|
|
|
*
|
|
|
|
* expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
|
|
|
|
*
|
|
|
|
* @name eql
|
|
|
|
* @param {*} value
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 08:03:47 +00:00
|
|
|
Assertion.prototype.eql = function (obj) {
|
2011-12-14 20:58:24 +00:00
|
|
|
this.assert(
|
|
|
|
eql(obj, this.obj)
|
2011-12-15 12:07:27 +00:00
|
|
|
, 'expected ' + this.inspect + ' to equal ' + inspect(obj)
|
|
|
|
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj));
|
2011-12-07 08:03:47 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .above(value)
|
|
|
|
*
|
|
|
|
* Assert greater than `value`.
|
|
|
|
*
|
|
|
|
* expect(10).to.be.above(5);
|
|
|
|
*
|
|
|
|
* @name above
|
|
|
|
* @param {Number} value
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.above = function (val) {
|
|
|
|
this.assert(
|
|
|
|
this.obj > val
|
|
|
|
, 'expected ' + this.inspect + ' to be above ' + val
|
2011-12-15 12:07:27 +00:00
|
|
|
, 'expected ' + this.inspect + ' to be below ' + val);
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .below(value)
|
|
|
|
*
|
|
|
|
* Assert less than `value`.
|
|
|
|
*
|
|
|
|
* expect(5).to.be.below(10);
|
|
|
|
*
|
|
|
|
* @name below
|
|
|
|
* @param {Number} value
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.below = function (val) {
|
|
|
|
this.assert(
|
|
|
|
this.obj < val
|
|
|
|
, 'expected ' + this.inspect + ' to be below ' + val
|
|
|
|
, 'expected ' + this.inspect + ' to be above ' + val);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .within(start, finish)
|
|
|
|
*
|
|
|
|
* Assert that a number is within a range.
|
|
|
|
*
|
|
|
|
* expect(7).to.be.within(5,10);
|
|
|
|
*
|
|
|
|
* @name within
|
|
|
|
* @param {Number} start lowerbound inclusive
|
|
|
|
* @param {Number} finish upperbound inclusive
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Assertion.prototype.within = function (start, finish) {
|
|
|
|
var range = start + '..' + finish;
|
|
|
|
|
|
|
|
this.assert(
|
|
|
|
this.obj >= start && this.obj <= finish
|
|
|
|
, 'expected ' + this.inspect + ' to be within ' + range
|
|
|
|
, 'expected ' + this.inspect + ' to not be within ' + range);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # .a(type)
|
|
|
|
*
|
|
|
|
* Assert typeof.
|
|
|
|
*
|
|
|
|
* expect('test').to.be.a('string');
|
|
|
|
*
|
|
|
|
* @name a
|
|
|
|
* @param {String} type
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.a = function (type) {
|
|
|
|
this.assert(
|
|
|
|
type == typeof this.obj
|
|
|
|
, 'expected ' + this.inspect + ' to be a ' + type
|
2011-12-15 12:07:27 +00:00
|
|
|
, 'expected ' + this.inspect + ' not to be a ' + type);
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
2011-12-24 18:20:48 +00:00
|
|
|
* # .instanceof(constructor)
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* Assert instanceof.
|
|
|
|
*
|
2011-12-18 09:51:36 +00:00
|
|
|
* var Tea = function (name) { this.name = name; }
|
|
|
|
* , Chai = new Tea('chai');
|
|
|
|
*
|
|
|
|
* expect(Chai).to.be.an.instanceOf(Tea);
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
2011-12-24 18:20:48 +00:00
|
|
|
* @name instanceof
|
2011-12-15 22:50:28 +00:00
|
|
|
* @param {Constructor}
|
2012-01-25 19:07:31 +00:00
|
|
|
* @alias instanceOf
|
2011-12-15 22:50:28 +00:00
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.instanceof = function (constructor) {
|
|
|
|
var name = constructor.name;
|
|
|
|
this.assert(
|
|
|
|
this.obj instanceof constructor
|
|
|
|
, 'expected ' + this.inspect + ' to be an instance of ' + name
|
|
|
|
, 'expected ' + this.inspect + ' to not be an instance of ' + name);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .property(name, [value])
|
|
|
|
*
|
2011-12-18 14:04:51 +00:00
|
|
|
* Assert that property of `name` exists, optionally with `value`.
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* var obj = { foo: 'bar' }
|
|
|
|
* expect(obj).to.have.property('foo');
|
|
|
|
* expect(obj).to.have.property('foo', 'bar');
|
|
|
|
* expect(obj).to.have.property('foo').to.be.a('string');
|
|
|
|
*
|
|
|
|
* @name property
|
|
|
|
* @param {String} name
|
|
|
|
* @param {*} value (optional)
|
|
|
|
* @returns value of property for chaining
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-14 20:58:24 +00:00
|
|
|
Assertion.prototype.property = function (name, val) {
|
2011-12-15 12:07:27 +00:00
|
|
|
if (this.negate && undefined !== val) {
|
|
|
|
if (undefined === this.obj[name]) {
|
|
|
|
throw new Error(this.inspect + ' has no property ' + inspect(name));
|
|
|
|
}
|
2011-12-14 20:58:24 +00:00
|
|
|
} else {
|
|
|
|
this.assert(
|
|
|
|
undefined !== this.obj[name]
|
2011-12-15 12:07:27 +00:00
|
|
|
, 'expected ' + this.inspect + ' to have a property ' + inspect(name)
|
|
|
|
, 'expected ' + this.inspect + ' to not have property ' + inspect(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (undefined !== val) {
|
|
|
|
this.assert(
|
|
|
|
val === this.obj[name]
|
|
|
|
, 'expected ' + this.inspect + ' to have a property ' + inspect(name) + ' of ' +
|
|
|
|
inspect(val) + ', but got ' + inspect(this.obj[name])
|
|
|
|
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val));
|
2011-12-14 20:58:24 +00:00
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
this.obj = this.obj[name];
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .ownProperty(name)
|
|
|
|
*
|
|
|
|
* Assert that has own property by `name`.
|
|
|
|
*
|
|
|
|
* expect('test').to.have.ownProperty('length');
|
|
|
|
*
|
|
|
|
* @name ownProperty
|
|
|
|
* @alias haveOwnProperty
|
|
|
|
* @param {String} name
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
Assertion.prototype.ownProperty = function (name) {
|
|
|
|
this.assert(
|
|
|
|
this.obj.hasOwnProperty(name)
|
|
|
|
, 'expected ' + this.inspect + ' to have own property ' + inspect(name)
|
|
|
|
, 'expected ' + this.inspect + ' to not have own property ' + inspect(name));
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .length(val)
|
|
|
|
*
|
|
|
|
* Assert that object has expected length.
|
|
|
|
*
|
|
|
|
* expect([1,2,3]).to.have.length(3);
|
|
|
|
* expect('foobar').to.have.length(6);
|
|
|
|
*
|
|
|
|
* @name length
|
|
|
|
* @alias lengthOf
|
|
|
|
* @param {Number} length
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.length = function (n) {
|
|
|
|
new Assertion(this.obj).to.have.property('length');
|
|
|
|
var len = this.obj.length;
|
|
|
|
|
|
|
|
this.assert(
|
|
|
|
len == n
|
2011-12-15 12:07:27 +00:00
|
|
|
, 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len
|
2011-12-07 06:10:58 +00:00
|
|
|
, 'expected ' + this.inspect + ' to not have a length of ' + len);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .match(regexp)
|
|
|
|
*
|
|
|
|
* Assert that matches regular expression.
|
|
|
|
*
|
|
|
|
* expect('foobar').to.match(/^foo/);
|
|
|
|
*
|
|
|
|
* @name match
|
|
|
|
* @param {RegExp} RegularExpression
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.match = function (re) {
|
|
|
|
this.assert(
|
|
|
|
re.exec(this.obj)
|
|
|
|
, 'expected ' + this.inspect + ' to match ' + re
|
2011-12-15 12:07:27 +00:00
|
|
|
, 'expected ' + this.inspect + ' not to match ' + re);
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
2011-12-18 12:02:18 +00:00
|
|
|
* # .include(obj)
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
2011-12-18 14:04:51 +00:00
|
|
|
* Assert the inclusion of an object in an Array or substring in string.
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* expect([1,2,3]).to.contain(2);
|
|
|
|
*
|
2011-12-18 12:02:18 +00:00
|
|
|
* @name include
|
2011-12-15 22:50:28 +00:00
|
|
|
* @param {Object|String|Number} obj
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
Assertion.prototype.include = function (obj) {
|
2011-12-07 06:10:58 +00:00
|
|
|
this.assert(
|
|
|
|
~this.obj.indexOf(obj)
|
2011-12-18 12:02:18 +00:00
|
|
|
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
|
|
|
|
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .string(string)
|
|
|
|
*
|
|
|
|
* Assert inclusion of string in string.
|
|
|
|
*
|
|
|
|
* expect('foobar').to.include.string('bar');
|
|
|
|
*
|
|
|
|
* @name string
|
|
|
|
* @param {String} string
|
|
|
|
* @api public
|
|
|
|
*/
|
2011-12-15 12:07:27 +00:00
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.string = function (str) {
|
|
|
|
new Assertion(this.obj).is.a('string');
|
|
|
|
|
|
|
|
this.assert(
|
|
|
|
~this.obj.indexOf(str)
|
2011-12-18 12:02:18 +00:00
|
|
|
, 'expected ' + this.inspect + ' to contain ' + inspect(str)
|
|
|
|
, 'expected ' + this.inspect + ' to not contain ' + inspect(str));
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
2011-12-18 12:02:18 +00:00
|
|
|
* # contain
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
2011-12-18 12:02:18 +00:00
|
|
|
* Toggles the `contain` flag for the `keys` assertion.
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
2011-12-18 12:02:18 +00:00
|
|
|
* @name contain
|
2011-12-15 22:50:28 +00:00
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
Object.defineProperty(Assertion.prototype, 'contain',
|
2011-12-18 09:51:36 +00:00
|
|
|
{ get: function () {
|
2011-12-18 12:02:18 +00:00
|
|
|
this.contains = true;
|
2011-12-18 09:51:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-12-15 22:50:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # .keys(key1, [key2], [...])
|
|
|
|
*
|
2011-12-18 14:04:51 +00:00
|
|
|
* Assert exact keys or the inclusing of keys using the `contain` modifier.
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
|
2011-12-18 12:02:18 +00:00
|
|
|
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* @name keys
|
|
|
|
* @alias key
|
|
|
|
* @param {String|Array} Keys
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
Assertion.prototype.keys = function(keys) {
|
|
|
|
var str
|
|
|
|
, ok = true;
|
|
|
|
|
|
|
|
keys = keys instanceof Array
|
|
|
|
? keys
|
|
|
|
: Array.prototype.slice.call(arguments);
|
|
|
|
|
|
|
|
if (!keys.length) throw new Error('keys required');
|
|
|
|
|
|
|
|
var actual = Object.keys(this.obj)
|
|
|
|
, len = keys.length;
|
|
|
|
|
|
|
|
// Inclusion
|
|
|
|
ok = keys.every(function(key){
|
|
|
|
return ~actual.indexOf(key);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Strict
|
2011-12-18 12:02:18 +00:00
|
|
|
if (!this.negate && !this.contains) {
|
2011-12-15 12:07:27 +00:00
|
|
|
ok = ok && keys.length == actual.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Key string
|
|
|
|
if (len > 1) {
|
|
|
|
keys = keys.map(function(key){
|
|
|
|
return inspect(key);
|
|
|
|
});
|
|
|
|
var last = keys.pop();
|
|
|
|
str = keys.join(', ') + ', and ' + last;
|
|
|
|
} else {
|
|
|
|
str = inspect(keys[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form
|
|
|
|
str = (len > 1 ? 'keys ' : 'key ') + str;
|
|
|
|
|
|
|
|
// Have / include
|
2011-12-18 12:02:18 +00:00
|
|
|
str = (this.contains ? 'contain ' : 'have ') + str;
|
2011-12-15 12:07:27 +00:00
|
|
|
|
|
|
|
// Assertion
|
|
|
|
this.assert(
|
|
|
|
ok
|
|
|
|
, 'expected ' + this.inspect + ' to ' + str
|
|
|
|
, 'expected ' + this.inspect + ' to not ' + str);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/**
|
|
|
|
* # .throw(constructor)
|
|
|
|
*
|
2011-12-18 14:04:51 +00:00
|
|
|
* Assert that a function will throw a specific type of error.
|
2011-12-15 22:50:28 +00:00
|
|
|
*
|
|
|
|
* var fn = function () { throw new ReferenceError(''); }
|
|
|
|
* expect(fn).to.throw(ReferenceError);
|
|
|
|
*
|
|
|
|
* @name throw
|
|
|
|
* @alias throws
|
|
|
|
* @param {ErrorConstructor} constructor
|
|
|
|
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
Assertion.prototype.throw = function (constructor) {
|
|
|
|
new Assertion(this.obj).is.a('function');
|
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
var thrown = false;
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
this.obj();
|
|
|
|
} catch (err) {
|
2011-12-18 12:02:18 +00:00
|
|
|
if (constructor) {
|
|
|
|
this.assert(
|
|
|
|
err instanceof constructor && err.name == constructor.name
|
|
|
|
, 'expected ' + this.inspect + ' to throw ' + constructor.name + ' but a ' + err.name + ' was thrown'
|
|
|
|
, 'expected ' + this.inspect + ' to not throw ' + constructor.name );
|
|
|
|
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
thrown = true;
|
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
var name = (constructor ? constructor.name : 'an error');
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
this.assert(
|
|
|
|
thrown === true
|
|
|
|
, 'expected ' + this.inspect + ' to throw ' + name
|
|
|
|
, 'expected ' + this.inspect + ' to not throw ' + name);
|
2011-12-18 12:02:18 +00:00
|
|
|
|
|
|
|
return this;
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
2011-12-15 12:07:27 +00:00
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
/**
|
|
|
|
* # .header(code)
|
|
|
|
*
|
|
|
|
* Assert `header` field has expected `value`.
|
|
|
|
*
|
|
|
|
* @name header
|
|
|
|
* @param {String} field
|
|
|
|
* @param {String} value
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Assertion.prototype.header = function (field, val) {
|
|
|
|
new Assertion(this.obj)
|
|
|
|
.to.have.property('headers').and
|
|
|
|
.to.have.property(field.toLowerCase(), val);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # .status(code)
|
|
|
|
*
|
|
|
|
* Assert `statusCode` of `code'.
|
|
|
|
*
|
2011-12-18 14:04:51 +00:00
|
|
|
* @name status
|
2011-12-18 12:02:18 +00:00
|
|
|
* @param {Number} code
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Assertion.prototype.status = function (code) {
|
|
|
|
new Assertion(this.obj).to.have.property('statusCode');
|
|
|
|
|
|
|
|
var status = this.obj.statusCode;
|
|
|
|
|
|
|
|
this.assert(
|
|
|
|
code == status
|
|
|
|
, 'expected response code of ' + code + ' ' + inspect(statusCodes[code])
|
|
|
|
+ ', but got ' + status + ' ' + inspect(statusCodes[status])
|
|
|
|
, 'expected to not respond with ' + code + ' ' + inspect(statusCodes[code]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # json
|
|
|
|
*
|
|
|
|
* Assert that this response has content-type: application/json.
|
|
|
|
*
|
|
|
|
* @name json
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Object.defineProperty(Assertion.prototype, 'json',
|
|
|
|
{ get: function () {
|
|
|
|
new Assertion(this.obj).to.have.header('content-type', 'application/json; charset=utf-8');
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # html
|
|
|
|
*
|
|
|
|
* Assert that this response has content-type: text/html.
|
|
|
|
*
|
|
|
|
* @name html
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
Object.defineProperty(Assertion.prototype, 'html',
|
|
|
|
{ get: function () {
|
|
|
|
new Assertion(this.obj).to.have.header('content-type', 'text/html; charset=utf-8');
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-12-15 22:50:28 +00:00
|
|
|
/*!
|
2011-12-15 12:07:27 +00:00
|
|
|
* Aliases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function alias(name, as){
|
|
|
|
Assertion.prototype[as] = Assertion.prototype[name];
|
|
|
|
return alias;
|
|
|
|
})
|
|
|
|
('length', 'lengthOf')
|
|
|
|
('keys', 'key')
|
|
|
|
('ownProperty', 'haveOwnProperty')
|
|
|
|
('above', 'greaterThan')
|
2011-12-15 22:50:28 +00:00
|
|
|
('below', 'lessThan')
|
2012-01-25 19:07:31 +00:00
|
|
|
('throw', 'throws')
|
|
|
|
('instanceof', 'instanceOf');
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
}); // module: assertion.js
|
|
|
|
|
|
|
|
require.register("chai.js", function(module, exports, require){
|
2011-12-15 13:02:26 +00:00
|
|
|
/*!
|
|
|
|
* chai
|
|
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
var exports = module.exports = {};
|
|
|
|
|
2012-01-02 06:14:24 +00:00
|
|
|
exports.version = '0.1.6';
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-15 13:02:26 +00:00
|
|
|
exports.expect = require('./interface/expect');
|
2011-12-07 06:10:58 +00:00
|
|
|
exports.assert = require('./interface/assert');
|
2011-12-15 12:07:27 +00:00
|
|
|
exports.should = require('./interface/should');
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
exports.Assertion = require('./assertion');
|
|
|
|
exports.AssertionError = require('./error');
|
2011-12-15 12:07:27 +00:00
|
|
|
|
|
|
|
exports.fail = function (actual, expected, message, operator, stackStartFunction) {
|
|
|
|
throw new exports.AssertionError({
|
|
|
|
message: message,
|
|
|
|
actual: actual,
|
|
|
|
expected: expected,
|
|
|
|
operator: operator,
|
|
|
|
stackStartFunction: stackStartFunction
|
|
|
|
});
|
2011-12-16 11:59:45 +00:00
|
|
|
};
|
2011-12-07 06:10:58 +00:00
|
|
|
}); // module: chai.js
|
|
|
|
|
|
|
|
require.register("error.js", function(module, exports, require){
|
2011-12-15 13:02:26 +00:00
|
|
|
/*!
|
|
|
|
* chai
|
|
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
var fail = require('./chai').fail;
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
module.exports = AssertionError;
|
|
|
|
|
2011-12-15 13:02:26 +00:00
|
|
|
/*!
|
|
|
|
* Inspired by node.js assert module
|
|
|
|
* https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
|
|
|
|
*/
|
2011-12-07 06:10:58 +00:00
|
|
|
function AssertionError (options) {
|
|
|
|
options = options || {};
|
|
|
|
this.name = 'AssertionError';
|
|
|
|
this.message = options.message;
|
|
|
|
this.actual = options.actual;
|
|
|
|
this.expected = options.expected;
|
2011-12-15 12:07:27 +00:00
|
|
|
this.operator = options.operator;
|
|
|
|
var stackStartFunction = options.stackStartFunction || fail;
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
if (Error.captureStackTrace) {
|
|
|
|
Error.captureStackTrace(this, stackStartFunction);
|
|
|
|
}
|
2011-12-15 13:02:26 +00:00
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
AssertionError.prototype.__proto__ = Error.prototype;
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
AssertionError.prototype.summary = function() {
|
2011-12-18 14:04:51 +00:00
|
|
|
var str = '';
|
|
|
|
|
|
|
|
if (this.operator) {
|
|
|
|
str += 'In: \'' + this.operator + '\'\n\t';
|
|
|
|
}
|
|
|
|
|
|
|
|
str += '' + this.name + (this.message ? ': ' + this.message : '');
|
|
|
|
|
|
|
|
return str;
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AssertionError.prototype.details = function() {
|
2011-12-18 14:04:51 +00:00
|
|
|
return this.summary();
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AssertionError.prototype.toString = function() {
|
2011-12-07 08:03:47 +00:00
|
|
|
return this.summary();
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
}); // module: error.js
|
|
|
|
|
|
|
|
require.register("interface/assert.js", function(module, exports, require){
|
2011-12-15 13:02:26 +00:00
|
|
|
/*!
|
|
|
|
* chai
|
|
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* ### TDD Style Introduction
|
|
|
|
*
|
|
|
|
* The TDD style is exposed through `assert` interfaces. This provides
|
|
|
|
* the classic assert.`test` notation, similiar to that packaged with
|
|
|
|
* node.js. This assert module, however, provides several additional
|
|
|
|
* tests and is browser compatible.
|
|
|
|
*
|
|
|
|
* // assert
|
|
|
|
* var assert = require('chai').assert;
|
|
|
|
* , foo = 'bar';
|
|
|
|
*
|
|
|
|
* assert.typeOf(foo, 'string');
|
|
|
|
* assert.equal(foo, 'bar');
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
2011-12-24 18:20:48 +00:00
|
|
|
var Assertion = require('../assertion')
|
|
|
|
, inspect = require('../utils/inspect')
|
2011-12-07 06:10:58 +00:00
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/*!
|
|
|
|
* Module export.
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
var assert = module.exports = {};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .ok(object, [message])
|
|
|
|
*
|
|
|
|
* Assert object is truthy.
|
|
|
|
*
|
|
|
|
* assert.ok('everthing', 'everything is ok');
|
|
|
|
* assert.ok(false, 'this will fail');
|
|
|
|
*
|
|
|
|
* @name ok
|
|
|
|
* @param {*} object to test
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.ok = function (val, msg) {
|
|
|
|
new Assertion(val, msg).is.ok;
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .equal(actual, expected, [message])
|
|
|
|
*
|
|
|
|
* Assert strict equality.
|
|
|
|
*
|
|
|
|
* assert.equal(3, 3, 'these numbers are equal');
|
|
|
|
*
|
|
|
|
* @name equal
|
|
|
|
* @param {*} actual
|
|
|
|
* @param {*} expected
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.equal = function (act, exp, msg) {
|
2011-12-24 18:20:48 +00:00
|
|
|
var test = new Assertion(act, msg);
|
|
|
|
|
|
|
|
test.assert(
|
|
|
|
exp == test.obj
|
|
|
|
, 'expected ' + test.inspect + ' to equal ' + inspect(exp)
|
|
|
|
, 'expected ' + test.inspect + ' to not equal ' + inspect(exp));
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .notEqual(actual, expected, [message])
|
|
|
|
*
|
2012-01-02 06:12:52 +00:00
|
|
|
* Assert not equal.
|
2011-12-18 09:51:36 +00:00
|
|
|
*
|
|
|
|
* assert.notEqual(3, 4, 'these numbers are not equal');
|
|
|
|
*
|
|
|
|
* @name notEqual
|
|
|
|
* @param {*} actual
|
|
|
|
* @param {*} expected
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.notEqual = function (act, exp, msg) {
|
2011-12-24 18:20:48 +00:00
|
|
|
var test = new Assertion(act, msg);
|
|
|
|
|
|
|
|
test.assert(
|
|
|
|
exp != test.obj
|
|
|
|
, 'expected ' + test.inspect + ' to equal ' + inspect(exp)
|
|
|
|
, 'expected ' + test.inspect + ' to not equal ' + inspect(exp));
|
|
|
|
};
|
|
|
|
|
2012-01-02 06:12:52 +00:00
|
|
|
/**
|
|
|
|
* # .strictEqual(actual, expected, [message])
|
|
|
|
*
|
|
|
|
* Assert strict equality.
|
|
|
|
*
|
|
|
|
* assert.strictEqual(true, true, 'these booleans are strictly equal');
|
|
|
|
*
|
|
|
|
* @name strictEqual
|
|
|
|
* @param {*} actual
|
|
|
|
* @param {*} expected
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-24 18:20:48 +00:00
|
|
|
assert.strictEqual = function (act, exp, msg) {
|
|
|
|
new Assertion(act, msg).to.equal(exp);
|
|
|
|
};
|
|
|
|
|
2012-01-02 06:12:52 +00:00
|
|
|
/**
|
|
|
|
* # .notStrictEqual(actual, expected, [message])
|
|
|
|
*
|
|
|
|
* Assert strict equality.
|
|
|
|
*
|
|
|
|
* assert.notStrictEqual(1, true, 'these booleans are not strictly equal');
|
|
|
|
*
|
|
|
|
* @name notStrictEqual
|
|
|
|
* @param {*} actual
|
|
|
|
* @param {*} expected
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-24 18:20:48 +00:00
|
|
|
assert.notStrictEqual = function (act, exp, msg) {
|
2011-12-07 06:10:58 +00:00
|
|
|
new Assertion(act, msg).to.not.equal(exp);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .deepEqual(actual, expected, [message])
|
|
|
|
*
|
|
|
|
* Assert not deep equality.
|
|
|
|
*
|
|
|
|
* assert.deepEqual({ tea: 'green' }, { tea: 'green' });
|
|
|
|
*
|
|
|
|
* @name deepEqual
|
|
|
|
* @param {*} actual
|
|
|
|
* @param {*} expected
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.deepEqual = function (act, exp, msg) {
|
2011-12-15 13:02:26 +00:00
|
|
|
new Assertion(act, msg).to.eql(exp);
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .notDeepEqual(actual, expected, [message])
|
|
|
|
*
|
|
|
|
* Assert not deep equality.
|
|
|
|
*
|
|
|
|
* assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
|
|
|
|
*
|
|
|
|
* @name notDeepEqual
|
|
|
|
* @param {*} actual
|
|
|
|
* @param {*} expected
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.notDeepEqual = function (act, exp, msg) {
|
2011-12-15 13:02:26 +00:00
|
|
|
new Assertion(act, msg).to.not.eql(exp);
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isTrue(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is true.
|
|
|
|
*
|
|
|
|
* var tea_served = true;
|
|
|
|
* assert.isTrue(tea_served, 'the tea has been served');
|
|
|
|
*
|
|
|
|
* @name isTrue
|
|
|
|
* @param {Boolean} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isTrue = function (val, msg) {
|
|
|
|
new Assertion(val, msg).is.true;
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isFalse(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is false.
|
|
|
|
*
|
|
|
|
* var tea_served = false;
|
|
|
|
* assert.isFalse(tea_served, 'no tea yet? hmm...');
|
|
|
|
*
|
|
|
|
* @name isFalse
|
|
|
|
* @param {Boolean} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isFalse = function (val, msg) {
|
|
|
|
new Assertion(val, msg).is.false;
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isNull(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is null.
|
|
|
|
*
|
|
|
|
* assert.isNull(err, 'no errors');
|
|
|
|
*
|
|
|
|
* @name isNull
|
|
|
|
* @param {*} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isNull = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.not.exist;
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isNotNull(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is not null.
|
|
|
|
*
|
|
|
|
* var tea = 'tasty chai';
|
|
|
|
* assert.isNotNull(tea, 'great, time for tea!');
|
|
|
|
*
|
|
|
|
* @name isNotNull
|
|
|
|
* @param {*} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isNotNull = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.exist;
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isUndefined(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is undefined.
|
|
|
|
*
|
|
|
|
* assert.isUndefined(tea, 'no tea defined');
|
|
|
|
*
|
|
|
|
* @name isUndefined
|
|
|
|
* @param {*} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isUndefined = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.equal(undefined);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isFunction(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is a function.
|
|
|
|
*
|
|
|
|
* var serve_tea = function () { return 'cup of tea'; };
|
|
|
|
* assert.isFunction(serve_tea, 'great, we can have tea now');
|
|
|
|
*
|
|
|
|
* @name isFunction
|
|
|
|
* @param {Function} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
assert.isFunction = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.be.a('function');
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isObject(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is an object.
|
|
|
|
*
|
|
|
|
* var selection = { name: 'Chai', serve: 'with spices' };
|
|
|
|
* assert.isObject(selection, 'tea selection is an object');
|
|
|
|
*
|
|
|
|
* @name isObject
|
|
|
|
* @param {Object} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isObject = function (val, msg) {
|
2012-01-25 21:29:26 +00:00
|
|
|
new Assertion(val, msg).to.be.a('object');
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isArray(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is an instance of Array.
|
|
|
|
*
|
|
|
|
* var menu = [ 'green', 'chai', 'oolong' ];
|
|
|
|
* assert.isArray(menu, 'what kind of tea do we want?');
|
|
|
|
*
|
|
|
|
* @name isArray
|
|
|
|
* @param {*} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
assert.isArray = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.be.instanceof(Array);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isString(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is a string.
|
|
|
|
*
|
|
|
|
* var teaorder = 'chai';
|
|
|
|
* assert.isString(tea_order, 'order placed');
|
|
|
|
*
|
|
|
|
* @name isString
|
|
|
|
* @param {String} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
assert.isString = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.be.a('string');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # .isNumber(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is a number
|
|
|
|
*
|
|
|
|
* var cups = 2;
|
|
|
|
* assert.isNumber(cups, 'how many cups');
|
|
|
|
*
|
|
|
|
* @name isNumber
|
|
|
|
* @param {Number} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isNumber = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.be.instanceof(Number);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .isBoolean(value, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is a boolean
|
|
|
|
*
|
|
|
|
* var teaready = true
|
|
|
|
* , teaserved = false;
|
|
|
|
*
|
|
|
|
* assert.isBoolean(tea_ready, 'is the tea ready');
|
|
|
|
* assert.isBoolean(tea_served, 'has tea been served');
|
|
|
|
*
|
|
|
|
* @name isBoolean
|
|
|
|
* @param {*} value
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.isBoolean = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.be.a('boolean');
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .typeOf(value, name, [message])
|
|
|
|
*
|
|
|
|
* Assert typeof `value` is `name`.
|
|
|
|
*
|
|
|
|
* assert.typeOf('tea', 'string', 'we have a string');
|
|
|
|
*
|
|
|
|
* @name typeOf
|
|
|
|
* @param {*} value
|
|
|
|
* @param {String} typeof name
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.typeOf = function (val, type, msg) {
|
|
|
|
new Assertion(val, msg).to.be.a(type);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .instanceOf(object, constructor, [message])
|
|
|
|
*
|
|
|
|
* Assert `value` is instanceof `constructor`.
|
|
|
|
*
|
|
|
|
* var Tea = function (name) { this.name = name; }
|
|
|
|
* , Chai = new Tea('chai');
|
|
|
|
*
|
|
|
|
* assert.instanceOf(Chai, Tea, 'chai is an instance of tea');
|
|
|
|
*
|
|
|
|
* @name instanceOf
|
|
|
|
* @param {Object} object
|
|
|
|
* @param {Constructor} constructor
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.instanceOf = function (val, type, msg) {
|
|
|
|
new Assertion(val, msg).to.be.instanceof(type);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .include(value, includes, [message])
|
|
|
|
*
|
2011-12-24 18:20:48 +00:00
|
|
|
* Assert the inclusion of an object in another. Works
|
|
|
|
* for strings and arrays.
|
2011-12-18 09:51:36 +00:00
|
|
|
*
|
|
|
|
* assert.include('foobar', 'bar', 'foobar contains string `var`);
|
|
|
|
* assert.include([ 1, 2, 3], 3, 'array contains value);
|
|
|
|
*
|
|
|
|
* @name include
|
2011-12-24 18:20:48 +00:00
|
|
|
* @param {Array|String} value
|
2011-12-18 09:51:36 +00:00
|
|
|
* @param {*} includes
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.include = function (exp, inc, msg) {
|
2011-12-18 09:51:36 +00:00
|
|
|
var obj = new Assertion(exp, msg);
|
|
|
|
|
|
|
|
if (Array.isArray(exp)) {
|
2011-12-24 18:20:48 +00:00
|
|
|
obj.to.include(inc);
|
2011-12-18 09:51:36 +00:00
|
|
|
} else if ('string' === typeof exp) {
|
2011-12-24 18:20:48 +00:00
|
|
|
obj.to.contain.string(inc);
|
2011-12-18 09:51:36 +00:00
|
|
|
}
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
2011-12-24 18:20:48 +00:00
|
|
|
* # .match(value, regex, [message])
|
2011-12-18 09:51:36 +00:00
|
|
|
*
|
|
|
|
* Assert that `value` matches regular expression.
|
|
|
|
*
|
|
|
|
* assert.match('foobar', /^foo/, 'Regexp matches');
|
|
|
|
*
|
|
|
|
* @name match
|
|
|
|
* @param {*} value
|
|
|
|
* @param {RegExp} RegularExpression
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.match = function (exp, re, msg) {
|
|
|
|
new Assertion(exp, msg).to.match(re);
|
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
|
|
|
* # .length(value, constructor, [message])
|
|
|
|
*
|
|
|
|
* Assert that object has expected length.
|
|
|
|
*
|
|
|
|
* assert.length([1,2,3], 3, 'Array has length of 3');
|
|
|
|
* assert.length('foobar', 5, 'String has length of 6');
|
|
|
|
*
|
|
|
|
* @name length
|
|
|
|
* @param {*} value
|
|
|
|
* @param {Number} length
|
|
|
|
* @param {String} message
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
assert.length = function (exp, len, msg) {
|
2011-12-15 12:07:27 +00:00
|
|
|
new Assertion(exp, msg).to.have.length(len);
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 09:51:36 +00:00
|
|
|
/**
|
2011-12-24 18:20:48 +00:00
|
|
|
* # .throws(function, [constructor], [message])
|
2011-12-18 09:51:36 +00:00
|
|
|
*
|
|
|
|
* Assert that a function will throw a specific
|
|
|
|
* type of error.
|
|
|
|
*
|
|
|
|
* var fn = function () { throw new ReferenceError(''); }
|
|
|
|
* assert.throw(fn, ReferenceError, 'function throw reference error');
|
|
|
|
*
|
2011-12-24 18:20:48 +00:00
|
|
|
* @name throws
|
|
|
|
* @alias throw
|
2011-12-18 09:51:36 +00:00
|
|
|
* @param {Function} function to test
|
|
|
|
* @param {ErrorConstructor} constructor
|
|
|
|
* @param {String} message
|
|
|
|
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-24 18:20:48 +00:00
|
|
|
assert.throws = function (fn, type, msg) {
|
|
|
|
if ('string' === typeof type) {
|
|
|
|
msg = type;
|
|
|
|
type = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
new Assertion(fn, msg).to.throw(type);
|
|
|
|
};
|
|
|
|
|
2012-01-02 06:12:52 +00:00
|
|
|
/**
|
|
|
|
* # .doesNotThrow(function, [constructor], [message])
|
|
|
|
*
|
|
|
|
* Assert that a function will throw a specific
|
|
|
|
* type of error.
|
|
|
|
*
|
|
|
|
* var fn = function (err) { if (err) throw Error(err) };
|
|
|
|
* assert.doesNotThrow(fn, Error, 'function throw reference error');
|
|
|
|
*
|
|
|
|
* @name doesNotThrow
|
|
|
|
* @param {Function} function to test
|
|
|
|
* @param {ErrorConstructor} constructor
|
|
|
|
* @param {String} message
|
|
|
|
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
2011-12-24 18:20:48 +00:00
|
|
|
assert.doesNotThrow = function (fn, type, msg) {
|
|
|
|
if ('string' === typeof type) {
|
|
|
|
msg = type;
|
|
|
|
type = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
new Assertion(fn, msg).to.not.throw(type);
|
|
|
|
};
|
|
|
|
|
2012-01-02 06:12:52 +00:00
|
|
|
/*!
|
|
|
|
* Undocumented / untested
|
|
|
|
*/
|
|
|
|
|
2011-12-24 18:20:48 +00:00
|
|
|
assert.ifError = function (val, msg) {
|
|
|
|
new Assertion(val, msg).to.not.be.ok;
|
2011-12-07 06:10:58 +00:00
|
|
|
};
|
2011-12-18 09:51:36 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Aliases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function alias(name, as){
|
|
|
|
assert[as] = assert[name];
|
|
|
|
return alias;
|
|
|
|
})
|
2011-12-24 18:20:48 +00:00
|
|
|
('length', 'lengthOf')
|
|
|
|
('throws', 'throw');
|
2011-12-18 09:51:36 +00:00
|
|
|
//('keys', 'key')
|
|
|
|
//('ownProperty', 'haveOwnProperty')
|
|
|
|
//('above', 'greaterThan')
|
|
|
|
//('below', 'lessThan')
|
|
|
|
//('throw', 'throws');
|
2012-01-25 19:07:31 +00:00
|
|
|
|
2011-12-07 06:10:58 +00:00
|
|
|
}); // module: interface/assert.js
|
2011-12-14 20:58:24 +00:00
|
|
|
|
2011-12-15 13:02:26 +00:00
|
|
|
require.register("interface/expect.js", function(module, exports, require){
|
|
|
|
/*!
|
|
|
|
* chai
|
|
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
2011-12-15 12:07:27 +00:00
|
|
|
|
2011-12-15 13:02:26 +00:00
|
|
|
var Assertion = require('../assertion');
|
|
|
|
|
|
|
|
module.exports = function (val, message) {
|
|
|
|
return new Assertion(val, message);
|
|
|
|
};
|
|
|
|
}); // module: interface/expect.js
|
|
|
|
|
|
|
|
require.register("interface/should.js", function(module, exports, require){
|
2011-12-15 12:07:27 +00:00
|
|
|
/*!
|
2011-12-15 13:02:26 +00:00
|
|
|
* chai
|
|
|
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
2011-12-15 12:07:27 +00:00
|
|
|
* MIT Licensed
|
|
|
|
*/
|
|
|
|
|
2011-12-15 13:02:26 +00:00
|
|
|
var Assertion = require('../assertion');
|
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
/**
|
|
|
|
* Expose api via `Object#should`.
|
|
|
|
*
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = function () {
|
2011-12-15 13:02:26 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Originally from: should.js
|
|
|
|
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
|
|
|
|
* MIT Licensed
|
|
|
|
*/
|
2011-12-15 12:07:27 +00:00
|
|
|
Object.defineProperty(Object.prototype, 'should', {
|
|
|
|
set: function(){},
|
|
|
|
get: function(){
|
2012-01-25 21:29:26 +00:00
|
|
|
if (this instanceof String || this instanceof Number) {
|
|
|
|
return new Assertion(this.constructor(this));
|
|
|
|
} else if (this instanceof Boolean) {
|
|
|
|
return new Assertion(this == true);
|
|
|
|
}
|
2011-12-15 12:07:27 +00:00
|
|
|
return new Assertion(this);
|
|
|
|
},
|
|
|
|
configurable: true
|
|
|
|
});
|
2011-12-15 13:02:26 +00:00
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
var should = {};
|
2011-12-15 13:02:26 +00:00
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
should.equal = function (val1, val2) {
|
|
|
|
new Assertion(val1).to.equal(val2);
|
|
|
|
};
|
2011-12-15 13:02:26 +00:00
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
should.throw = function (fn, err) {
|
|
|
|
new Assertion(fn).to.throw(err);
|
|
|
|
};
|
|
|
|
|
2012-01-02 05:50:47 +00:00
|
|
|
should.exist = function (val) {
|
|
|
|
new Assertion(val).to.exist;
|
|
|
|
}
|
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
// negation
|
|
|
|
should.not = {}
|
|
|
|
|
|
|
|
should.not.equal = function (val1, val2) {
|
2012-01-02 05:50:47 +00:00
|
|
|
new Assertion(val1).to.not.equal(val2);
|
2011-12-18 12:02:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
should.not.throw = function (fn, err) {
|
|
|
|
new Assertion(fn).to.not.throw(err);
|
|
|
|
};
|
|
|
|
|
2012-01-02 05:50:47 +00:00
|
|
|
should.not.exist = function (val) {
|
|
|
|
new Assertion(val).to.not.exist;
|
|
|
|
}
|
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
return should;
|
|
|
|
};
|
2012-01-25 21:29:26 +00:00
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
}); // module: interface/should.js
|
|
|
|
|
2011-12-18 12:02:18 +00:00
|
|
|
require.register("utils/constants.js", function(module, exports, require){
|
|
|
|
|
|
|
|
var exports = module.exports = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* More includes from node.js code
|
|
|
|
* https://github.com/joyent/node/blob/master/lib/http.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.STATUS_CODES = {
|
|
|
|
100 : 'Continue',
|
|
|
|
101 : 'Switching Protocols',
|
|
|
|
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
|
|
|
|
200 : 'OK',
|
|
|
|
201 : 'Created',
|
|
|
|
202 : 'Accepted',
|
|
|
|
203 : 'Non-Authoritative Information',
|
|
|
|
204 : 'No Content',
|
|
|
|
205 : 'Reset Content',
|
|
|
|
206 : 'Partial Content',
|
|
|
|
207 : 'Multi-Status', // RFC 4918
|
|
|
|
300 : 'Multiple Choices',
|
|
|
|
301 : 'Moved Permanently',
|
|
|
|
302 : 'Moved Temporarily',
|
|
|
|
303 : 'See Other',
|
|
|
|
304 : 'Not Modified',
|
|
|
|
305 : 'Use Proxy',
|
|
|
|
307 : 'Temporary Redirect',
|
|
|
|
400 : 'Bad Request',
|
|
|
|
401 : 'Unauthorized',
|
|
|
|
402 : 'Payment Required',
|
|
|
|
403 : 'Forbidden',
|
|
|
|
404 : 'Not Found',
|
|
|
|
405 : 'Method Not Allowed',
|
|
|
|
406 : 'Not Acceptable',
|
|
|
|
407 : 'Proxy Authentication Required',
|
|
|
|
408 : 'Request Time-out',
|
|
|
|
409 : 'Conflict',
|
|
|
|
410 : 'Gone',
|
|
|
|
411 : 'Length Required',
|
|
|
|
412 : 'Precondition Failed',
|
|
|
|
413 : 'Request Entity Too Large',
|
|
|
|
414 : 'Request-URI Too Large',
|
|
|
|
415 : 'Unsupported Media Type',
|
|
|
|
416 : 'Requested Range Not Satisfiable',
|
|
|
|
417 : 'Expectation Failed',
|
|
|
|
418 : 'I\'m a teapot', // RFC 2324
|
|
|
|
422 : 'Unprocessable Entity', // RFC 4918
|
|
|
|
423 : 'Locked', // RFC 4918
|
|
|
|
424 : 'Failed Dependency', // RFC 4918
|
|
|
|
425 : 'Unordered Collection', // RFC 4918
|
|
|
|
426 : 'Upgrade Required', // RFC 2817
|
|
|
|
500 : 'Internal Server Error',
|
|
|
|
501 : 'Not Implemented',
|
|
|
|
502 : 'Bad Gateway',
|
|
|
|
503 : 'Service Unavailable',
|
|
|
|
504 : 'Gateway Time-out',
|
|
|
|
505 : 'HTTP Version not supported',
|
|
|
|
506 : 'Variant Also Negotiates', // RFC 2295
|
|
|
|
507 : 'Insufficient Storage', // RFC 4918
|
|
|
|
509 : 'Bandwidth Limit Exceeded',
|
|
|
|
510 : 'Not Extended' // RFC 2774
|
|
|
|
};
|
|
|
|
}); // module: utils/constants.js
|
|
|
|
|
2011-12-15 12:07:27 +00:00
|
|
|
require.register("utils/eql.js", function(module, exports, require){
|
2011-12-15 13:02:26 +00:00
|
|
|
// This is directly from Node.js assert
|
|
|
|
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
|
2011-12-14 20:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = _deepEqual;
|
|
|
|
|
|
|
|
// For browser implementation
|
|
|
|
if (!Buffer) {
|
|
|
|
var Buffer = {
|
|
|
|
isBuffer: function () {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2011-12-15 12:07:27 +00:00
|
|
|
|
2011-12-14 20:58:24 +00:00
|
|
|
function _deepEqual(actual, expected) {
|
|
|
|
// 7.1. All identical values are equivalent, as determined by ===.
|
|
|
|
if (actual === expected) {
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
|
|
|
|
if (actual.length != expected.length) return false;
|
|
|
|
|
|
|
|
for (var i = 0; i < actual.length; i++) {
|
|
|
|
if (actual[i] !== expected[i]) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// 7.2. If the expected value is a Date object, the actual value is
|
|
|
|
// equivalent if it is also a Date object that refers to the same time.
|
|
|
|
} else if (actual instanceof Date && expected instanceof Date) {
|
|
|
|
return actual.getTime() === expected.getTime();
|
|
|
|
|
|
|
|
// 7.3. Other pairs that do not both pass typeof value == 'object',
|
|
|
|
// equivalence is determined by ==.
|
|
|
|
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
2011-12-15 12:07:27 +00:00
|
|
|
return actual === expected;
|
2011-12-14 20:58:24 +00:00
|
|
|
|
|
|
|
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
|
|
|
// determined by having the same number of owned properties (as verified
|
|
|
|
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
|
|
|
// (although not necessarily the same order), equivalent values for every
|
|
|
|
// corresponding key, and an identical 'prototype' property. Note: this
|
|
|
|
// accounts for both named and indexed properties on Arrays.
|
|
|
|
} else {
|
|
|
|
return objEquiv(actual, expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isUndefinedOrNull(value) {
|
|
|
|
return value === null || value === undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isArguments(object) {
|
|
|
|
return Object.prototype.toString.call(object) == '[object Arguments]';
|
|
|
|
}
|
|
|
|
|
|
|
|
function objEquiv(a, b) {
|
|
|
|
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
|
|
|
return false;
|
|
|
|
// an identical 'prototype' property.
|
|
|
|
if (a.prototype !== b.prototype) return false;
|
|
|
|
//~~~I've managed to break Object.keys through screwy arguments passing.
|
|
|
|
// Converting to array solves the problem.
|
|
|
|
if (isArguments(a)) {
|
|
|
|
if (!isArguments(b)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
a = pSlice.call(a);
|
|
|
|
b = pSlice.call(b);
|
|
|
|
return _deepEqual(a, b);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
var ka = Object.keys(a),
|
|
|
|
kb = Object.keys(b),
|
|
|
|
key, i;
|
|
|
|
} catch (e) {//happens when one is a string literal and the other isn't
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// having the same number of owned properties (keys incorporates
|
|
|
|
// hasOwnProperty)
|
|
|
|
if (ka.length != kb.length)
|
|
|
|
return false;
|
|
|
|
//the same set of keys (although not necessarily the same order),
|
|
|
|
ka.sort();
|
|
|
|
kb.sort();
|
|
|
|
//~~~cheap key test
|
|
|
|
for (i = ka.length - 1; i >= 0; i--) {
|
|
|
|
if (ka[i] != kb[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//equivalent values for every corresponding key, and
|
|
|
|
//~~~possibly expensive deep test
|
|
|
|
for (i = ka.length - 1; i >= 0; i--) {
|
|
|
|
key = ka[i];
|
|
|
|
if (!_deepEqual(a[key], b[key])) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-15 12:07:27 +00:00
|
|
|
}); // module: utils/eql.js
|
|
|
|
|
|
|
|
require.register("utils/inspect.js", function(module, exports, require){
|
2011-12-15 13:02:26 +00:00
|
|
|
// This is (almost) directly from Node.js utils
|
|
|
|
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
|
2011-12-15 12:07:27 +00:00
|
|
|
|
|
|
|
module.exports = inspect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Echos the value of a value. Trys to print the value out
|
|
|
|
* in the best way possible given the different types.
|
|
|
|
*
|
|
|
|
* @param {Object} obj The object to print out.
|
|
|
|
* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
|
|
|
|
* properties of objects.
|
|
|
|
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
|
|
|
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
|
|
|
* output. Default is false (no coloring).
|
|
|
|
*/
|
|
|
|
function inspect(obj, showHidden, depth, colors) {
|
|
|
|
var ctx = {
|
|
|
|
showHidden: showHidden,
|
|
|
|
seen: [],
|
|
|
|
stylize: function (str) { return str; }
|
|
|
|
};
|
|
|
|
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatValue(ctx, value, recurseTimes) {
|
|
|
|
// Provide a hook for user-specified inspect functions.
|
|
|
|
// Check that value is an object with an inspect function on it
|
|
|
|
if (value && typeof value.inspect === 'function' &&
|
|
|
|
// Filter out the util module, it's inspect function is special
|
|
|
|
value.inspect !== exports.inspect &&
|
|
|
|
// Also filter out any prototype objects using the circular check.
|
|
|
|
!(value.constructor && value.constructor.prototype === value)) {
|
|
|
|
return value.inspect(recurseTimes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Primitive types cannot have properties
|
|
|
|
var primitive = formatPrimitive(ctx, value);
|
|
|
|
if (primitive) {
|
|
|
|
return primitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look up the keys of the object.
|
|
|
|
var visibleKeys = Object.keys(value);
|
|
|
|
var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys;
|
|
|
|
|
|
|
|
// Some type of object without properties can be shortcutted.
|
|
|
|
if (keys.length === 0) {
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
var name = value.name ? ': ' + value.name : '';
|
|
|
|
return ctx.stylize('[Function' + name + ']', 'special');
|
|
|
|
}
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
|
|
}
|
|
|
|
if (isDate(value)) {
|
|
|
|
return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
|
|
|
|
}
|
|
|
|
if (isError(value)) {
|
|
|
|
return formatError(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var base = '', array = false, braces = ['{', '}'];
|
|
|
|
|
|
|
|
// Make Array say that they are Array
|
|
|
|
if (isArray(value)) {
|
|
|
|
array = true;
|
|
|
|
braces = ['[', ']'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make functions say that they are functions
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
var n = value.name ? ': ' + value.name : '';
|
|
|
|
base = ' [Function' + n + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make RegExps say that they are RegExps
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
base = ' ' + RegExp.prototype.toString.call(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make dates with properties first say the date
|
|
|
|
if (isDate(value)) {
|
|
|
|
base = ' ' + Date.prototype.toUTCString.call(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make error with message first say the error
|
|
|
|
if (isError(value)) {
|
|
|
|
base = ' ' + formatError(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keys.length === 0 && (!array || value.length == 0)) {
|
|
|
|
return braces[0] + base + braces[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recurseTimes < 0) {
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
|
|
} else {
|
|
|
|
return ctx.stylize('[Object]', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.seen.push(value);
|
|
|
|
|
|
|
|
var output;
|
|
|
|
if (array) {
|
|
|
|
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|
|
|
} else {
|
|
|
|
output = keys.map(function(key) {
|
|
|
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.seen.pop();
|
|
|
|
|
|
|
|
return reduceToSingleString(output, base, braces);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatPrimitive(ctx, value) {
|
|
|
|
switch (typeof value) {
|
|
|
|
case 'undefined':
|
|
|
|
return ctx.stylize('undefined', 'undefined');
|
|
|
|
|
|
|
|
case 'string':
|
|
|
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|
|
|
.replace(/'/g, "\\'")
|
|
|
|
.replace(/\\"/g, '"') + '\'';
|
|
|
|
return ctx.stylize(simple, 'string');
|
|
|
|
|
|
|
|
case 'number':
|
|
|
|
return ctx.stylize('' + value, 'number');
|
|
|
|
|
|
|
|
case 'boolean':
|
|
|
|
return ctx.stylize('' + value, 'boolean');
|
|
|
|
}
|
|
|
|
// For some reason typeof null is "object", so special case here.
|
|
|
|
if (value === null) {
|
|
|
|
return ctx.stylize('null', 'null');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatError(value) {
|
|
|
|
return '[' + Error.prototype.toString.call(value) + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
var output = [];
|
|
|
|
for (var i = 0, l = value.length; i < l; ++i) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
String(i), true));
|
|
|
|
} else {
|
|
|
|
output.push('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keys.forEach(function(key) {
|
|
|
|
if (!key.match(/^\d+$/)) {
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
key, true));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|
|
|
var name, str;
|
|
|
|
if (value.__lookupGetter__) {
|
|
|
|
if (value.__lookupGetter__(key)) {
|
|
|
|
if (value.__lookupSetter__(key)) {
|
|
|
|
str = ctx.stylize('[Getter/Setter]', 'special');
|
|
|
|
} else {
|
|
|
|
str = ctx.stylize('[Getter]', 'special');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (value.__lookupSetter__(key)) {
|
|
|
|
str = ctx.stylize('[Setter]', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (visibleKeys.indexOf(key) < 0) {
|
|
|
|
name = '[' + key + ']';
|
|
|
|
}
|
|
|
|
if (!str) {
|
|
|
|
if (ctx.seen.indexOf(value[key]) < 0) {
|
|
|
|
if (recurseTimes === null) {
|
|
|
|
str = formatValue(ctx, value[key], null);
|
|
|
|
} else {
|
|
|
|
str = formatValue(ctx, value[key], recurseTimes - 1);
|
|
|
|
}
|
|
|
|
if (str.indexOf('\n') > -1) {
|
|
|
|
if (array) {
|
|
|
|
str = str.split('\n').map(function(line) {
|
|
|
|
return ' ' + line;
|
|
|
|
}).join('\n').substr(2);
|
|
|
|
} else {
|
|
|
|
str = '\n' + str.split('\n').map(function(line) {
|
|
|
|
return ' ' + line;
|
|
|
|
}).join('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str = ctx.stylize('[Circular]', 'special');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof name === 'undefined') {
|
|
|
|
if (array && key.match(/^\d+$/)) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
name = JSON.stringify('' + key);
|
|
|
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
|
|
name = name.substr(1, name.length - 2);
|
|
|
|
name = ctx.stylize(name, 'name');
|
|
|
|
} else {
|
|
|
|
name = name.replace(/'/g, "\\'")
|
|
|
|
.replace(/\\"/g, '"')
|
|
|
|
.replace(/(^"|"$)/g, "'");
|
|
|
|
name = ctx.stylize(name, 'string');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return name + ': ' + str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function reduceToSingleString(output, base, braces) {
|
|
|
|
var numLinesEst = 0;
|
|
|
|
var length = output.reduce(function(prev, cur) {
|
|
|
|
numLinesEst++;
|
|
|
|
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|
|
|
return prev + cur.length + 1;
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
if (length > 60) {
|
|
|
|
return braces[0] +
|
|
|
|
(base === '' ? '' : base + '\n ') +
|
|
|
|
' ' +
|
|
|
|
output.join(',\n ') +
|
|
|
|
' ' +
|
|
|
|
braces[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function isArray(ar) {
|
|
|
|
return Array.isArray(ar) ||
|
|
|
|
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRegExp(re) {
|
|
|
|
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isDate(d) {
|
|
|
|
return typeof d === 'object' && objectToString(d) === '[object Date]';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isError(e) {
|
|
|
|
return typeof e === 'object' && objectToString(e) === '[object Error]';
|
|
|
|
}
|
|
|
|
|
|
|
|
function objectToString(o) {
|
|
|
|
return Object.prototype.toString.call(o);
|
|
|
|
}
|
|
|
|
}); // module: utils/inspect.js
|
2011-12-07 06:10:58 +00:00
|
|
|
|
|
|
|
|
2011-12-18 12:31:58 +00:00
|
|
|
return require('chai');
|
|
|
|
});
|