From 4b448a877cedec4e1029fdeb30542389dc87775a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 10 Feb 2014 23:00:19 -0800 Subject: [PATCH] Update vendor/underscore to v1.6.0. --- README.md | 5 +- dist/lodash.underscore.js | 124 +++++--- dist/lodash.underscore.min.js | 71 ++--- test/underscore.html | 15 +- vendor/underscore/LICENSE | 2 +- vendor/underscore/test/arrays.js | 60 ++-- vendor/underscore/test/chaining.js | 22 +- vendor/underscore/test/collections.js | 70 ++--- vendor/underscore/test/functions.js | 130 +++++---- vendor/underscore/test/objects.js | 395 ++++++++++++++------------ vendor/underscore/test/utility.js | 138 +++++---- vendor/underscore/underscore-min.js | 6 +- vendor/underscore/underscore.js | 233 +++++++++------ 13 files changed, 724 insertions(+), 547 deletions(-) diff --git a/README.md b/README.md index 4c4cb86d6..6597e89cd 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ A list of upcoming features is available on our [roadmap](https://github.com/lod ## Features *not* in Underscore * ~100% [code coverage](https://coveralls.io/r/lodash) - * AMD loader support ([curl](https://github.com/cujojs/curl), [dojo](http://dojotoolkit.org/), [requirejs](http://requirejs.org/), etc.) * Module collections for [AMD](https://github.com/lodash/lodash-amd/tree/2.4.1), [Node.js](https://npmjs.org/package/lodash-node), & as [npm packages](https://npmjs.org/browse/keyword/lodash-modularized) * [Semantic versioning](http://semver.org/) support for releases * [_(…)](http://lodash.com/docs#_) supports intuitive chaining @@ -32,14 +31,13 @@ A list of upcoming features is available on our [roadmap](https://github.com/lod * [_.bindKey](http://lodash.com/docs#bindKey) for binding [*“lazy”*](http://michaux.ca/articles/lazy-function-definition-pattern) defined methods * [_.clone](http://lodash.com/docs#clone) supports shallow cloning of `Date` & `RegExp` objects * [_.cloneDeep](http://lodash.com/docs#cloneDeep) for deep cloning arrays & objects - * [_.constant](http://lodash.com/docs#constant) & [_.property](http://lodash.com/docs#property) function generators for composing functions * [_.contains](http://lodash.com/docs#contains) accepts a `fromIndex` * [_.create](http://lodash.com/docs#create) for easier object inheritance * [_.callback](http://lodash.com/docs#createCallback) for extending callbacks in methods & mixins * [_.curry](http://lodash.com/docs#curry) for creating [curried](http://hughfdjackson.com/javascript/2013/07/06/why-curry-helps/) functions * [_.debounce](http://lodash.com/docs#debounce) & [_.throttle](http://lodash.com/docs#throttle) accept additional `options` for more control * [_.findIndex](http://lodash.com/docs#findIndex) & [_.findKey](http://lodash.com/docs#findKey) for finding indexes & keys - * [_.forEach](http://lodash.com/docs#forEach) is chainable & supports exiting early + * [_.forEach](http://lodash.com/docs#forEach) supports exiting early * [_.forIn](http://lodash.com/docs#forIn) for iterating own & inherited properties * [_.forOwn](http://lodash.com/docs#forOwn) for iterating own properties * [_.isPlainObject](http://lodash.com/docs#isPlainObject) for checking if values are created by `Object` @@ -47,7 +45,6 @@ A list of upcoming features is available on our [roadmap](https://github.com/lod * [_.memoize](http://lodash.com/docs#memoize) exposes the `cache` of memoized functions * [_.merge](http://lodash.com/docs#merge) for a deep [_.extend](http://lodash.com/docs#extend) * [_.noop](http://lodash.com/docs#noop) for function placeholders - * [_.now](http://lodash.com/docs#now) as a cross-browser `Date.now` alternative * [_.parseInt](http://lodash.com/docs#parseInt) for consistent behavior * [_.pull](http://lodash.com/docs#pull) & [_.remove](http://lodash.com/docs#remove) for mutating arrays * [_.random](http://lodash.com/docs#random) supports returning floating-point numbers diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index fe6570865..0560e1db5 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -268,7 +268,7 @@ * `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, * `flatten`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, * `forOwnRight`, `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, - * `invert`, `invoke`, `keys`, `map`, `mapValues`, `match`, `max`, `memoize`, + * `invert`, `invoke`, `keys`, `map`, `mapValues`, `matches`, `max`, `memoize`, * `merge`, `min`, `noop`, `object`, `omit`, `once`, `pairs`, `partial`, * `partialRight`, `pick`, `pluck`, `property`, `pull`, `push`, `range`, * `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, @@ -2304,33 +2304,6 @@ } } - /** - * Examines each element in a `collection`, returning the first that - * has the given properties. When checking `properties`, this method - * performs a deep comparison between values to determine if they are - * equivalent to each other. - * - * @static - * @memberOf _ - * @category Collections - * @param {Array|Object|string} collection The collection to iterate over. - * @param {Object} properties The object of property values to filter by. - * @returns {*} Returns the found element, else `undefined`. - * @example - * - * var food = [ - * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - * { 'name': 'banana', 'organic': true, 'type': 'fruit' }, - * { 'name': 'beet', 'organic': false, 'type': 'vegetable' } - * ]; - * - * _.findWhere(food, { 'type': 'vegetable' }); - * // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' } - */ - function findWhere(object, properties) { - return where(object, properties, true); - } - /** * Iterates over elements of a collection, executing the callback for each * element. The callback is bound to `thisArg` and invoked with three arguments; @@ -2371,6 +2344,7 @@ } else { baseEach(collection, callback); } + return collection; } /** @@ -2705,6 +2679,54 @@ return result; } + /** + * Creates an array of elements split into two groups, the first of which + * contains elements the callback returns truey for, while the second of which + * contains elements the callback returns falsey for. The callback is bound + * to `thisArg` and invoked with three arguments; (value, index|key, collection). + * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @category Collections + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function|Object|string} [callback=identity] The function called + * per iteration. If a property name or object is provided it will be used + * to create a "_.pluck" or "_.where" style callback, respectively. + * @param {*} [thisArg] The `this` binding of `callback`. + * @returns {Array} Returns a new array of grouped elements. + * @example + * + * _.partition([1, 2, 3], function(num) { return num % 2; }); + * // => [[1, 3], [2]] + * + * _.partition([1.2, 2.3, 3.4], function(num) { return this.floor(num) % 2; }, Math); + * // => [[1, 3], [2]] + * + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40, 'blocked': true }, + * { 'name': 'pebbles', 'age': 1 } + * ]; + * + * // using "_.where" callback shorthand + * _.map(_.partition(characters, { 'age': 1 }), function(array) { return _.pluck(array, 'name'); }); + * // => [['pebbles'], ['barney', 'fred']] + * + * // using "_.pluck" callback shorthand + * _.map(_.partition(characters, 'blocked'), function(array) { return _.pluck(array, 'name'); }); + * // => [['fred'], ['barney', 'pebbles']] + */ + var partition = createAggregator(function(result, value, key) { + result[key ? 0 : 1].push(value); + }, true); + /** * Retrieves the value of a specified property from all elements in the collection. * @@ -3122,11 +3144,7 @@ * _.where(characters, { 'pets': ['dino'] }); * // => [{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }] */ - function where(collection, properties, first) { - return (first && isEmpty(properties)) - ? undefined - : (first ? find : filter)(collection, properties); - } + var where = filter; /*--------------------------------------------------------------------------*/ @@ -4628,6 +4646,27 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @category Utilities + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new function. + * @example + * + * var object = { 'name': 'fred' }; + * var getter = _.constant(object); + * getter() === object; + * // => true + */ + function constant(value) { + return function() { + return value; + }; + } + /** * Produces a callback bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. @@ -4667,7 +4706,7 @@ func || baseCreateCallback(func, thisArg, argCount); } // handle "_.pluck" and "_.where" style callback shorthands - return type != 'object' ? property(func) : match(func); + return type != 'object' ? property(func) : matches(func); } /** @@ -4705,21 +4744,21 @@ * { 'name': 'barney', 'age': 36 } * ]; * - * var matchAge = _.match({ 'age': 36 }); + * var matchesAge = _.matches({ 'age': 36 }); * - * _.filter(characters, matchAge); + * _.filter(characters, matchesAge); * // => [{ 'name': 'barney', 'age': 36 }] * - * _.find(characters, matchAge); + * _.find(characters, matchesAge); * // => { 'name': 'barney', 'age': 36 } */ - function match(source) { + function matches(source) { source || (source = {}); var props = keys(source); return function(object) { var length = props.length, - result = false; + result = true; while (length--) { var key = props[length]; @@ -5010,6 +5049,7 @@ lodash.chain = chain; lodash.compact = compact; lodash.compose = compose; + lodash.constant = constant; lodash.countBy = countBy; lodash.debounce = debounce; lodash.defaults = defaults; @@ -5028,6 +5068,7 @@ lodash.invoke = invoke; lodash.keys = keys; lodash.map = map; + lodash.matches = matches; lodash.max = max; lodash.memoize = memoize; lodash.min = min; @@ -5035,8 +5076,10 @@ lodash.once = once; lodash.pairs = pairs; lodash.partial = partial; + lodash.partition = partition; lodash.pick = pick; lodash.pluck = pluck; + lodash.property = property; lodash.range = range; lodash.reject = reject; lodash.rest = rest; @@ -5095,6 +5138,7 @@ lodash.lastIndexOf = lastIndexOf; lodash.mixin = mixin; lodash.noConflict = noConflict; + lodash.now = now; lodash.random = random; lodash.reduce = reduce; lodash.reduceRight = reduceRight; @@ -5110,7 +5154,7 @@ lodash.all = every; lodash.any = some; lodash.detect = find; - lodash.findWhere = findWhere; + lodash.findWhere = find; lodash.foldl = reduce; lodash.foldr = reduceRight; lodash.include = contains; diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 0f0e50b5b..7060dbb06 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,38 +3,39 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ -;(function(){function n(n){var r=[];if(!L(n))return r;for(var t in n)Ur.call(n,t)&&r.push(t);return r}function r(n,r){if(L(n))for(var t in n)if(r(n[t],t,n)===sr)break}function t(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function h(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++tu(f,l))&&(t&&f.push(l),i.push(a))}return i}function _(n){return function(r,t,e){var u={};t=Z(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++et&&(t=0),n=[n,r,t,e,u,o],r==or||r==(or|lr)?l(n):s(n)}function w(){var n=(n=f.indexOf)===A?t:n;return n}function j(n){return typeof n=="function"&&Wr.test(Pr.call(n))}function x(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Dr.call(n)==br||false}function T(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=-1;for(r=Z(r,t,3);++oe?Yr(0,u+e):e||0;else if(e)return e=k(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function E(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=Z(r,t,3);++ur?r=Yr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Yr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=Z(r,t,3),h(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function M(n,r,t,e){var u=3>arguments.length;r=Z(r,e,4);var o=-1,i=n?n.length:0; -if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=Z(r,e,4),v(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function W(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return h(n,function(n){var t;t=++r,t=0+Cr(rt()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=Z(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++targuments.length)return d(n,or,null,r);if(n)var t=n[pr]?n[pr][2]:n.length,e=O(arguments,2),t=t-e.length;return d(n,or|lr,t,r,e)}function U(n,r,t){function e(){c&&clearTimeout(c),i=c=p=ur,(h||g!==r)&&(s=lt(),f=n.apply(l,o),c||i||(o=l=null))}function u(){var t=r-(lt()-a);0=y;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(l,o)):i||(i=setTimeout(e,y))}return m&&c?c=clearTimeout(c):c||r===g||(c=setTimeout(u,r)),t&&(m=true,f=n.apply(l,o)),!m||c||i||(o=l=null),f}}function V(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t; -for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,yr=/($^)/,mr=/['\n\r\t\u2028\u2029\\]/g,br="[object Arguments]",_r="[object Array]",dr="[object Boolean]",wr="[object Date]",jr="[object Number]",xr="[object Object]",Tr="[object RegExp]",Ar="[object String]",Er={"&":"&","<":"<",">":">",'"':""","'":"'"},Or={"&":"&","<":"<",">":">",""":'"',"'":"'"},kr={"function":true,object:true},Sr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Nr=kr[typeof window]&&window||this,qr=kr[typeof exports]&&exports&&!exports.nodeType&&exports,Fr=kr[typeof module]&&module&&!module.nodeType&&module,Br=qr&&Fr&&typeof global=="object"&&global; -!Br||Br.global!==Br&&Br.window!==Br&&Br.self!==Br||(Nr=Br);var Rr=Fr&&Fr.exports===qr&&qr,$r=Array.prototype,Ir=Object.prototype,Mr=Nr._,Dr=Ir.toString,Wr=RegExp("^"+(Dr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),zr=Math.ceil,Cr=Math.floor,Pr=Function.prototype.toString,Ur=Ir.hasOwnProperty,Vr=$r.push,Gr=Ir.propertyIsEnumerable,Hr=$r.splice,Jr=j(Jr=Object.create)&&Jr,Kr=j(Kr=Array.isArray)&&Kr,Lr=Nr.isFinite,Qr=Nr.isNaN,Xr=j(Xr=Object.keys)&&Xr,Yr=Math.max,Zr=Math.min,nt=j(nt=Date.now)&&nt,rt=Math.random; -a.prototype=f.prototype;var tt={};!function(){var n={0:1,length:1};tt.spliceObjects=(Hr.call(n,0,1),!n[0])}(1),f.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Jr||(c=function(){function n(){}return function(r){if(L(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Nr.Object()}}()),x(arguments)||(x=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ur.call(n,"callee")&&!Gr.call(n,"callee")||false});var et=_(function(n,r,t){Ur.call(n,t)?n[t]++:n[t]=1 -}),ut=_(function(n,r,t){Ur.call(n,t)?n[t].push(r):n[t]=[r]}),ot=_(function(n,r,t){n[t]=r}),it=$,ft=Kr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Dr.call(n)==_r||false};K(/x/)&&(K=function(n){return typeof n=="function"&&"[object Function]"==Dr.call(n)});var at=Xr?function(n){return L(n)?Xr(n):[]}:n,lt=nt||function(){return(new Date).getTime()};f.after=function(n,r){if(!K(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},f.bind=P,f.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},f.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++rarguments.length&&typeof u=="number")for(;++tr?0:r);++nt?Yr(0,e+t):Zr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},f.mixin=tr,f.noConflict=function(){return Nr._=Mr,this},f.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Cr(rt()*(r-n+1)) -},f.reduce=M,f.reduceRight=D,f.result=function(n,r){if(null!=n){var t=n[r];return K(t)?n[r]():t}},f.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:at(n).length},f.some=z,f.sortedIndex=k,f.template=function(n,r,t){var e=f,u=e.templateSettings;n=(n||"")+"",t=G({},t,u);var i=0,a="__p+='",u=t.variable;n.replace(RegExp((t.escape||yr).source+"|"+(t.interpolate||yr).source+"|"+(t.evaluate||yr).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(mr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r -}),a+="';",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var l=Function("_","return "+a)(e)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},f.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(hr,i))},f.uniqueId=function(n){var r=++gr+"";return n?n+r:r},f.all=q,f.any=z,f.detect=B,f.findWhere=function(n,r){return C(n,r,true)},f.foldl=M,f.foldr=D,f.include=N,f.inject=M,f.first=T,f.last=function(n,r,t){var e=0,u=n?n.length:0; -if(typeof r!="number"&&null!=r){var o=u;for(r=Z(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:ur;return e=u-e,O(n,0e||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function h(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++tu(f,l))&&(t&&f.push(l),i.push(a))}return i}function _(n,r){return function(t,e,u){var o=r?[[],[]]:{};e=X(e,u,3),u=-1;var i=t?t.length:0;if(typeof i=="number")for(;++ut&&(t=0),n=[n,r,t,e,u,o],r==er||r==(er|fr)?l(n):s(n)}function w(){var n=(n=f.indexOf)===A?t:n;return n}function j(n){return typeof n=="function"&&Mr.test(zr.call(n))}function x(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ir.call(n)==yr||false}function T(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=-1;for(r=X(r,t,3);++oe?Qr(0,u+e):e||0;else if(e)return e=k(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function E(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=X(r,t,3);++ur?r=Qr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Qr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=X(r,t,3),h(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function M(n,r,t,e){var u=3>arguments.length;r=X(r,e,4);var o=-1,i=n?n.length:0; +if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=X(r,e,4),v(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function W(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return h(n,function(n){var t;t=++r,t=0+Wr(Zr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=X(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++targuments.length)return d(n,er,null,r);if(n)var t=n[lr]?n[lr][2]:n.length,e=O(arguments,2),t=t-e.length;return d(n,er|fr,t,r,e)}function P(n,r,t){function e(){c&&clearTimeout(c),i=c=p=tr,(h||g!==r)&&(s=lt(),f=n.apply(l,o),c||i||(o=l=null))}function u(){var t=r-(lt()-a);0=y;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(l,o)):i||(i=setTimeout(e,y))}return m&&c?c=clearTimeout(c):c||r===g||(c=setTimeout(u,r)),t&&(m=true,f=n.apply(l,o)),!m||c||i||(o=l=null),f}}function U(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,hr=/($^)/,vr=/['\n\r\t\u2028\u2029\\]/g,yr="[object Arguments]",mr="[object Array]",br="[object Boolean]",_r="[object Date]",dr="[object Number]",wr="[object Object]",jr="[object RegExp]",xr="[object String]",Tr={"&":"&","<":"<",">":">",'"':""","'":"'"},Ar={"&":"&","<":"<",">":">",""":'"',"'":"'"},Er={"function":true,object:true},Or={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},kr=Er[typeof window]&&window||this,Sr=Er[typeof exports]&&exports&&!exports.nodeType&&exports,Nr=Er[typeof module]&&module&&!module.nodeType&&module,qr=Sr&&Nr&&typeof global=="object"&&global; +!qr||qr.global!==qr&&qr.window!==qr&&qr.self!==qr||(kr=qr);var Fr=Nr&&Nr.exports===Sr&&Sr,Br=Array.prototype,Rr=Object.prototype,$r=kr._,Ir=Rr.toString,Mr=RegExp("^"+(Ir+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Dr=Math.ceil,Wr=Math.floor,zr=Function.prototype.toString,Cr=Rr.hasOwnProperty,Pr=Br.push,Ur=Rr.propertyIsEnumerable,Vr=Br.splice,Gr=j(Gr=Object.create)&&Gr,Hr=j(Hr=Array.isArray)&&Hr,Jr=kr.isFinite,Kr=kr.isNaN,Lr=j(Lr=Object.keys)&&Lr,Qr=Math.max,Xr=Math.min,Yr=j(Yr=Date.now)&&Yr,Zr=Math.random; +a.prototype=f.prototype;var nt={};!function(){var n={0:1,length:1};nt.spliceObjects=(Vr.call(n,0,1),!n[0])}(1),f.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Gr||(c=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||kr.Object()}}()),x(arguments)||(x=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Cr.call(n,"callee")&&!Ur.call(n,"callee")||false});var rt=_(function(n,r,t){Cr.call(n,t)?n[t]++:n[t]=1 +}),tt=_(function(n,r,t){Cr.call(n,t)?n[t].push(r):n[t]=[r]}),et=_(function(n,r,t){n[t]=r}),ut=_(function(n,r,t){n[t?0:1].push(r)},true),ot=$,it=F,ft=Hr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ir.call(n)==mr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Ir.call(n)});var at=Lr?function(n){return J(n)?Lr(n):[]}:n,lt=Yr||function(){return(new Date).getTime()};f.after=function(n,r){if(!H(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0 +}},f.bind=C,f.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},f.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++rarguments.length&&typeof u=="number")for(;++tr?0:r);++nt?Qr(0,e+t):Xr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},f.mixin=nr,f.noConflict=function(){return kr._=$r,this},f.now=lt,f.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Wr(Zr()*(r-n+1))},f.reduce=M,f.reduceRight=D,f.result=function(n,r){if(null!=n){var t=n[r];return H(t)?n[r]():t}},f.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:at(n).length},f.some=z,f.sortedIndex=k,f.template=function(n,r,t){var e=f,u=e.templateSettings; +n=(n||"")+"",t=V({},t,u);var i=0,a="__p+='",u=t.variable;n.replace(RegExp((t.escape||hr).source+"|"+(t.interpolate||hr).source+"|"+(t.evaluate||hr).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(vr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r}),a+="';",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; +try{var l=Function("_","return "+a)(e)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},f.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(sr,i))},f.uniqueId=function(n){var r=++pr+"";return n?n+r:r},f.all=q,f.any=z,f.detect=B,f.findWhere=B,f.foldl=M,f.foldr=D,f.include=N,f.inject=M,f.first=T,f.last=function(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=u;for(r=X(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:tr;return e=u-e,O(n,0 1 ? null : true; })), '[[0,1],[2,3,4,5]]', 'handles null return values'); + equal(inspect(_.partition(list, function(x) { if(x < 2) return true; })), '[[0,1],[2,3,4,5]]', 'handles undefined return values'); + }); + + test('uniq', function() { var list = [1, 2, 1, 3, 1, 4]; equal(_.uniq(list).join(', '), '1, 2, 3, 4', 'can find the unique values of an unsorted array'); @@ -101,7 +113,7 @@ $(document).ready(function() { equal(result.join(', '), '1, 2, 3, 4', 'works on an arguments object'); }); - test("intersection", function() { + test('intersection', function() { var stooges = ['moe', 'curly', 'larry'], leaders = ['moe', 'groucho']; equal(_.intersection(stooges, leaders).join(''), 'moe', 'can take the set intersection of two arrays'); equal(_(stooges).intersection(leaders).join(''), 'moe', 'can perform an OO-style intersection'); @@ -111,7 +123,7 @@ $(document).ready(function() { equal(_.intersection(theSixStooges, leaders).join(''), 'moe', 'returns a duplicate-free array'); }); - test("union", function() { + test('union', function() { var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]); equal(result.join(' '), '1 2 3 30 40', 'takes the union of a list of arrays'); @@ -127,7 +139,7 @@ $(document).ready(function() { deepEqual(result, [null, 1, 2, 3]); }); - test("difference", function() { + test('difference', function() { var result = _.difference([1, 2, 3], [2, 30, 40]); equal(result.join(' '), '1 3', 'takes the difference of two arrays'); @@ -167,7 +179,7 @@ $(document).ready(function() { ok(_.isEqual(_.object(null), {}), 'handles nulls'); }); - test("indexOf", function() { + test('indexOf', function() { var numbers = [1, 2, 3]; numbers.indexOf = null; equal(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function'); @@ -193,7 +205,7 @@ $(document).ready(function() { equal(index, 7, 'supports the fromIndex argument'); }); - test("lastIndexOf", function() { + test('lastIndexOf', function() { var numbers = [1, 0, 1]; equal(_.lastIndexOf(numbers, 1), 2); @@ -210,7 +222,7 @@ $(document).ready(function() { equal(index, 1, 'supports the fromIndex argument'); }); - test("range", function() { + test('range', function() { equal(_.range(0).join(''), '', 'range with 0 as a first argument generates an empty array'); equal(_.range(4).join(' '), '0 1 2 3', 'range with a single positive argument generates an array of elements 0,1,2,...,n-1'); equal(_.range(5, 8).join(' '), '5 6 7', 'range with two arguments a & b, a<b generates an array of elements a,a+1,a+2,...,b-2,b-1'); @@ -221,4 +233,4 @@ $(document).ready(function() { equal(_.range(0, -10, -1).join(' '), '0 -1 -2 -3 -4 -5 -6 -7 -8 -9', 'final example in the Python docs'); }); -}); +})(); diff --git a/vendor/underscore/test/chaining.js b/vendor/underscore/test/chaining.js index 6eeef0f87..43afea376 100644 --- a/vendor/underscore/test/chaining.js +++ b/vendor/underscore/test/chaining.js @@ -1,8 +1,8 @@ -$(document).ready(function() { +(function() { - module("Chaining"); + module('Chaining'); - test("map/flatten/reduce", function() { + test('map/flatten/reduce', function() { var lyrics = [ "I'm a lumberjack and I'm okay", "I sleep all night and I work all day", @@ -20,7 +20,7 @@ $(document).ready(function() { ok(counts.a == 16 && counts.e == 10, 'counted all the letters in the song'); }); - test("select/reject/sortBy", function() { + test('select/reject/sortBy', function() { var numbers = [1,2,3,4,5,6,7,8,9,10]; numbers = _(numbers).chain().select(function(n) { return n % 2 === 0; @@ -29,10 +29,10 @@ $(document).ready(function() { }).sortBy(function(n) { return -n; }).value(); - equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers"); + equal(numbers.join(', '), '10, 6, 2', 'filtered and reversed the numbers'); }); - test("select/reject/sortBy in functional style", function() { + test('select/reject/sortBy in functional style', function() { var numbers = [1,2,3,4,5,6,7,8,9,10]; numbers = _.chain(numbers).select(function(n) { return n % 2 === 0; @@ -41,10 +41,10 @@ $(document).ready(function() { }).sortBy(function(n) { return -n; }).value(); - equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers"); + equal(numbers.join(', '), '10, 6, 2', 'filtered and reversed the numbers'); }); - test("reverse/concat/unshift/pop/map", function() { + test('reverse/concat/unshift/pop/map', function() { var numbers = [1,2,3,4,5]; numbers = _(numbers).chain() .reverse() @@ -53,13 +53,13 @@ $(document).ready(function() { .pop() .map(function(n){ return n * 2; }) .value(); - equal(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.'); + equal(numbers.join(', '), '34, 10, 8, 6, 4, 2, 10, 10', 'can chain together array functions.'); }); - test("chaining works in small stages", function() { + test('chaining works in small stages', function() { var o = _([1, 2, 3, 4]).chain(); deepEqual(o.filter(function(i) { return i < 3; }).value(), [1, 2]); deepEqual(o.filter(function(i) { return i > 2; }).value(), [3, 4]); }); -}); +})(); diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index 82176ad01..eb3d07e74 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -1,8 +1,8 @@ -$(document).ready(function() { +(function() { - module("Collections"); + module('Collections'); - test("each", function() { + test('each', function() { _.each([1, 2, 3], function(num, i) { equal(num, i + 1, 'each iterators provide value and iteration count'); }); @@ -19,7 +19,7 @@ $(document).ready(function() { var obj = {one : 1, two : 2, three : 3}; obj.constructor.prototype.four = 4; _.each(obj, function(value, key){ answers.push(key); }); - equal(answers.join(", "), 'one, two, three', 'iterating over objects works, and ignores the object prototype.'); + equal(answers.join(', '), 'one, two, three', 'iterating over objects works, and ignores the object prototype.'); delete obj.constructor.prototype.four; var answer = null; @@ -29,6 +29,12 @@ $(document).ready(function() { answers = 0; _.each(null, function(){ ++answers; }); equal(answers, 0, 'handles a null properly'); + + _.each(false, function(){}); + + var a = [1, 2, 3]; + strictEqual(_.each(a, function(){}), a); + strictEqual(_.each(null, function(){}), null); }); test('map', function() { @@ -49,11 +55,10 @@ $(document).ready(function() { deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on NodeLists.'); } - var ids = _.map($('#map-test').children(), function(n){ return n.id; }); - deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on jQuery Array-likes.'); - - var ids = _.map(document.images, function(n){ return n.id; }); - ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections'); + var ids = _.map({length: 2, 0: {id: '1'}, 1: {id: '2'}}, function(n){ + return n.id; + }); + deepEqual(ids, ['1', '2'], 'Can use collection methods on Array-likes.'); var ifnull = _.map(null, function(){}); ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly'); @@ -93,13 +98,13 @@ $(document).ready(function() { }); test('reduceRight', function() { - var list = _.reduceRight(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, ''); + var list = _.reduceRight(['foo', 'bar', 'baz'], function(memo, str){ return memo + str; }, ''); equal(list, 'bazbarfoo', 'can perform right folds'); - var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, ''); + var list = _.foldr(['foo', 'bar', 'baz'], function(memo, str){ return memo + str; }, ''); equal(list, 'bazbarfoo', 'aliased as "foldr"'); - var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; }); + var list = _.foldr(['foo', 'bar', 'baz'], function(memo, str){ return memo + str; }); equal(list, 'bazbarfoo', 'default initial value'); var ifnull; @@ -175,10 +180,10 @@ $(document).ready(function() { var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; }); equal(odds.join(', '), '1, 3, 5', 'rejected each even number'); - var context = "obj"; + var context = 'obj'; var evens = _.reject([1, 2, 3, 4, 5, 6], function(num){ - equal(context, "obj"); + equal(context, 'obj'); return num % 2 != 0; }, context); equal(evens.join(', '), '2, 4, 6', 'rejected each odd number'); @@ -239,13 +244,13 @@ $(document).ready(function() { return 42; }; var list = [[5, 1, 7], [3, 2, 1]]; - var s = "foo"; - equal(s.call(), 42, "call function exists"); + var s = 'foo'; + equal(s.call(), 42, 'call function exists'); var result = _.invoke(list, 'sort'); equal(result[0].join(', '), '1, 5, 7', 'first array sorted'); equal(result[1].join(', '), '1, 2, 3', 'second array sorted'); delete String.prototype.call; - equal(s.call, undefined, "call function removed"); + equal(s.call, undefined, 'call function removed'); }); test('pluck', function() { @@ -261,11 +266,8 @@ $(document).ready(function() { result = _.where(list, {b: 2}); equal(result.length, 2); equal(result[0].a, 1); - - result = _.where(list, {a: 1}, true); - equal(result.b, 2, "Only get the first object matched.") - result = _.where(list, {a: 1}, false); - equal(result.length, 3); + result = _.where(list, {}); + equal(result.length, list.length); }); test('findWhere', function() { @@ -276,10 +278,10 @@ $(document).ready(function() { deepEqual(result, {a: 1, b: 4}); result = _.findWhere(list, {c:1}) - ok(_.isUndefined(result), "undefined when not found"); + ok(_.isUndefined(result), 'undefined when not found'); result = _.findWhere([], {c:1}); - ok(_.isUndefined(result), "undefined when searching empty list"); + ok(_.isUndefined(result), 'undefined when searching empty list'); }); test('max', function() { @@ -292,7 +294,7 @@ $(document).ready(function() { equal(-Infinity, _.max([]), 'Maximum value of an empty array'); equal(_.max({'a': 'a'}), -Infinity, 'Maximum value of a non-numeric collection'); - equal(299999, _.max(_.range(1,300000)), "Maximum value of a too-big array"); + equal(299999, _.max(_.range(1,300000)), 'Maximum value of a too-big array'); }); test('min', function() { @@ -309,7 +311,7 @@ $(document).ready(function() { var then = new Date(0); equal(_.min([now, then]), then); - equal(1, _.min(_.range(1,300000)), "Minimum value of a too-big array"); + equal(1, _.min(_.range(1,300000)), 'Minimum value of a too-big array'); }); test('sortBy', function() { @@ -320,7 +322,7 @@ $(document).ready(function() { var list = [undefined, 4, 1, undefined, 3, 2]; equal(_.sortBy(list, _.identity).join(','), '1,2,3,4,,', 'sortBy with undefined values'); - var list = ["one", "two", "three", "four", "five"]; + var list = ['one', 'two', 'three', 'four', 'five']; var sorted = _.sortBy(list, 'length'); equal(sorted.join(' '), 'one two four five three', 'sorted by length'); @@ -346,6 +348,9 @@ $(document).ready(function() { }); deepEqual(actual, collection, 'sortBy should be stable'); + + var list = ['q', 'w', 'e', 'r', 't', 'y']; + strictEqual(_.sortBy(list).join(''), 'eqrtwy', 'uses _.identity if iterator is not specified'); }); test('groupBy', function() { @@ -353,7 +358,7 @@ $(document).ready(function() { ok('0' in parity && '1' in parity, 'created a group for each value'); equal(parity[0].join(', '), '2, 4, 6', 'put each even number in the right group'); - var list = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; + var list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']; var grouped = _.groupBy(list, 'length'); equal(grouped['3'].join(' '), 'one two six ten'); equal(grouped['4'].join(' '), 'four five nine'); @@ -390,7 +395,7 @@ $(document).ready(function() { equal(parity['true'], 4); equal(parity['false'], 5); - var list = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; + var list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']; var grouped = _.indexBy(list, 'length'); equal(grouped['3'], 'ten'); equal(grouped['4'], 'nine'); @@ -408,7 +413,7 @@ $(document).ready(function() { equal(parity['true'], 2); equal(parity['false'], 3); - var list = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; + var list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']; var grouped = _.countBy(list, 'length'); equal(grouped['3'], 4); equal(grouped['4'], 3); @@ -468,6 +473,7 @@ $(document).ready(function() { notStrictEqual(_.sample([], 5), [], 'sampling empty array with a number returns an empty array'); notStrictEqual(_.sample([1, 2, 3], 0), [], 'sampling an array with 0 picks returns an empty array'); deepEqual(_.sample([1, 2], -1), [], 'sampling a negative number of picks returns an empty array'); + ok(_.contains([1, 2, 3], _.sample({a: 1, b: 2, c: 3})), 'sample one value from an object'); }); test('toArray', function() { @@ -491,7 +497,7 @@ $(document).ready(function() { test('size', function() { equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object'); equal(_.size([1, 2, 3]), 3, 'can compute the size of an array'); - equal(_.size($('
').add('').add('')), 3, 'can compute the size of jQuery objects'); + equal(_.size({length: 3, 0: 0, 1: 0, 2: 0}), 3, 'can compute the size of Array-likes'); var func = function() { return _.size(arguments); @@ -505,4 +511,4 @@ $(document).ready(function() { equal(_.size(null), 0, 'handles nulls'); }); -}); +})(); diff --git a/vendor/underscore/test/functions.js b/vendor/underscore/test/functions.js index 7a773f32e..14ea934c2 100644 --- a/vendor/underscore/test/functions.js +++ b/vendor/underscore/test/functions.js @@ -1,10 +1,10 @@ -$(document).ready(function() { +(function() { - module("Functions"); + module('Functions'); - test("bind", function() { + test('bind', function() { var context = {name : 'moe'}; - var func = function(arg) { return "name: " + (this.name || arg); }; + var func = function(arg) { return 'name: ' + (this.name || arg); }; var bound = _.bind(func, context); equal(bound(), 'name: moe', 'can bind a function to a context'); @@ -33,22 +33,32 @@ $(document).ready(function() { // These tests are only meaningful when using a browser without a native bind function // To test this with a modern browser, set underscore's nativeBind to undefined var F = function () { return this; }; - var Boundf = _.bind(F, {hello: "moe curly"}); + var Boundf = _.bind(F, {hello: 'moe curly'}); var newBoundf = new Boundf(); - equal(newBoundf.hello, undefined, "function should not be bound to the context, to comply with ECMAScript 5"); - equal(Boundf().hello, "moe curly", "When called without the new operator, it's OK to be bound to the context"); - ok(newBoundf instanceof F, "a bound instance is an instance of the original function"); + equal(newBoundf.hello, undefined, 'function should not be bound to the context, to comply with ECMAScript 5'); + equal(Boundf().hello, 'moe curly', "When called without the new operator, it's OK to be bound to the context"); + ok(newBoundf instanceof F, 'a bound instance is an instance of the original function'); }); - test("partial", function() { + test('partial', function() { var obj = {name: 'moe'}; var func = function() { return this.name + ' ' + _.toArray(arguments).join(' '); }; obj.func = _.partial(func, 'a', 'b'); equal(obj.func('c', 'd'), 'moe a b c d', 'can partially apply'); + + obj.func = _.partial(func, _, 'b', _, 'd'); + equal(obj.func('a', 'c'), 'moe a b c d', 'can partially apply with placeholders'); + + func = _.partial(function() { return arguments.length; }, _, 'b', _, 'd'); + equal(func('a', 'c', 'e'), 5, 'accepts more arguments than the number of placeholders'); + equal(func('a'), 4, 'accepts fewer arguments than the number of placeholders'); + + func = _.partial(function() { return typeof arguments[2]; }, _, 'b', _, 'd'); + equal(func('a'), 'undefined', 'unfilled placeholders are undefined'); }); - test("bindAll", function() { + test('bindAll', function() { var curly = {name : 'curly'}, moe = { name : 'moe', getName : function() { return 'name: ' + this.name; }, @@ -74,7 +84,7 @@ $(document).ready(function() { equal(curly.sayHi(), 'hi: moe'); }); - test("memoize", function() { + test('memoize', function() { var fib = function(n) { return n < 2 ? n : fib(n - 1) + fib(n - 2); }; @@ -90,59 +100,59 @@ $(document).ready(function() { equal(fastO('toString'), 'toString', 'checks hasOwnProperty'); }); - asyncTest("delay", 2, function() { + asyncTest('delay', 2, function() { var delayed = false; _.delay(function(){ delayed = true; }, 100); setTimeout(function(){ ok(!delayed, "didn't delay the function quite yet"); }, 50); setTimeout(function(){ ok(delayed, 'delayed the function'); start(); }, 150); }); - asyncTest("defer", 1, function() { + asyncTest('defer', 1, function() { var deferred = false; _.defer(function(bool){ deferred = bool; }, true); - _.delay(function(){ ok(deferred, "deferred the function"); start(); }, 50); + _.delay(function(){ ok(deferred, 'deferred the function'); start(); }, 50); }); - asyncTest("throttle", 2, function() { + asyncTest('throttle', 2, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 32); throttledIncr(); throttledIncr(); - equal(counter, 1, "incr was called immediately"); - _.delay(function(){ equal(counter, 2, "incr was throttled"); start(); }, 64); + equal(counter, 1, 'incr was called immediately'); + _.delay(function(){ equal(counter, 2, 'incr was throttled'); start(); }, 64); }); - asyncTest("throttle arguments", 2, function() { + asyncTest('throttle arguments', 2, function() { var value = 0; var update = function(val){ value = val; }; var throttledUpdate = _.throttle(update, 32); throttledUpdate(1); throttledUpdate(2); _.delay(function(){ throttledUpdate(3); }, 64); - equal(value, 1, "updated to latest value"); - _.delay(function(){ equal(value, 3, "updated to latest value"); start(); }, 96); + equal(value, 1, 'updated to latest value'); + _.delay(function(){ equal(value, 3, 'updated to latest value'); start(); }, 96); }); - asyncTest("throttle once", 2, function() { + asyncTest('throttle once', 2, function() { var counter = 0; var incr = function(){ return ++counter; }; var throttledIncr = _.throttle(incr, 32); var result = throttledIncr(); _.delay(function(){ - equal(result, 1, "throttled functions return their value"); - equal(counter, 1, "incr was called once"); start(); + equal(result, 1, 'throttled functions return their value'); + equal(counter, 1, 'incr was called once'); start(); }, 64); }); - asyncTest("throttle twice", 1, function() { + asyncTest('throttle twice', 1, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 32); throttledIncr(); throttledIncr(); - _.delay(function(){ equal(counter, 2, "incr was called twice"); start(); }, 64); + _.delay(function(){ equal(counter, 2, 'incr was called twice'); start(); }, 64); }); - asyncTest("more throttling", 3, function() { + asyncTest('more throttling', 3, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 30); @@ -156,7 +166,7 @@ $(document).ready(function() { }, 85); }); - asyncTest("throttle repeatedly with results", 6, function() { + asyncTest('throttle repeatedly with results', 6, function() { var counter = 0; var incr = function(){ return ++counter; }; var throttledIncr = _.throttle(incr, 100); @@ -168,17 +178,17 @@ $(document).ready(function() { _.delay(saveResult, 160); _.delay(saveResult, 230); _.delay(function() { - equal(results[0], 1, "incr was called once"); - equal(results[1], 1, "incr was throttled"); - equal(results[2], 1, "incr was throttled"); - equal(results[3], 2, "incr was called twice"); - equal(results[4], 2, "incr was throttled"); - equal(results[5], 3, "incr was called trailing"); + equal(results[0], 1, 'incr was called once'); + equal(results[1], 1, 'incr was throttled'); + equal(results[2], 1, 'incr was throttled'); + equal(results[3], 2, 'incr was called twice'); + equal(results[4], 2, 'incr was throttled'); + equal(results[5], 3, 'incr was called trailing'); start(); }, 300); }); - asyncTest("throttle triggers trailing call when invoked repeatedly", 2, function() { + asyncTest('throttle triggers trailing call when invoked repeatedly', 2, function() { var counter = 0; var limit = 48; var incr = function(){ counter++; }; @@ -197,7 +207,7 @@ $(document).ready(function() { }, 96); }); - asyncTest("throttle does not trigger leading call when leading is set to false", 2, function() { + asyncTest('throttle does not trigger leading call when leading is set to false', 2, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 60, {leading: false}); @@ -211,7 +221,7 @@ $(document).ready(function() { }, 96); }); - asyncTest("more throttle does not trigger leading call when leading is set to false", 3, function() { + asyncTest('more throttle does not trigger leading call when leading is set to false', 3, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 100, {leading: false}); @@ -232,7 +242,7 @@ $(document).ready(function() { }, 350); }); - asyncTest("one more throttle with leading: false test", 2, function() { + asyncTest('one more throttle with leading: false test', 2, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 100, {leading: false}); @@ -247,7 +257,7 @@ $(document).ready(function() { }, 200); }); - asyncTest("throttle does not trigger trailing call when trailing is set to false", 4, function() { + asyncTest('throttle does not trigger trailing call when trailing is set to false', 4, function() { var counter = 0; var incr = function(){ counter++; }; var throttledIncr = _.throttle(incr, 60, {trailing: false}); @@ -268,16 +278,16 @@ $(document).ready(function() { }, 96); }); - asyncTest("debounce", 1, function() { + asyncTest('debounce', 1, function() { var counter = 0; var incr = function(){ counter++; }; var debouncedIncr = _.debounce(incr, 32); debouncedIncr(); debouncedIncr(); _.delay(debouncedIncr, 16); - _.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 96); + _.delay(function(){ equal(counter, 1, 'incr was debounced'); start(); }, 96); }); - asyncTest("debounce asap", 4, function() { + asyncTest('debounce asap', 4, function() { var a, b; var counter = 0; var incr = function(){ return ++counter; }; @@ -290,21 +300,21 @@ $(document).ready(function() { _.delay(debouncedIncr, 16); _.delay(debouncedIncr, 32); _.delay(debouncedIncr, 48); - _.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 128); + _.delay(function(){ equal(counter, 1, 'incr was debounced'); start(); }, 128); }); - asyncTest("debounce asap recursively", 2, function() { + asyncTest('debounce asap recursively', 2, function() { var counter = 0; var debouncedIncr = _.debounce(function(){ counter++; if (counter < 10) debouncedIncr(); }, 32, true); debouncedIncr(); - equal(counter, 1, "incr was called immediately"); - _.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 96); + equal(counter, 1, 'incr was called immediately'); + _.delay(function(){ equal(counter, 1, 'incr was debounced'); start(); }, 96); }); - test("once", function() { + test('once', function() { var num = 0; var increment = _.once(function(){ num++; }); increment(); @@ -312,7 +322,7 @@ $(document).ready(function() { equal(num, 1); }); - test("Recursive onced function.", 1, function() { + test('Recursive onced function.', 1, function() { var f = _.once(function(){ ok(true); f(); @@ -320,15 +330,15 @@ $(document).ready(function() { f(); }); - test("wrap", function() { - var greet = function(name){ return "hi: " + name; }; + test('wrap', function() { + var greet = function(name){ return 'hi: ' + name; }; var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); }); equal(backwards('moe'), 'hi: moe eom', 'wrapped the salutation function'); - var inner = function(){ return "Hello "; }; - var obj = {name : "Moe"}; + var inner = function(){ return 'Hello '; }; + var obj = {name : 'Moe'}; obj.hi = _.wrap(inner, function(fn){ return fn() + this.name; }); - equal(obj.hi(), "Hello Moe"); + equal(obj.hi(), 'Hello Moe'); var noop = function(){}; var wrapped = _.wrap(noop, function(fn){ return Array.prototype.slice.call(arguments, 0); }); @@ -336,8 +346,8 @@ $(document).ready(function() { deepEqual(ret, [noop, ['whats', 'your'], 'vector', 'victor']); }); - test("compose", function() { - var greet = function(name){ return "hi: " + name; }; + test('compose', function() { + var greet = function(name){ return 'hi: ' + name; }; var exclaim = function(sentence){ return sentence + '!'; }; var composed = _.compose(exclaim, greet); equal(composed('moe'), 'hi: moe!', 'can compose a function that takes another'); @@ -346,7 +356,7 @@ $(document).ready(function() { equal(composed('moe'), 'hi: moe!', 'in this case, the functions are also commutative'); }); - test("after", function() { + test('after', function() { var testAfter = function(afterAmount, timesCalled) { var afterCalled = 0; var after = _.after(afterAmount, function() { @@ -356,10 +366,10 @@ $(document).ready(function() { return afterCalled; }; - equal(testAfter(5, 5), 1, "after(N) should fire after being called N times"); - equal(testAfter(5, 4), 0, "after(N) should not fire unless called N times"); - equal(testAfter(0, 0), 0, "after(0) should not fire immediately"); - equal(testAfter(0, 1), 1, "after(0) should fire when first invoked"); + equal(testAfter(5, 5), 1, 'after(N) should fire after being called N times'); + equal(testAfter(5, 4), 0, 'after(N) should not fire unless called N times'); + equal(testAfter(0, 0), 0, 'after(0) should not fire immediately'); + equal(testAfter(0, 1), 1, 'after(0) should fire when first invoked'); }); -}); +})(); diff --git a/vendor/underscore/test/objects.js b/vendor/underscore/test/objects.js index 492171e06..4ea85c45a 100644 --- a/vendor/underscore/test/objects.js +++ b/vendor/underscore/test/objects.js @@ -1,30 +1,30 @@ -$(document).ready(function() { +(function() { - module("Objects"); + module('Objects'); - test("keys", function() { + test('keys', function() { equal(_.keys({one : 1, two : 2}).join(', '), 'one, two', 'can extract the keys from an object'); // the test above is not safe because it relies on for-in enumeration order var a = []; a[1] = 0; equal(_.keys(a).join(', '), '1', 'is not fooled by sparse arrays; see issue #95'); - raises(function() { _.keys(null); }, TypeError, 'throws an error for `null` values'); - raises(function() { _.keys(void 0); }, TypeError, 'throws an error for `undefined` values'); - raises(function() { _.keys(1); }, TypeError, 'throws an error for number primitives'); - raises(function() { _.keys('a'); }, TypeError, 'throws an error for string primitives'); - raises(function() { _.keys(true); }, TypeError, 'throws an error for boolean primitives'); + deepEqual(_.keys(null), []); + deepEqual(_.keys(void 0), []); + deepEqual(_.keys(1), []); + deepEqual(_.keys('a'), []); + deepEqual(_.keys(true), []); }); - test("values", function() { + test('values', function() { equal(_.values({one: 1, two: 2}).join(', '), '1, 2', 'can extract the values from an object'); equal(_.values({one: 1, two: 2, length: 3}).join(', '), '1, 2, 3', '... even when one of them is "length"'); }); - test("pairs", function() { + test('pairs', function() { deepEqual(_.pairs({one: 1, two: 2}), [['one', 1], ['two', 2]], 'can convert an object into pairs'); deepEqual(_.pairs({one: 1, two: 2, length: 3}), [['one', 1], ['two', 2], ['length', 3]], '... even when one of them is "length"'); }); - test("invert", function() { + test('invert', function() { var obj = {first: 'Moe', second: 'Larry', third: 'Curly'}; equal(_.keys(_.invert(obj)).join(' '), 'Moe Larry Curly', 'can invert an object'); ok(_.isEqual(_.invert(_.invert(obj)), obj), 'two inverts gets you back where you started'); @@ -33,7 +33,7 @@ $(document).ready(function() { ok(_.invert(obj)['3'] == 'length', 'can invert an object with "length"') }); - test("functions", function() { + test('functions', function() { var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce}; ok(_.isEqual(['b', 'd'], _.functions(obj)), 'can grab the function names of any passed-in object'); @@ -42,7 +42,7 @@ $(document).ready(function() { equal(_.functions(new Animal).join(''), 'run', 'also looks up functions on the prototype'); }); - test("extend", function() { + test('extend', function() { var result; equal(_.extend({}, {a:'b'}).a, 'b', 'can extend an object with the attributes of another'); equal(_.extend({a:'x'}, {a:'b'}).a, 'b', 'properties in source override destination'); @@ -62,7 +62,7 @@ $(document).ready(function() { equal(result.a, 1, 'should not error on `null` or `undefined` sources'); }); - test("pick", function() { + test('pick', function() { var result; result = _.pick({a:1, b:2, c:3}, 'a', 'c'); ok(_.isEqual(result, {a:1, c:3}), 'can restrict properties to those named'); @@ -76,7 +76,7 @@ $(document).ready(function() { ok(_.isEqual(_.pick(new Obj, 'a', 'c'), {a:1, c: 3}), 'include prototype props'); }); - test("omit", function() { + test('omit', function() { var result; result = _.omit({a:1, b:2, c:3}, 'b'); ok(_.isEqual(result, {a:1, c:3}), 'can omit a single named property'); @@ -90,9 +90,9 @@ $(document).ready(function() { ok(_.isEqual(_.omit(new Obj, 'b'), {a:1, c: 3}), 'include prototype props'); }); - test("defaults", function() { + test('defaults', function() { var result; - var options = {zero: 0, one: 1, empty: "", nan: NaN, nothing: null}; + var options = {zero: 0, one: 1, empty: '', nan: NaN, nothing: null}; _.defaults(options, {zero: 1, one: 10, twenty: 20, nothing: 'str'}); equal(options.zero, 0, 'value exists'); @@ -100,10 +100,10 @@ $(document).ready(function() { equal(options.twenty, 20, 'default applied'); equal(options.nothing, null, "null isn't overridden"); - _.defaults(options, {empty: "full"}, {nan: "nan"}, {word: "word"}, {word: "dog"}); - equal(options.empty, "", 'value exists'); + _.defaults(options, {empty: 'full'}, {nan: 'nan'}, {word: 'word'}, {word: 'dog'}); + equal(options.empty, '', 'value exists'); ok(_.isNaN(options.nan), "NaN isn't overridden"); - equal(options.word, "word", 'new value is added, first one wins'); + equal(options.word, 'word', 'new value is added, first one wins'); try { options = {}; @@ -113,7 +113,7 @@ $(document).ready(function() { equal(options.a, 1, 'should not error on `null` or `undefined` sources'); }); - test("clone", function() { + test('clone', function() { var moe = {name : 'moe', lucky : [13, 27, 34]}; var clone = _.clone(moe); equal(clone.name, 'moe', 'the clone as the attributes of the original'); @@ -129,7 +129,7 @@ $(document).ready(function() { equal(_.clone(null), null, 'non objects should not be changed by clone'); }); - test("isEqual", function() { + test('isEqual', function() { function First() { this.value = 1; } @@ -140,133 +140,134 @@ $(document).ready(function() { Second.prototype.value = 2; // Basic equality and identity comparisons. - ok(_.isEqual(null, null), "`null` is equal to `null`"); - ok(_.isEqual(), "`undefined` is equal to `undefined`"); + ok(_.isEqual(null, null), '`null` is equal to `null`'); + ok(_.isEqual(), '`undefined` is equal to `undefined`'); - ok(!_.isEqual(0, -0), "`0` is not equal to `-0`"); - ok(!_.isEqual(-0, 0), "Commutative equality is implemented for `0` and `-0`"); - ok(!_.isEqual(null, undefined), "`null` is not equal to `undefined`"); - ok(!_.isEqual(undefined, null), "Commutative equality is implemented for `null` and `undefined`"); + ok(!_.isEqual(0, -0), '`0` is not equal to `-0`'); + ok(!_.isEqual(-0, 0), 'Commutative equality is implemented for `0` and `-0`'); + ok(!_.isEqual(null, undefined), '`null` is not equal to `undefined`'); + ok(!_.isEqual(undefined, null), 'Commutative equality is implemented for `null` and `undefined`'); // String object and primitive comparisons. - ok(_.isEqual("Curly", "Curly"), "Identical string primitives are equal"); - ok(_.isEqual(new String("Curly"), new String("Curly")), "String objects with identical primitive values are equal"); - ok(_.isEqual(new String("Curly"), "Curly"), "String primitives and their corresponding object wrappers are equal"); - ok(_.isEqual("Curly", new String("Curly")), "Commutative equality is implemented for string objects and primitives"); + ok(_.isEqual('Curly', 'Curly'), 'Identical string primitives are equal'); + ok(_.isEqual(new String('Curly'), new String('Curly')), 'String objects with identical primitive values are equal'); + ok(_.isEqual(new String('Curly'), 'Curly'), 'String primitives and their corresponding object wrappers are equal'); + ok(_.isEqual('Curly', new String('Curly')), 'Commutative equality is implemented for string objects and primitives'); - ok(!_.isEqual("Curly", "Larry"), "String primitives with different values are not equal"); - ok(!_.isEqual(new String("Curly"), new String("Larry")), "String objects with different primitive values are not equal"); - ok(!_.isEqual(new String("Curly"), {toString: function(){ return "Curly"; }}), "String objects and objects with a custom `toString` method are not equal"); + ok(!_.isEqual('Curly', 'Larry'), 'String primitives with different values are not equal'); + ok(!_.isEqual(new String('Curly'), new String('Larry')), 'String objects with different primitive values are not equal'); + ok(!_.isEqual(new String('Curly'), {toString: function(){ return 'Curly'; }}), 'String objects and objects with a custom `toString` method are not equal'); // Number object and primitive comparisons. - ok(_.isEqual(75, 75), "Identical number primitives are equal"); - ok(_.isEqual(new Number(75), new Number(75)), "Number objects with identical primitive values are equal"); - ok(_.isEqual(75, new Number(75)), "Number primitives and their corresponding object wrappers are equal"); - ok(_.isEqual(new Number(75), 75), "Commutative equality is implemented for number objects and primitives"); - ok(!_.isEqual(new Number(0), -0), "`new Number(0)` and `-0` are not equal"); - ok(!_.isEqual(0, new Number(-0)), "Commutative equality is implemented for `new Number(0)` and `-0`"); + ok(_.isEqual(75, 75), 'Identical number primitives are equal'); + ok(_.isEqual(new Number(75), new Number(75)), 'Number objects with identical primitive values are equal'); + ok(_.isEqual(75, new Number(75)), 'Number primitives and their corresponding object wrappers are equal'); + ok(_.isEqual(new Number(75), 75), 'Commutative equality is implemented for number objects and primitives'); + ok(!_.isEqual(new Number(0), -0), '`new Number(0)` and `-0` are not equal'); + ok(!_.isEqual(0, new Number(-0)), 'Commutative equality is implemented for `new Number(0)` and `-0`'); - ok(!_.isEqual(new Number(75), new Number(63)), "Number objects with different primitive values are not equal"); - ok(!_.isEqual(new Number(63), {valueOf: function(){ return 63; }}), "Number objects and objects with a `valueOf` method are not equal"); + ok(!_.isEqual(new Number(75), new Number(63)), 'Number objects with different primitive values are not equal'); + ok(!_.isEqual(new Number(63), {valueOf: function(){ return 63; }}), 'Number objects and objects with a `valueOf` method are not equal'); // Comparisons involving `NaN`. - ok(_.isEqual(NaN, NaN), "`NaN` is equal to `NaN`"); - ok(!_.isEqual(61, NaN), "A number primitive is not equal to `NaN`"); - ok(!_.isEqual(new Number(79), NaN), "A number object is not equal to `NaN`"); - ok(!_.isEqual(Infinity, NaN), "`Infinity` is not equal to `NaN`"); + ok(_.isEqual(NaN, NaN), '`NaN` is equal to `NaN`'); + ok(!_.isEqual(61, NaN), 'A number primitive is not equal to `NaN`'); + ok(!_.isEqual(new Number(79), NaN), 'A number object is not equal to `NaN`'); + ok(!_.isEqual(Infinity, NaN), '`Infinity` is not equal to `NaN`'); // Boolean object and primitive comparisons. - ok(_.isEqual(true, true), "Identical boolean primitives are equal"); - ok(_.isEqual(new Boolean, new Boolean), "Boolean objects with identical primitive values are equal"); - ok(_.isEqual(true, new Boolean(true)), "Boolean primitives and their corresponding object wrappers are equal"); - ok(_.isEqual(new Boolean(true), true), "Commutative equality is implemented for booleans"); - ok(!_.isEqual(new Boolean(true), new Boolean), "Boolean objects with different primitive values are not equal"); + ok(_.isEqual(true, true), 'Identical boolean primitives are equal'); + ok(_.isEqual(new Boolean, new Boolean), 'Boolean objects with identical primitive values are equal'); + ok(_.isEqual(true, new Boolean(true)), 'Boolean primitives and their corresponding object wrappers are equal'); + ok(_.isEqual(new Boolean(true), true), 'Commutative equality is implemented for booleans'); + ok(!_.isEqual(new Boolean(true), new Boolean), 'Boolean objects with different primitive values are not equal'); // Common type coercions. - ok(!_.isEqual(true, new Boolean(false)), "Boolean objects are not equal to the boolean primitive `true`"); - ok(!_.isEqual("75", 75), "String and number primitives with like values are not equal"); - ok(!_.isEqual(new Number(63), new String(63)), "String and number objects with like values are not equal"); - ok(!_.isEqual(75, "75"), "Commutative equality is implemented for like string and number values"); - ok(!_.isEqual(0, ""), "Number and string primitives with like values are not equal"); - ok(!_.isEqual(1, true), "Number and boolean primitives with like values are not equal"); - ok(!_.isEqual(new Boolean(false), new Number(0)), "Boolean and number objects with like values are not equal"); - ok(!_.isEqual(false, new String("")), "Boolean primitives and string objects with like values are not equal"); - ok(!_.isEqual(12564504e5, new Date(2009, 9, 25)), "Dates and their corresponding numeric primitive values are not equal"); + ok(!_.isEqual(new Boolean(false), true), '`new Boolean(false)` is not equal to `true`'); + ok(!_.isEqual('75', 75), 'String and number primitives with like values are not equal'); + ok(!_.isEqual(new Number(63), new String(63)), 'String and number objects with like values are not equal'); + ok(!_.isEqual(75, '75'), 'Commutative equality is implemented for like string and number values'); + ok(!_.isEqual(0, ''), 'Number and string primitives with like values are not equal'); + ok(!_.isEqual(1, true), 'Number and boolean primitives with like values are not equal'); + ok(!_.isEqual(new Boolean(false), new Number(0)), 'Boolean and number objects with like values are not equal'); + ok(!_.isEqual(false, new String('')), 'Boolean primitives and string objects with like values are not equal'); + ok(!_.isEqual(12564504e5, new Date(2009, 9, 25)), 'Dates and their corresponding numeric primitive values are not equal'); // Dates. - ok(_.isEqual(new Date(2009, 9, 25), new Date(2009, 9, 25)), "Date objects referencing identical times are equal"); - ok(!_.isEqual(new Date(2009, 9, 25), new Date(2009, 11, 13)), "Date objects referencing different times are not equal"); + ok(_.isEqual(new Date(2009, 9, 25), new Date(2009, 9, 25)), 'Date objects referencing identical times are equal'); + ok(!_.isEqual(new Date(2009, 9, 25), new Date(2009, 11, 13)), 'Date objects referencing different times are not equal'); ok(!_.isEqual(new Date(2009, 11, 13), { getTime: function(){ return 12606876e5; } - }), "Date objects and objects with a `getTime` method are not equal"); - ok(!_.isEqual(new Date("Curly"), new Date("Curly")), "Invalid dates are not equal"); + }), 'Date objects and objects with a `getTime` method are not equal'); + ok(!_.isEqual(new Date('Curly'), new Date('Curly')), 'Invalid dates are not equal'); // Functions. - ok(!_.isEqual(First, Second), "Different functions with identical bodies and source code representations are not equal"); + ok(!_.isEqual(First, Second), 'Different functions with identical bodies and source code representations are not equal'); // RegExps. - ok(_.isEqual(/(?:)/gim, /(?:)/gim), "RegExps with equivalent patterns and flags are equal"); - ok(!_.isEqual(/(?:)/g, /(?:)/gi), "RegExps with equivalent patterns and different flags are not equal"); - ok(!_.isEqual(/Moe/gim, /Curly/gim), "RegExps with different patterns and equivalent flags are not equal"); - ok(!_.isEqual(/(?:)/gi, /(?:)/g), "Commutative equality is implemented for RegExps"); - ok(!_.isEqual(/Curly/g, {source: "Larry", global: true, ignoreCase: false, multiline: false}), "RegExps and RegExp-like objects are not equal"); + ok(_.isEqual(/(?:)/gim, /(?:)/gim), 'RegExps with equivalent patterns and flags are equal'); + ok(_.isEqual(/(?:)/gi, /(?:)/ig), 'Flag order is not significant'); + ok(!_.isEqual(/(?:)/g, /(?:)/gi), 'RegExps with equivalent patterns and different flags are not equal'); + ok(!_.isEqual(/Moe/gim, /Curly/gim), 'RegExps with different patterns and equivalent flags are not equal'); + ok(!_.isEqual(/(?:)/gi, /(?:)/g), 'Commutative equality is implemented for RegExps'); + ok(!_.isEqual(/Curly/g, {source: 'Larry', global: true, ignoreCase: false, multiline: false}), 'RegExps and RegExp-like objects are not equal'); // Empty arrays, array-like objects, and object literals. - ok(_.isEqual({}, {}), "Empty object literals are equal"); - ok(_.isEqual([], []), "Empty array literals are equal"); - ok(_.isEqual([{}], [{}]), "Empty nested arrays and objects are equal"); - ok(!_.isEqual({length: 0}, []), "Array-like objects and arrays are not equal."); - ok(!_.isEqual([], {length: 0}), "Commutative equality is implemented for array-like objects"); + ok(_.isEqual({}, {}), 'Empty object literals are equal'); + ok(_.isEqual([], []), 'Empty array literals are equal'); + ok(_.isEqual([{}], [{}]), 'Empty nested arrays and objects are equal'); + ok(!_.isEqual({length: 0}, []), 'Array-like objects and arrays are not equal.'); + ok(!_.isEqual([], {length: 0}), 'Commutative equality is implemented for array-like objects'); - ok(!_.isEqual({}, []), "Object literals and array literals are not equal"); - ok(!_.isEqual([], {}), "Commutative equality is implemented for objects and arrays"); + ok(!_.isEqual({}, []), 'Object literals and array literals are not equal'); + ok(!_.isEqual([], {}), 'Commutative equality is implemented for objects and arrays'); // Arrays with primitive and object values. - ok(_.isEqual([1, "Larry", true], [1, "Larry", true]), "Arrays containing identical primitives are equal"); - ok(_.isEqual([(/Moe/g), new Date(2009, 9, 25)], [(/Moe/g), new Date(2009, 9, 25)]), "Arrays containing equivalent elements are equal"); + ok(_.isEqual([1, 'Larry', true], [1, 'Larry', true]), 'Arrays containing identical primitives are equal'); + ok(_.isEqual([(/Moe/g), new Date(2009, 9, 25)], [(/Moe/g), new Date(2009, 9, 25)]), 'Arrays containing equivalent elements are equal'); // Multi-dimensional arrays. - var a = [new Number(47), false, "Larry", /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}]; - var b = [new Number(47), false, "Larry", /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}]; - ok(_.isEqual(a, b), "Arrays containing nested arrays and objects are recursively compared"); + var a = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}]; + var b = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}]; + ok(_.isEqual(a, b), 'Arrays containing nested arrays and objects are recursively compared'); // Overwrite the methods defined in ES 5.1 section 15.4.4. a.forEach = a.map = a.filter = a.every = a.indexOf = a.lastIndexOf = a.some = a.reduce = a.reduceRight = null; b.join = b.pop = b.reverse = b.shift = b.slice = b.splice = b.concat = b.sort = b.unshift = null; // Array elements and properties. - ok(_.isEqual(a, b), "Arrays containing equivalent elements and different non-numeric properties are equal"); - a.push("White Rocks"); - ok(!_.isEqual(a, b), "Arrays of different lengths are not equal"); - a.push("East Boulder"); - b.push("Gunbarrel Ranch", "Teller Farm"); - ok(!_.isEqual(a, b), "Arrays of identical lengths containing different elements are not equal"); + ok(_.isEqual(a, b), 'Arrays containing equivalent elements and different non-numeric properties are equal'); + a.push('White Rocks'); + ok(!_.isEqual(a, b), 'Arrays of different lengths are not equal'); + a.push('East Boulder'); + b.push('Gunbarrel Ranch', 'Teller Farm'); + ok(!_.isEqual(a, b), 'Arrays of identical lengths containing different elements are not equal'); // Sparse arrays. - ok(_.isEqual(Array(3), Array(3)), "Sparse arrays of identical lengths are equal"); - ok(!_.isEqual(Array(3), Array(6)), "Sparse arrays of different lengths are not equal when both are empty"); + ok(_.isEqual(Array(3), Array(3)), 'Sparse arrays of identical lengths are equal'); + ok(!_.isEqual(Array(3), Array(6)), 'Sparse arrays of different lengths are not equal when both are empty'); // Simple objects. - ok(_.isEqual({a: "Curly", b: 1, c: true}, {a: "Curly", b: 1, c: true}), "Objects containing identical primitives are equal"); - ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), "Objects containing equivalent members are equal"); - ok(!_.isEqual({a: 63, b: 75}, {a: 61, b: 55}), "Objects of identical sizes with different values are not equal"); - ok(!_.isEqual({a: 63, b: 75}, {a: 61, c: 55}), "Objects of identical sizes with different property names are not equal"); - ok(!_.isEqual({a: 1, b: 2}, {a: 1}), "Objects of different sizes are not equal"); - ok(!_.isEqual({a: 1}, {a: 1, b: 2}), "Commutative equality is implemented for objects"); - ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), "Objects with identical keys and different values are not equivalent"); + ok(_.isEqual({a: 'Curly', b: 1, c: true}, {a: 'Curly', b: 1, c: true}), 'Objects containing identical primitives are equal'); + ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), 'Objects containing equivalent members are equal'); + ok(!_.isEqual({a: 63, b: 75}, {a: 61, b: 55}), 'Objects of identical sizes with different values are not equal'); + ok(!_.isEqual({a: 63, b: 75}, {a: 61, c: 55}), 'Objects of identical sizes with different property names are not equal'); + ok(!_.isEqual({a: 1, b: 2}, {a: 1}), 'Objects of different sizes are not equal'); + ok(!_.isEqual({a: 1}, {a: 1, b: 2}), 'Commutative equality is implemented for objects'); + ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), 'Objects with identical keys and different values are not equivalent'); // `A` contains nested objects and arrays. a = { - name: new String("Moe Howard"), + name: new String('Moe Howard'), age: new Number(77), stooge: true, - hobbies: ["acting"], + hobbies: ['acting'], film: { - name: "Sing a Song of Six Pants", + name: 'Sing a Song of Six Pants', release: new Date(1947, 9, 30), - stars: [new String("Larry Fine"), "Shemp Howard"], + stars: [new String('Larry Fine'), 'Shemp Howard'], minutes: new Number(16), seconds: 54 } @@ -274,81 +275,81 @@ $(document).ready(function() { // `B` contains equivalent nested objects and arrays. b = { - name: new String("Moe Howard"), + name: new String('Moe Howard'), age: new Number(77), stooge: true, - hobbies: ["acting"], + hobbies: ['acting'], film: { - name: "Sing a Song of Six Pants", + name: 'Sing a Song of Six Pants', release: new Date(1947, 9, 30), - stars: [new String("Larry Fine"), "Shemp Howard"], + stars: [new String('Larry Fine'), 'Shemp Howard'], minutes: new Number(16), seconds: 54 } }; - ok(_.isEqual(a, b), "Objects with nested equivalent members are recursively compared"); + ok(_.isEqual(a, b), 'Objects with nested equivalent members are recursively compared'); // Instances. - ok(_.isEqual(new First, new First), "Object instances are equal"); - ok(!_.isEqual(new First, new Second), "Objects with different constructors and identical own properties are not equal"); - ok(!_.isEqual({value: 1}, new First), "Object instances and objects sharing equivalent properties are not equal"); - ok(!_.isEqual({value: 2}, new Second), "The prototype chain of objects should not be examined"); + ok(_.isEqual(new First, new First), 'Object instances are equal'); + ok(!_.isEqual(new First, new Second), 'Objects with different constructors and identical own properties are not equal'); + ok(!_.isEqual({value: 1}, new First), 'Object instances and objects sharing equivalent properties are not equal'); + ok(!_.isEqual({value: 2}, new Second), 'The prototype chain of objects should not be examined'); // Circular Arrays. (a = []).push(a); (b = []).push(b); - ok(_.isEqual(a, b), "Arrays containing circular references are equal"); - a.push(new String("Larry")); - b.push(new String("Larry")); - ok(_.isEqual(a, b), "Arrays containing circular references and equivalent properties are equal"); - a.push("Shemp"); - b.push("Curly"); - ok(!_.isEqual(a, b), "Arrays containing circular references and different properties are not equal"); + ok(_.isEqual(a, b), 'Arrays containing circular references are equal'); + a.push(new String('Larry')); + b.push(new String('Larry')); + ok(_.isEqual(a, b), 'Arrays containing circular references and equivalent properties are equal'); + a.push('Shemp'); + b.push('Curly'); + ok(!_.isEqual(a, b), 'Arrays containing circular references and different properties are not equal'); // More circular arrays #767. - a = ["everything is checked but", "this", "is not"]; + a = ['everything is checked but', 'this', 'is not']; a[1] = a; - b = ["everything is checked but", ["this", "array"], "is not"]; - ok(!_.isEqual(a, b), "Comparison of circular references with non-circular references are not equal"); + b = ['everything is checked but', ['this', 'array'], 'is not']; + ok(!_.isEqual(a, b), 'Comparison of circular references with non-circular references are not equal'); // Circular Objects. a = {abc: null}; b = {abc: null}; a.abc = a; b.abc = b; - ok(_.isEqual(a, b), "Objects containing circular references are equal"); + ok(_.isEqual(a, b), 'Objects containing circular references are equal'); a.def = 75; b.def = 75; - ok(_.isEqual(a, b), "Objects containing circular references and equivalent properties are equal"); + ok(_.isEqual(a, b), 'Objects containing circular references and equivalent properties are equal'); a.def = new Number(75); b.def = new Number(63); - ok(!_.isEqual(a, b), "Objects containing circular references and different properties are not equal"); + ok(!_.isEqual(a, b), 'Objects containing circular references and different properties are not equal'); // More circular objects #767. - a = {everything: "is checked", but: "this", is: "not"}; + a = {everything: 'is checked', but: 'this', is: 'not'}; a.but = a; - b = {everything: "is checked", but: {that:"object"}, is: "not"}; - ok(!_.isEqual(a, b), "Comparison of circular references with non-circular object references are not equal"); + b = {everything: 'is checked', but: {that:'object'}, is: 'not'}; + ok(!_.isEqual(a, b), 'Comparison of circular references with non-circular object references are not equal'); // Cyclic Structures. a = [{abc: null}]; b = [{abc: null}]; (a[0].abc = a).push(a); (b[0].abc = b).push(b); - ok(_.isEqual(a, b), "Cyclic structures are equal"); - a[0].def = "Larry"; - b[0].def = "Larry"; - ok(_.isEqual(a, b), "Cyclic structures containing equivalent properties are equal"); - a[0].def = new String("Larry"); - b[0].def = new String("Curly"); - ok(!_.isEqual(a, b), "Cyclic structures containing different properties are not equal"); + ok(_.isEqual(a, b), 'Cyclic structures are equal'); + a[0].def = 'Larry'; + b[0].def = 'Larry'; + ok(_.isEqual(a, b), 'Cyclic structures containing equivalent properties are equal'); + a[0].def = new String('Larry'); + b[0].def = new String('Curly'); + ok(!_.isEqual(a, b), 'Cyclic structures containing different properties are not equal'); // Complex Circular References. a = {foo: {b: {foo: {c: {foo: null}}}}}; b = {foo: {b: {foo: {c: {foo: null}}}}}; a.foo.b.foo.c.foo = a; b.foo.b.foo.c.foo = b; - ok(_.isEqual(a, b), "Cyclic structures with nested and identically-named properties are equal"); + ok(_.isEqual(a, b), 'Cyclic structures with nested and identically-named properties are equal'); // Chaining. ok(!_.isEqual(_({x: 1, y: undefined}).chain(), _({x: 1, z: 2}).chain()), 'Chained objects containing different values are not equal'); @@ -359,9 +360,22 @@ $(document).ready(function() { // Objects from another frame. ok(_.isEqual({}, iObject)); + + // Objects without a `constructor` property + if (Object.create) { + a = Object.create(null, {x: {value: 1, enumerable: true}}); + b = {x: 1}; + ok(_.isEqual(a, b)); + } + + function Foo() { this.a = 1; } + Foo.prototype.constructor = null; + + var other = { 'a': 1 }; + strictEqual(_.isEqual(new Foo, other), false); }); - test("isEmpty", function() { + test('isEmpty', function() { ok(!_([1]).isEmpty(), '[1] is not empty'); ok(_.isEmpty([]), '[] is empty'); ok(!_.isEmpty({one : 1}), '{one : 1} is not empty'); @@ -379,14 +393,15 @@ $(document).ready(function() { // Setup remote variables for iFrame tests. var iframe = document.createElement('iframe'); - jQuery(iframe).appendTo(document.body); - var iDoc = iframe.contentDocument || iframe.contentWindow.document; + iframe.frameBorder = iframe.height = iframe.width = 0 + document.body.appendChild(iframe); + var iDoc = (iDoc = iframe.contentDocument || iframe.contentWindow).document || iDoc; iDoc.write( - "" + ' ); iDoc.close(); - test("isElement", function() { + test('isElement', function() { ok(!_.isElement('div'), 'strings are not dom elements'); - ok(_.isElement($('html')[0]), 'the html tag is a DOM element'); + ok(_.isElement(document.body), 'the body tag is a DOM element'); ok(_.isElement(iElement), 'even from another frame'); }); - test("isArguments", function() { + test('isArguments', function() { var args = (function(){ return arguments; })(1, 2, 3); ok(!_.isArguments('string'), 'a string is not an arguments object'); ok(!_.isArguments(_.isArguments), 'a function is not an arguments object'); @@ -416,10 +431,10 @@ $(document).ready(function() { ok(_.isArguments(iArguments), 'even from another frame'); }); - test("isObject", function() { + test('isObject', function() { ok(_.isObject(arguments), 'the arguments object is object'); ok(_.isObject([1, 2, 3]), 'and arrays'); - ok(_.isObject($('html')[0]), 'and DOM element'); + ok(_.isObject(document.body), 'and DOM element'); ok(_.isObject(iElement), 'even from another frame'); ok(_.isObject(function () {}), 'and functions'); ok(_.isObject(iFunction), 'even from another frame'); @@ -431,23 +446,23 @@ $(document).ready(function() { ok(_.isObject(new String('string')), 'but new String()'); }); - test("isArray", function() { + test('isArray', function() { ok(!_.isArray(undefined), 'undefined vars are not arrays'); ok(!_.isArray(arguments), 'the arguments object is not an array'); ok(_.isArray([1, 2, 3]), 'but arrays are'); ok(_.isArray(iArray), 'even from another frame'); }); - test("isString", function() { - var obj = new String("I am a string object"); + test('isString', function() { + var obj = new String('I am a string object'); ok(!_.isString(document.body), 'the document body is not a string'); ok(_.isString([1, 2, 3].join(', ')), 'but strings are'); ok(_.isString(iString), 'even from another frame'); - ok(_.isString("I am a string literal"), 'string literals are'); + ok(_.isString('I am a string literal'), 'string literals are'); ok(_.isString(obj), 'so are String objects'); }); - test("isNumber", function() { + test('isNumber', function() { ok(!_.isNumber('string'), 'a string is not a number'); ok(!_.isNumber(arguments), 'the arguments object is not a number'); ok(!_.isNumber(undefined), 'undefined is not a number'); @@ -458,11 +473,11 @@ $(document).ready(function() { ok(!_.isNumber('1'), 'numeric strings are not numbers'); }); - test("isBoolean", function() { + test('isBoolean', function() { ok(!_.isBoolean(2), 'a number is not a boolean'); - ok(!_.isBoolean("string"), 'a string is not a boolean'); - ok(!_.isBoolean("false"), 'the string "false" is not a boolean'); - ok(!_.isBoolean("true"), 'the string "true" is not a boolean'); + ok(!_.isBoolean('string'), 'a string is not a boolean'); + ok(!_.isBoolean('false'), 'the string "false" is not a boolean'); + ok(!_.isBoolean('true'), 'the string "true" is not a boolean'); ok(!_.isBoolean(arguments), 'the arguments object is not a boolean'); ok(!_.isBoolean(undefined), 'undefined is not a boolean'); ok(!_.isBoolean(NaN), 'NaN is not a boolean'); @@ -472,7 +487,7 @@ $(document).ready(function() { ok(_.isBoolean(iBoolean), 'even from another frame'); }); - test("isFunction", function() { + test('isFunction', function() { ok(!_.isFunction(undefined), 'undefined vars are not functions'); ok(!_.isFunction([1, 2, 3]), 'arrays are not functions'); ok(!_.isFunction('moe'), 'strings are not functions'); @@ -481,36 +496,36 @@ $(document).ready(function() { ok(_.isFunction(function(){}), 'even anonymous ones'); }); - test("isDate", function() { + test('isDate', function() { ok(!_.isDate(100), 'numbers are not dates'); ok(!_.isDate({}), 'objects are not dates'); ok(_.isDate(new Date()), 'but dates are'); ok(_.isDate(iDate), 'even from another frame'); }); - test("isRegExp", function() { + test('isRegExp', function() { ok(!_.isRegExp(_.identity), 'functions are not RegExps'); ok(_.isRegExp(/identity/), 'but RegExps are'); ok(_.isRegExp(iRegExp), 'even from another frame'); }); - test("isFinite", function() { - ok(!_.isFinite(undefined), 'undefined is not Finite'); - ok(!_.isFinite(null), 'null is not Finite'); - ok(!_.isFinite(NaN), 'NaN is not Finite'); - ok(!_.isFinite(Infinity), 'Infinity is not Finite'); - ok(!_.isFinite(-Infinity), '-Infinity is not Finite'); + test('isFinite', function() { + ok(!_.isFinite(undefined), 'undefined is not finite'); + ok(!_.isFinite(null), 'null is not finite'); + ok(!_.isFinite(NaN), 'NaN is not finite'); + ok(!_.isFinite(Infinity), 'Infinity is not finite'); + ok(!_.isFinite(-Infinity), '-Infinity is not finite'); ok(_.isFinite('12'), 'Numeric strings are numbers'); ok(!_.isFinite('1a'), 'Non numeric strings are not numbers'); ok(!_.isFinite(''), 'Empty strings are not numbers'); var obj = new Number(5); ok(_.isFinite(obj), 'Number instances can be finite'); - ok(_.isFinite(0), '0 is Finite'); - ok(_.isFinite(123), 'Ints are Finite'); - ok(_.isFinite(-12.44), 'Floats are Finite'); + ok(_.isFinite(0), '0 is finite'); + ok(_.isFinite(123), 'Ints are finite'); + ok(_.isFinite(-12.44), 'Floats are finite'); }); - test("isNaN", function() { + test('isNaN', function() { ok(!_.isNaN(undefined), 'undefined is not NaN'); ok(!_.isNaN(null), 'null is not NaN'); ok(!_.isNaN(0), '0 is not NaN'); @@ -519,14 +534,14 @@ $(document).ready(function() { ok(_.isNaN(new Number(NaN)), 'wrapped NaN is still NaN'); }); - test("isNull", function() { + test('isNull', function() { ok(!_.isNull(undefined), 'undefined is not null'); ok(!_.isNull(NaN), 'NaN is not null'); ok(_.isNull(null), 'but null is'); ok(_.isNull(iNull), 'even from another frame'); }); - test("isUndefined", function() { + test('isUndefined', function() { ok(!_.isUndefined(1), 'numbers are defined'); ok(!_.isUndefined(null), 'null is defined'); ok(!_.isUndefined(false), 'false is defined'); @@ -537,8 +552,8 @@ $(document).ready(function() { }); if (window.ActiveXObject) { - test("IE host objects", function() { - var xml = new ActiveXObject("Msxml2.DOMDocument.3.0"); + test('IE host objects', function() { + var xml = new ActiveXObject('Msxml2.DOMDocument.3.0'); ok(!_.isNumber(xml)); ok(!_.isBoolean(xml)); ok(!_.isNaN(xml)); @@ -548,12 +563,12 @@ $(document).ready(function() { }); } - test("tap", function() { + test('tap', function() { var intercepted = null; var interceptor = function(obj) { intercepted = obj; }; var returned = _.tap(1, interceptor); - equal(intercepted, 1, "passes tapped object to interceptor"); - equal(returned, 1, "returns tapped object"); + equal(intercepted, 1, 'passes tapped object to interceptor'); + equal(returned, 1, 'returns tapped object'); returned = _([1,2,3]).chain(). map(function(n){ return n * 2; }). @@ -564,14 +579,22 @@ $(document).ready(function() { }); test("has", function () { - var obj = {foo: "bar", func: function () {} }; - ok (_.has(obj, "foo"), "has() checks that the object has a property."); - ok (_.has(obj, "baz") == false, "has() returns false if the object doesn't have the property."); - ok (_.has(obj, "func"), "has() works for functions too."); - obj.hasOwnProperty = null; - ok (_.has(obj, "foo"), "has() works even when the hasOwnProperty method is deleted."); - var child = {}; - child.prototype = obj; - ok (_.has(child, "foo") == false, "has() does not check the prototype chain for a property.") + var obj = {foo: "bar", func: function () {} }; + ok(_.has(obj, "foo"), "has() checks that the object has a property."); + ok(_.has(obj, "baz") == false, "has() returns false if the object doesn't have the property."); + ok(_.has(obj, "func"), "has() works for functions too."); + obj.hasOwnProperty = null; + ok(_.has(obj, "foo"), "has() works even when the hasOwnProperty method is deleted."); + var child = {}; + child.prototype = obj; + ok(_.has(child, "foo") == false, "has() does not check the prototype chain for a property.") }); -}); + + test("matches", function() { + var moe = {name: 'Moe Howard', hair: true}, + curly = {name: 'Curly Howard', hair: false}, + stooges = [moe, curly]; + ok(_.find(stooges, _.matches({hair: false})) === curly, "returns a predicate that can be used by finding functions.") + ok(_.find(stooges, _.matches(moe)) === moe, "can be used to locate an object exists in a collection.") + }) +})(); diff --git a/vendor/underscore/test/utility.js b/vendor/underscore/test/utility.js index 52c5495fb..513b8341a 100644 --- a/vendor/underscore/test/utility.js +++ b/vendor/underscore/test/utility.js @@ -1,8 +1,8 @@ -$(document).ready(function() { +(function() { var templateSettings; - module("Utility", { + module('Utility', { setup: function() { templateSettings = _.clone(_.templateSettings); @@ -14,54 +14,69 @@ $(document).ready(function() { }); - test("#750 - Return _ instance.", 2, function() { + test('#750 - Return _ instance.', 2, function() { var instance = _([]); ok(_(instance) === instance); ok(new _(instance) === instance); }); - test("identity", function() { + test('identity', function() { var moe = {name : 'moe'}; equal(_.identity(moe), moe, 'moe is the same as his identity'); }); - test("random", function() { + test('constant', function() { + var moe = {name : 'moe'}; + equal(_.constant(moe)(), moe, 'should create a function that returns moe'); + }); + + test('property', function() { + var moe = {name : 'moe'}; + equal(_.property('name')(moe), 'moe', 'should return the property with the given name'); + }); + + test('random', function() { var array = _.range(1000); var min = Math.pow(2, 31); var max = Math.pow(2, 62); ok(_.every(array, function() { return _.random(min, max) >= min; - }), "should produce a random number greater than or equal to the minimum number"); + }), 'should produce a random number greater than or equal to the minimum number'); ok(_.some(array, function() { return _.random(Number.MAX_VALUE) > 0; - }), "should produce a random number when passed `Number.MAX_VALUE`"); + }), 'should produce a random number when passed `Number.MAX_VALUE`'); }); - test("uniqueId", function() { + test('now', function() { + var diff = _.now() - new Date().getTime(); + ok(diff <= 0 && diff > -5, 'Produces the correct time in milliseconds');//within 5ms + }); + + test('uniqueId', function() { var ids = [], i = 0; while(i++ < 100) ids.push(_.uniqueId()); equal(_.uniq(ids).length, ids.length, 'can generate a globally-unique stream of ids'); }); - test("times", function() { + test('times', function() { var vals = []; _.times(3, function (i) { vals.push(i); }); - ok(_.isEqual(vals, [0,1,2]), "is 0 indexed"); + ok(_.isEqual(vals, [0,1,2]), 'is 0 indexed'); // vals = []; _(3).times(function(i) { vals.push(i); }); - ok(_.isEqual(vals, [0,1,2]), "works as a wrapper"); + ok(_.isEqual(vals, [0,1,2]), 'works as a wrapper'); // collects return values - ok(_.isEqual([0, 1, 2], _.times(3, function(i) { return i; })), "collects return values"); + ok(_.isEqual([0, 1, 2], _.times(3, function(i) { return i; })), 'collects return values'); deepEqual(_.times(0, _.identity), []); deepEqual(_.times(-1, _.identity), []); deepEqual(_.times(parseFloat('-Infinity'), _.identity), []); }); - test("mixin", function() { + test('mixin', function() { _.mixin({ myReverse: function(string) { return string.split('').reverse().join(''); @@ -71,60 +86,60 @@ $(document).ready(function() { equal(_('champ').myReverse(), 'pmahc', 'mixed in a function to the OOP wrapper'); }); - test("_.escape", function() { - equal(_.escape("Curly & Moe"), "Curly & Moe"); + test('_.escape', function() { + equal(_.escape('Curly & Moe'), 'Curly & Moe'); equal(_.escape('Curly & Moe\'s'), '<a href="http://moe.com">Curly & Moe's</a>'); - equal(_.escape("Curly & Moe"), "Curly &amp; Moe"); + equal(_.escape('Curly & Moe'), 'Curly &amp; Moe'); equal(_.escape(null), ''); }); - test("_.unescape", function() { - var string = "Curly & Moe"; - equal(_.unescape("Curly & Moe"), string); + test('_.unescape', function() { + var string = 'Curly & Moe'; + equal(_.unescape('Curly & Moe'), string); equal(_.unescape('<a href="http://moe.com">Curly & Moe's</a>'), 'Curly & Moe\'s'); - equal(_.unescape("Curly &amp; Moe"), "Curly & Moe"); + equal(_.unescape('Curly &amp; Moe'), 'Curly & Moe'); equal(_.unescape(null), ''); equal(_.unescape(_.escape(string)), string); }); - test("template", function() { + test('template', function() { var basicTemplate = _.template("<%= thing %> is gettin' on my noives!"); var result = basicTemplate({thing : 'This'}); equal(result, "This is gettin' on my noives!", 'can do basic attribute interpolation'); - var sansSemicolonTemplate = _.template("A <% this %> B"); - equal(sansSemicolonTemplate(), "A B"); + var sansSemicolonTemplate = _.template('A <% this %> B'); + equal(sansSemicolonTemplate(), 'A B'); - var backslashTemplate = _.template("<%= thing %> is \\ridanculous"); - equal(backslashTemplate({thing: 'This'}), "This is \\ridanculous"); + var backslashTemplate = _.template('<%= thing %> is \\ridanculous'); + equal(backslashTemplate({thing: 'This'}), 'This is \\ridanculous'); var escapeTemplate = _.template('<%= a ? "checked=\\"checked\\"" : "" %>'); equal(escapeTemplate({a: true}), 'checked="checked"', 'can handle slash escapes in interpolations.'); - var fancyTemplate = _.template("
    <% \ + var fancyTemplate = _.template('
      <% \ for (var key in people) { \ - %>
    • <%= people[key] %>
    • <% } %>
    "); - result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}}); - equal(result, "
    • Moe
    • Larry
    • Curly
    ", 'can run arbitrary javascript in templates'); + %>
  • <%= people[key] %>
  • <% } %>
'); + result = fancyTemplate({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}}); + equal(result, '
  • Moe
  • Larry
  • Curly
', 'can run arbitrary javascript in templates'); - var escapedCharsInJavascriptTemplate = _.template("
    <% _.each(numbers.split('\\n'), function(item) { %>
  • <%= item %>
  • <% }) %>
"); - result = escapedCharsInJavascriptTemplate({numbers: "one\ntwo\nthree\nfour"}); - equal(result, "
  • one
  • two
  • three
  • four
", 'Can use escaped characters (e.g. \\n) in Javascript'); + var escapedCharsInJavascriptTemplate = _.template('
    <% _.each(numbers.split("\\n"), function(item) { %>
  • <%= item %>
  • <% }) %>
'); + result = escapedCharsInJavascriptTemplate({numbers: 'one\ntwo\nthree\nfour'}); + equal(result, '
  • one
  • two
  • three
  • four
', 'Can use escaped characters (e.g. \\n) in JavaScript'); - var namespaceCollisionTemplate = _.template("<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %>
\">
<% }); %>"); + var namespaceCollisionTemplate = _.template('<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %>
<% }); %>'); result = namespaceCollisionTemplate({ pageCount: 3, thumbnails: { - 1: "p1-thumbnail.gif", - 2: "p2-thumbnail.gif", - 3: "p3-thumbnail.gif" + 1: 'p1-thumbnail.gif', + 2: 'p2-thumbnail.gif', + 3: 'p3-thumbnail.gif' } }); - equal(result, "3 p3-thumbnail.gif
"); + equal(result, '3 p3-thumbnail.gif
'); - var noInterpolateTemplate = _.template("

Just some text. Hey, I know this is silly but it aids consistency.

"); + var noInterpolateTemplate = _.template('

Just some text. Hey, I know this is silly but it aids consistency.

'); result = noInterpolateTemplate(); - equal(result, "

Just some text. Hey, I know this is silly but it aids consistency.

"); + equal(result, '

Just some text. Hey, I know this is silly but it aids consistency.

'); var quoteTemplate = _.template("It's its, not it's"); equal(quoteTemplate({}), "It's its, not it's"); @@ -132,65 +147,68 @@ $(document).ready(function() { var quoteInStatementAndBody = _.template("<%\ if(foo == 'bar'){ \ %>Statement quotes and 'quotes'.<% } %>"); - equal(quoteInStatementAndBody({foo: "bar"}), "Statement quotes and 'quotes'."); + equal(quoteInStatementAndBody({foo: 'bar'}), "Statement quotes and 'quotes'."); var withNewlinesAndTabs = _.template('This\n\t\tis: <%= x %>.\n\tok.\nend.'); equal(withNewlinesAndTabs({x: 'that'}), 'This\n\t\tis: that.\n\tok.\nend.'); - var template = _.template("<%- value %>"); - var result = template({value: "