forked from cmdjs/gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpect.js
More file actions
1 lines (1 loc) · 14.4 KB
/
expect.js
File metadata and controls
1 lines (1 loc) · 14.4 KB
1
define("gallery/expect/0.3.1/expect",[],function(require,exports,module){!function(global,module){function expect(a){return new Assertion(a)}function Assertion(a,b,c){if(this.obj=a,this.flags={},void 0!=c){this.flags[b]=!0;for(var d in c.flags)c.flags.hasOwnProperty(d)&&(this.flags[d]=!0)}var e=b?flags[b]:keys(flags),f=this;if(e)for(var d=0,g=e.length;g>d;d++)if(!this.flags[e[d]]){var h=e[d],i=new Assertion(this.obj,h,this);if("function"==typeof Assertion.prototype[h]){var j=this[h];this[h]=function(){return j.apply(f,arguments)};for(var k in Assertion.prototype)Assertion.prototype.hasOwnProperty(k)&&k!=h&&(this[h][k]=bind(i[k],i))}else this[h]=i}}function bind(a,b){return function(){return a.apply(b,arguments)}}function every(a,b,c){for(var d=c||global,e=0,f=a.length;f>e;++e)if(!b.call(d,a[e],e,a))return!1;return!0}function indexOf(a,b,c){if(Array.prototype.indexOf)return Array.prototype.indexOf.call(a,b,c);if(void 0===a.length)return-1;for(var d=a.length,c=0>c?0>c+d?0:c+d:c||0;d>c&&a[c]!==b;c++);return c>=d?-1:c}function i(a,b,c){function d(a){return a}function e(a,c){if(a&&"function"==typeof a.inspect&&a!==exports&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(c);switch(typeof a){case"undefined":return d("undefined","undefined");case"string":var g="'"+json.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return d(g,"string");case"number":return d(""+a,"number");case"boolean":return d(""+a,"boolean")}if(null===a)return d("null","null");if(isDOMElement(a))return getOuterHTML(a);var h=keys(a),i=b?Object.getOwnPropertyNames(a):h;if("function"==typeof a&&0===i.length){if(isRegExp(a))return d(""+a,"regexp");var j=a.name?": "+a.name:"";return d("[Function"+j+"]","special")}if(isDate(a)&&0===i.length)return d(a.toUTCString(),"date");if(a instanceof Error)return d("["+a.toString()+"]","Error");var k,l,m;if(isArray(a)?(l="Array",m=["[","]"]):(l="Object",m=["{","}"]),"function"==typeof a){var n=a.name?": "+a.name:"";k=isRegExp(a)?" "+a:" [Function"+n+"]"}else k="";if(isDate(a)&&(k=" "+a.toUTCString()),0===i.length)return m[0]+k+m[1];if(0>c)return isRegExp(a)?d(""+a,"regexp"):d("[Object]","special");f.push(a);var o=map(i,function(b){var g,i;if(a.__lookupGetter__&&(a.__lookupGetter__(b)?i=a.__lookupSetter__(b)?d("[Getter/Setter]","special"):d("[Getter]","special"):a.__lookupSetter__(b)&&(i=d("[Setter]","special"))),indexOf(h,b)<0&&(g="["+b+"]"),i||(indexOf(f,a[b])<0?(i=null===c?e(a[b]):e(a[b],c-1),i.indexOf("\n")>-1&&(i=isArray(a)?map(i.split("\n"),function(a){return" "+a}).join("\n").substr(2):"\n"+map(i.split("\n"),function(a){return" "+a}).join("\n"))):i=d("[Circular]","special")),"undefined"==typeof g){if("Array"===l&&b.match(/^\d+$/))return i;g=json.stringify(""+b),g.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(g=g.substr(1,g.length-2),g=d(g,"name")):(g=g.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),g=d(g,"string"))}return g+": "+i});f.pop();var p=0,q=reduce(o,function(a,b){return p++,indexOf(b,"\n")>=0&&p++,a+b.length+1},0);return o=q>50?m[0]+(""===k?"":k+"\n ")+" "+o.join(",\n ")+" "+m[1]:m[0]+k+" "+o.join(", ")+" "+m[1]}var f=[];return e(a,"undefined"==typeof c?2:c)}function isArray(a){return"[object Array]"===Object.prototype.toString.call(a)}function isRegExp(a){var b;try{b=""+a}catch(c){return!1}return a instanceof RegExp||"function"==typeof a&&"RegExp"===a.constructor.name&&a.compile&&a.test&&a.exec&&b.match(/^\/.*\/[gim]{0,3}$/)}function isDate(a){return a instanceof Date}function keys(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&b.push(c);return b}function map(a,b,c){if(Array.prototype.map)return Array.prototype.map.call(a,b,c);for(var d=new Array(a.length),e=0,f=a.length;f>e;e++)e in a&&(d[e]=b.call(c,a[e],e,a));return d}function reduce(a,b){if(Array.prototype.reduce)return Array.prototype.reduce.apply(a,Array.prototype.slice.call(arguments,1));var c=+this.length;if("function"!=typeof b)throw new TypeError;if(0===c&&1===arguments.length)throw new TypeError;var d=0;if(arguments.length>=2)var e=arguments[1];else for(;;){if(d in this){e=this[d++];break}if(++d>=c)throw new TypeError}for(;c>d;d++)d in this&&(e=b.call(null,e,this[d],d,this));return e}function isUndefinedOrNull(a){return null===a||void 0===a}function isArguments(a){return"[object Arguments]"==Object.prototype.toString.call(a)}function regExpEquiv(a,b){return a.source===b.source&&a.global===b.global&&a.ignoreCase===b.ignoreCase&&a.multiline===b.multiline}function objEquiv(a,b){if(isUndefinedOrNull(a)||isUndefinedOrNull(b))return!1;if(a.prototype!==b.prototype)return!1;if(isArguments(a))return isArguments(b)?(a=pSlice.call(a),b=pSlice.call(b),expect.eql(a,b)):!1;try{var c,d,e=keys(a),f=keys(b)}catch(g){return!1}if(e.length!=f.length)return!1;for(e.sort(),f.sort(),d=e.length-1;d>=0;d--)if(e[d]!=f[d])return!1;for(d=e.length-1;d>=0;d--)if(c=e[d],!expect.eql(a[c],b[c]))return!1;return!0}var exports=module.exports;module.exports=expect,expect.Assertion=Assertion,expect.version="0.3.1";var flags={not:["to","be","have","include","only"],to:["be","have","include","only","not"],only:["have"],have:["own"],be:["an"]};Assertion.prototype.assert=function(a,b,c,d){var e,b=this.flags.not?c:b,f=this.flags.not?!a:a;if(!f)throw e=new Error(b.call(this)),arguments.length>3&&(e.actual=this.obj,e.expected=d,e.showDiff=!0),e;this.and=new Assertion(this.obj)},Assertion.prototype.ok=function(){this.assert(!!this.obj,function(){return"expected "+i(this.obj)+" to be truthy"},function(){return"expected "+i(this.obj)+" to be falsy"})},Assertion.prototype.withArgs=function(){expect(this.obj).to.be.a("function");var a=this.obj,b=Array.prototype.slice.call(arguments);return expect(function(){a.apply(null,b)})},Assertion.prototype.throwError=Assertion.prototype.throwException=function(a){expect(this.obj).to.be.a("function");var b=!1,c=this.flags.not;try{this.obj()}catch(d){if(isRegExp(a)){var e="string"==typeof d?d:d.message;c?expect(e).to.not.match(a):expect(e).to.match(a)}else"function"==typeof a&&a(d);b=!0}isRegExp(a)&&c&&(this.flags.not=!1);var f=this.obj.name||"fn";this.assert(b,function(){return"expected "+f+" to throw an exception"},function(){return"expected "+f+" not to throw an exception"})},Assertion.prototype.empty=function(){var a;return"object"!=typeof this.obj||null===this.obj||isArray(this.obj)?("string"!=typeof this.obj&&expect(this.obj).to.be.an("object"),expect(this.obj).to.have.property("length"),a=!this.obj.length):a="number"==typeof this.obj.length?!this.obj.length:!keys(this.obj).length,this.assert(a,function(){return"expected "+i(this.obj)+" to be empty"},function(){return"expected "+i(this.obj)+" to not be empty"}),this},Assertion.prototype.be=Assertion.prototype.equal=function(a){return this.assert(a===this.obj,function(){return"expected "+i(this.obj)+" to equal "+i(a)},function(){return"expected "+i(this.obj)+" to not equal "+i(a)}),this},Assertion.prototype.eql=function(a){return this.assert(expect.eql(this.obj,a),function(){return"expected "+i(this.obj)+" to sort of equal "+i(a)},function(){return"expected "+i(this.obj)+" to sort of not equal "+i(a)},a),this},Assertion.prototype.within=function(a,b){var c=a+".."+b;return this.assert(this.obj>=a&&this.obj<=b,function(){return"expected "+i(this.obj)+" to be within "+c},function(){return"expected "+i(this.obj)+" to not be within "+c}),this},Assertion.prototype.a=Assertion.prototype.an=function(a){if("string"==typeof a){var b=/^[aeiou]/.test(a)?"n":"";this.assert("array"==a?isArray(this.obj):"regexp"==a?isRegExp(this.obj):"object"==a?"object"==typeof this.obj&&null!==this.obj:a==typeof this.obj,function(){return"expected "+i(this.obj)+" to be a"+b+" "+a},function(){return"expected "+i(this.obj)+" not to be a"+b+" "+a})}else{var c=a.name||"supplied constructor";this.assert(this.obj instanceof a,function(){return"expected "+i(this.obj)+" to be an instance of "+c},function(){return"expected "+i(this.obj)+" not to be an instance of "+c})}return this},Assertion.prototype.greaterThan=Assertion.prototype.above=function(a){return this.assert(this.obj>a,function(){return"expected "+i(this.obj)+" to be above "+a},function(){return"expected "+i(this.obj)+" to be below "+a}),this},Assertion.prototype.lessThan=Assertion.prototype.below=function(a){return this.assert(this.obj<a,function(){return"expected "+i(this.obj)+" to be below "+a},function(){return"expected "+i(this.obj)+" to be above "+a}),this},Assertion.prototype.match=function(a){return this.assert(a.exec(this.obj),function(){return"expected "+i(this.obj)+" to match "+a},function(){return"expected "+i(this.obj)+" not to match "+a}),this},Assertion.prototype.length=function(a){expect(this.obj).to.have.property("length");var b=this.obj.length;return this.assert(a==b,function(){return"expected "+i(this.obj)+" to have a length of "+a+" but got "+b},function(){return"expected "+i(this.obj)+" to not have a length of "+b}),this},Assertion.prototype.property=function(a,b){if(this.flags.own)return this.assert(Object.prototype.hasOwnProperty.call(this.obj,a),function(){return"expected "+i(this.obj)+" to have own property "+i(a)},function(){return"expected "+i(this.obj)+" to not have own property "+i(a)}),this;if(this.flags.not&&void 0!==b){if(void 0===this.obj[a])throw new Error(i(this.obj)+" has no property "+i(a))}else{var c;try{c=a in this.obj}catch(d){c=void 0!==this.obj[a]}this.assert(c,function(){return"expected "+i(this.obj)+" to have a property "+i(a)},function(){return"expected "+i(this.obj)+" to not have a property "+i(a)})}return void 0!==b&&this.assert(b===this.obj[a],function(){return"expected "+i(this.obj)+" to have a property "+i(a)+" of "+i(b)+", but got "+i(this.obj[a])},function(){return"expected "+i(this.obj)+" to not have a property "+i(a)+" of "+i(b)}),this.obj=this.obj[a],this},Assertion.prototype.string=Assertion.prototype.contain=function(a){return"string"==typeof this.obj?this.assert(~this.obj.indexOf(a),function(){return"expected "+i(this.obj)+" to contain "+i(a)},function(){return"expected "+i(this.obj)+" to not contain "+i(a)}):this.assert(~indexOf(this.obj,a),function(){return"expected "+i(this.obj)+" to contain "+i(a)},function(){return"expected "+i(this.obj)+" to not contain "+i(a)}),this},Assertion.prototype.key=Assertion.prototype.keys=function(a){var b,c=!0;if(a=isArray(a)?a:Array.prototype.slice.call(arguments),!a.length)throw new Error("keys required");var d=keys(this.obj),e=a.length;if(c=every(a,function(a){return~indexOf(d,a)}),!this.flags.not&&this.flags.only&&(c=c&&a.length==d.length),e>1){a=map(a,function(a){return i(a)});var f=a.pop();b=a.join(", ")+", and "+f}else b=i(a[0]);return b=(e>1?"keys ":"key ")+b,b=(this.flags.only?"only have ":"include ")+b,this.assert(c,function(){return"expected "+i(this.obj)+" to "+b},function(){return"expected "+i(this.obj)+" to not "+b}),this},Assertion.prototype.fail=function(a){var b=function(){return a||"explicit failure"};return this.assert(!1,b,b),this};var getOuterHTML=function(a){if("outerHTML"in a)return a.outerHTML;var b,c="http://www.w3.org/1999/xhtml",d=document.createElementNS(c,"_"),e=new XMLSerializer;return document.xmlVersion?e.serializeToString(a):(d.appendChild(a.cloneNode(!1)),b=d.innerHTML.replace("><",">"+a.innerHTML+"<"),d.innerHTML="",b)},isDOMElement=function(a){return"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&1===a.nodeType&&"string"==typeof a.nodeName};expect.stringify=i,expect.eql=function(a,b){if(a===b)return!0;if("undefined"!=typeof Buffer&&Buffer.isBuffer(a)&&Buffer.isBuffer(b)){if(a.length!=b.length)return!1;for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}return a instanceof Date&&b instanceof Date?a.getTime()===b.getTime():"object"!=typeof a&&"object"!=typeof b?a==b:isRegExp(a)&&isRegExp(b)?regExpEquiv(a,b):objEquiv(a,b)};var json=function(){"use strict";function f(a){return 10>a?"0"+a:a}function date(a){return isFinite(a.valueOf())?a.getUTCFullYear()+"-"+f(a.getUTCMonth()+1)+"-"+f(a.getUTCDate())+"T"+f(a.getUTCHours())+":"+f(a.getUTCMinutes())+":"+f(a.getUTCSeconds())+"Z":null}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i instanceof Date&&(i=date(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}if("object"==typeof JSON&&JSON.parse&&JSON.stringify)return{parse:nativeJSON.parse,stringify:nativeJSON.stringify};var JSON={},cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;return JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})},JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")},JSON}();"undefined"!=typeof window&&(window.expect=module.exports)}(this,"undefined"!=typeof module?module:{exports:{}})});