Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use consistent quoting style

  - 'string without quotes'
  - "string with 'single' quotes"
  - 'string with "double" quotes'
  - 'string with \'single\' and "double" quotes'
  • Loading branch information...
commit e840329e45fffe85d77d38dcb75cf87d74481683 1 parent d3d0f70
@davidchambers davidchambers authored
View
46 test/arrays.js
@@ -1,11 +1,11 @@
(function() {
- module("Arrays");
+ module('Arrays');
- test("first", function() {
+ test('first', function() {
equal(_.first([1,2,3]), 1, 'can pull out the first element of an array');
equal(_([1, 2, 3]).first(), 1, 'can perform OO-style "first()"');
- equal(_.first([1,2,3], 0).join(', '), "", 'can pass an index to first');
+ equal(_.first([1,2,3], 0).join(', '), '', 'can pass an index to first');
equal(_.first([1,2,3], 2).join(', '), '1, 2', 'can pass an index to first');
equal(_.first([1,2,3], 5).join(', '), '1, 2, 3', 'can pass an index to first');
var result = (function(){ return _.first(arguments); })(4, 3, 2, 1);
@@ -19,10 +19,10 @@
strictEqual(_.first([1, 2, 3], -1).length, 0);
});
- test("rest", function() {
+ test('rest', function() {
var numbers = [1, 2, 3, 4];
- equal(_.rest(numbers).join(", "), "2, 3, 4", 'working rest()');
- equal(_.rest(numbers, 0).join(", "), "1, 2, 3, 4", 'working rest(0)');
+ equal(_.rest(numbers).join(', '), '2, 3, 4', 'working rest()');
+ equal(_.rest(numbers, 0).join(', '), '1, 2, 3, 4', 'working rest(0)');
equal(_.rest(numbers, 2).join(', '), '3, 4', 'rest can take an index');
var result = (function(){ return _(arguments).tail(); })(1, 2, 3, 4);
equal(result.join(', '), '2, 3, 4', 'aliased as tail and works on arguments object');
@@ -32,18 +32,18 @@
equal(result.join(', '), '2, 3, 4', 'aliased as drop and works on arguments object');
});
- test("initial", function() {
- equal(_.initial([1,2,3,4,5]).join(", "), "1, 2, 3, 4", 'working initial()');
- equal(_.initial([1,2,3,4],2).join(", "), "1, 2", 'initial can take an index');
+ test('initial', function() {
+ equal(_.initial([1,2,3,4,5]).join(', '), '1, 2, 3, 4', 'working initial()');
+ equal(_.initial([1,2,3,4],2).join(', '), '1, 2', 'initial can take an index');
var result = (function(){ return _(arguments).initial(); })(1, 2, 3, 4);
- equal(result.join(", "), "1, 2, 3", 'initial works on arguments object');
+ equal(result.join(', '), '1, 2, 3', 'initial works on arguments object');
result = _.map([[1,2,3],[1,2,3]], _.initial);
equal(_.flatten(result).join(','), '1,2,1,2', 'initial works with _.map');
});
- test("last", function() {
+ test('last', function() {
equal(_.last([1,2,3]), 3, 'can pull out the last element of an array');
- equal(_.last([1,2,3], 0).join(', '), "", 'can pass an index to last');
+ equal(_.last([1,2,3], 0).join(', '), '', 'can pass an index to last');
equal(_.last([1,2,3], 2).join(', '), '2, 3', 'can pass an index to last');
equal(_.last([1,2,3], 5).join(', '), '1, 2, 3', 'can pass an index to last');
var result = (function(){ return _(arguments).last(); })(1, 2, 3, 4);
@@ -55,13 +55,13 @@
strictEqual(_.last([1, 2, 3], -1).length, 0);
});
- test("compact", function() {
+ test('compact', function() {
equal(_.compact([0, 1, false, 2, false, 3]).length, 3, 'can trim out all falsy values');
var result = (function(){ return _.compact(arguments).length; })(0, 1, false, 2, false, 3);
equal(result, 3, 'works on an arguments object');
});
- test("flatten", function() {
+ test('flatten', function() {
var list = [1, [2], [3, [[[4]]]]];
deepEqual(_.flatten(list), [1,2,3,4], 'can flatten nested arrays');
deepEqual(_.flatten(list, true), [1,2,3,[[[4]]]], 'can shallowly flatten nested arrays');
@@ -71,7 +71,7 @@
deepEqual(_.flatten(list, true), [1, 2, 3, [4]], 'can shallowly flatten arrays containing only other arrays');
});
- test("without", function() {
+ test('without', function() {
var list = [1, 2, 1, 0, 3, 1, 4];
equal(_.without(list, 0, 1).join(', '), '2, 3, 4', 'can remove all instances of an object');
var result = (function(){ return _.without(arguments, 0, 1); })(1, 2, 1, 0, 3, 1, 4);
@@ -82,7 +82,7 @@
ok(_.without(list, list[0]).length == 1, 'ditto.');
});
- test("partition", function() {
+ test('partition', function() {
var list = [0, 1, 2, 3, 4, 5];
function inspect(x) { return x instanceof Array ? '[' + _.map(x, inspect) + ']' : '' + x; }
equal(inspect(_.partition(list, function(x) { return x < 4; })), '[[0,1,2,3],[4,5]]', 'handles bool return values');
@@ -92,7 +92,7 @@
equal(inspect(_.partition(list, function(x) { if(x < 2) return true; })), '[[0,1],[2,3,4,5]]', 'handles undefined return values');
});
- test("uniq", function() {
+ 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');
@@ -113,7 +113,7 @@
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');
@@ -123,7 +123,7 @@
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');
@@ -139,7 +139,7 @@
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');
@@ -179,7 +179,7 @@
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');
@@ -205,7 +205,7 @@
equal(index, 7, 'supports the fromIndex argument');
});
- test("lastIndexOf", function() {
+ test('lastIndexOf', function() {
var numbers = [1, 0, 1];
equal(_.lastIndexOf(numbers, 1), 2);
@@ -222,7 +222,7 @@
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 &amp; b, a&lt;b generates an array of elements a,a+1,a+2,...,b-2,b-1');
View
18 test/chaining.js
@@ -1,8 +1,8 @@
(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 @@
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 @@
}).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 @@
}).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,10 +53,10 @@
.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]);
View
40 test/collections.js
@@ -1,8 +1,8 @@
(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 @@
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;
@@ -98,13 +98,13 @@
});
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;
@@ -180,10 +180,10 @@
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');
@@ -244,13 +244,13 @@
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() {
@@ -268,7 +268,7 @@
equal(result[0].a, 1);
result = _.where(list, {a: 1}, true);
- equal(result.b, 2, "Only get the first object matched.")
+ equal(result.b, 2, 'Only get the first object matched.')
result = _.where(list, {a: 1}, false);
equal(result.length, 3);
@@ -286,10 +286,10 @@
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() {
@@ -302,7 +302,7 @@
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() {
@@ -319,7 +319,7 @@
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() {
@@ -330,7 +330,7 @@
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');
@@ -366,7 +366,7 @@
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');
@@ -403,7 +403,7 @@
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');
@@ -421,7 +421,7 @@
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);
View
116 test/functions.js
@@ -1,10 +1,10 @@
(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,14 +33,14 @@
// 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(' '); };
@@ -58,7 +58,7 @@
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; },
@@ -84,7 +84,7 @@
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);
};
@@ -100,59 +100,59 @@
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);
@@ -166,7 +166,7 @@
}, 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);
@@ -178,17 +178,17 @@
_.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++; };
@@ -207,7 +207,7 @@
}, 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});
@@ -221,7 +221,7 @@
}, 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});
@@ -242,7 +242,7 @@
}, 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});
@@ -257,7 +257,7 @@
}, 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});
@@ -278,16 +278,16 @@
}, 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; };
@@ -300,21 +300,21 @@
_.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();
@@ -322,7 +322,7 @@
equal(num, 1);
});
- test("Recursive onced function.", 1, function() {
+ test('Recursive onced function.', 1, function() {
var f = _.once(function(){
ok(true);
f();
@@ -330,15 +330,15 @@
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); });
@@ -346,8 +346,8 @@
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');
@@ -356,7 +356,7 @@
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() {
@@ -366,10 +366,10 @@
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');
});
})();
View
330 test/objects.js
@@ -1,8 +1,8 @@
(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;
@@ -14,17 +14,17 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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,133 @@
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(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');
// 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(/(?:)/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 +274,81 @@
// `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');
@@ -374,7 +374,7 @@
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');
@@ -396,11 +396,11 @@
document.body.appendChild(iframe);
var iDoc = (iDoc = iframe.contentDocument || iframe.contentWindow).document || iDoc;
iDoc.write(
- "<script>\
- parent.iElement = document.createElement('div');\
+ '<script>\
+ parent.iElement = document.createElement("div");\
parent.iArguments = (function(){ return arguments; })(1, 2, 3);\
parent.iArray = [1, 2, 3];\
- parent.iString = new String('hello');\
+ parent.iString = new String("hello");\
parent.iNumber = new Number(100);\
parent.iFunction = (function(){});\
parent.iDate = new Date();\
@@ -410,17 +410,17 @@
parent.iBoolean = new Boolean(false);\
parent.iUndefined = undefined;\
parent.iObject = {};\
- </script>"
+ </script>'
);
iDoc.close();
- test("isElement", function() {
+ test('isElement', function() {
ok(!_.isElement('div'), 'strings are not dom elements');
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');
@@ -430,7 +430,7 @@
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(document.body), 'and DOM element');
@@ -445,23 +445,23 @@
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');
@@ -472,11 +472,11 @@
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');
@@ -486,7 +486,7 @@
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');
@@ -495,20 +495,20 @@
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() {
+ test('isFinite', function() {
ok(!_.isFinite(undefined), 'undefined is not Finite');
ok(!_.isFinite(null), 'null is not Finite');
ok(!_.isFinite(NaN), 'NaN is not Finite');
@@ -524,7 +524,7 @@
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');
@@ -533,14 +533,14 @@
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');
@@ -551,8 +551,8 @@
});
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));
@@ -562,12 +562,12 @@
});
}
- 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; }).
@@ -577,15 +577,15 @@
ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain');
});
- 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.");
+ 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.");
+ 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.")
+ ok (_.has(child, 'foo') == false, 'has() does not check the prototype chain for a property.')
});
})();
View
116 test/utility.js
@@ -2,7 +2,7 @@
var templateSettings;
- module("Utility", {
+ module('Utility', {
setup: function() {
templateSettings = _.clone(_.templateSettings);
@@ -14,69 +14,69 @@
});
- 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("constant", function() {
+ test('constant', function() {
var moe = {name : 'moe'};
equal(_.constant(moe)(), moe, 'should create a function that returns moe');
});
- test("property", function() {
+ test('property', function() {
var moe = {name : 'moe'};
equal(_.property('name')(moe), 'moe', 'should return the property with the given name');
});
- test("random", function() {
+ 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("now", function() {
+ test('now', function() {
var diff = _.now() - new Date().getTime();
- ok(diff <= 0 && diff > -5, "Produces the correct time in milliseconds");//within 5ms
+ ok(diff <= 0 && diff > -5, 'Produces the correct time in milliseconds');//within 5ms
});
- test("uniqueId", function() {
+ 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('');
@@ -86,60 +86,60 @@
equal(_('champ').myReverse(), 'pmahc', 'mixed in a function to the OOP wrapper');
});
- test("_.escape", function() {
- equal(_.escape("Curly & Moe"), "Curly &amp; Moe");
+ test('_.escape', function() {
+ equal(_.escape('Curly & Moe'), 'Curly &amp; Moe');
equal(_.escape('<a href="http://moe.com">Curly & Moe\'s</a>'), '&lt;a href=&quot;http://moe.com&quot;&gt;Curly &amp; Moe&#x27;s&lt;/a&gt;');
- equal(_.escape("Curly &amp; Moe"), "Curly &amp;amp; Moe");
+ equal(_.escape('Curly &amp; Moe'), 'Curly &amp;amp; Moe');
equal(_.escape(null), '');
});
- test("_.unescape", function() {
- var string = "Curly & Moe";
- equal(_.unescape("Curly &amp; Moe"), string);
+ test('_.unescape', function() {
+ var string = 'Curly & Moe';
+ equal(_.unescape('Curly &amp; Moe'), string);
equal(_.unescape('&lt;a href=&quot;http://moe.com&quot;&gt;Curly &amp; Moe&#x27;s&lt;/a&gt;'), '<a href="http://moe.com">Curly & Moe\'s</a>');
- equal(_.unescape("Curly &amp;amp; Moe"), "Curly &amp; Moe");
+ equal(_.unescape('Curly &amp;amp; Moe'), 'Curly &amp; 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("<ul><% \
+ var fancyTemplate = _.template('<ul><% \
for (var key in people) { \
- %><li><%= people[key] %></li><% } %></ul>");
- result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
- equal(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
+ %><li><%= people[key] %></li><% } %></ul>');
+ result = fancyTemplate({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}});
+ equal(result, '<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>', 'can run arbitrary javascript in templates');
- var escapedCharsInJavascriptTemplate = _.template("<ul><% _.each(numbers.split('\\n'), function(item) { %><li><%= item %></li><% }) %></ul>");
- result = escapedCharsInJavascriptTemplate({numbers: "one\ntwo\nthree\nfour"});
- equal(result, "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>", 'Can use escaped characters (e.g. \\n) in Javascript');
+ var escapedCharsInJavascriptTemplate = _.template('<ul><% _.each(numbers.split("\\n"), function(item) { %><li><%= item %></li><% }) %></ul>');
+ result = escapedCharsInJavascriptTemplate({numbers: 'one\ntwo\nthree\nfour'});
+ equal(result, '<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>', 'Can use escaped characters (e.g. \\n) in Javascript');
- var namespaceCollisionTemplate = _.template("<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %><div class=\"thumbnail\" rel=\"<%= p %>\"></div><% }); %>");
+ var namespaceCollisionTemplate = _.template('<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %><div class="thumbnail" rel="<%= p %>"></div><% }); %>');
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 <div class=\"thumbnail\" rel=\"p1-thumbnail.gif\"></div><div class=\"thumbnail\" rel=\"p2-thumbnail.gif\"></div><div class=\"thumbnail\" rel=\"p3-thumbnail.gif\"></div>");
+ equal(result, '3 p3-thumbnail.gif <div class="thumbnail" rel="p1-thumbnail.gif"></div><div class="thumbnail" rel="p2-thumbnail.gif"></div><div class="thumbnail" rel="p3-thumbnail.gif"></div>');
- var noInterpolateTemplate = _.template("<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>");
+ var noInterpolateTemplate = _.template('<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>');
result = noInterpolateTemplate();
- equal(result, "<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>");
+ equal(result, '<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>');
var quoteTemplate = _.template("It's its, not it's");
equal(quoteTemplate({}), "It's its, not it's");
@@ -147,17 +147,17 @@
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("<i><%- value %></i>");
- var result = template({value: "<script>"});
+ var template = _.template('<i><%- value %></i>');
+ var result = template({value: '<script>'});
equal(result, '<i>&lt;script&gt;</i>');
var stooge = {
- name: "Moe",
+ name: 'Moe',
template: _.template("I'm <%= this.name %>")
};
equal(stooge.template(), "I'm Moe");
@@ -175,40 +175,40 @@
interpolate : /\{\{=([\s\S]+?)\}\}/g
};
- var custom = _.template("<ul>{{ for (var key in people) { }}<li>{{= people[key] }}</li>{{ } }}</ul>");
- result = custom({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
- equal(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
+ var custom = _.template('<ul>{{ for (var key in people) { }}<li>{{= people[key] }}</li>{{ } }}</ul>');
+ result = custom({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}});
+ equal(result, '<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>', 'can run arbitrary javascript in templates');
var customQuote = _.template("It's its, not it's");
equal(customQuote({}), "It's its, not it's");
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'.");
_.templateSettings = {
evaluate : /<\?([\s\S]+?)\?>/g,
interpolate : /<\?=([\s\S]+?)\?>/g
};
- var customWithSpecialChars = _.template("<ul><? for (var key in people) { ?><li><?= people[key] ?></li><? } ?></ul>");
- result = customWithSpecialChars({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
- equal(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
+ var customWithSpecialChars = _.template('<ul><? for (var key in people) { ?><li><?= people[key] ?></li><? } ?></ul>');
+ result = customWithSpecialChars({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}});
+ equal(result, '<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>', 'can run arbitrary javascript in templates');
var customWithSpecialCharsQuote = _.template("It's its, not it's");
equal(customWithSpecialCharsQuote({}), "It's its, not it's");
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'.");
_.templateSettings = {
interpolate : /\{\{(.+?)\}\}/g
};
- var mustache = _.template("Hello {{planet}}!");
- equal(mustache({planet : "World"}), "Hello World!", "can mimic mustache.js");
+ var mustache = _.template('Hello {{planet}}!');
+ equal(mustache({planet : 'World'}), 'Hello World!', 'can mimic mustache.js');
- var templateWithNull = _.template("a null undefined {{planet}}");
- equal(templateWithNull({planet : "world"}), "a null undefined world", "can handle missing escape and evaluate settings");
+ var templateWithNull = _.template('a null undefined {{planet}}');
+ equal(templateWithNull({planet : 'world'}), 'a null undefined world', 'can handle missing escape and evaluate settings');
});
test('_.template provides the generated function source, when a SyntaxError occurs', function() {
View
4 underscore.js
@@ -519,7 +519,7 @@
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
- var length = _.max(_.pluck(arguments, "length").concat(0));
+ var length = _.max(_.pluck(arguments, 'length').concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
results[i] = _.pluck(arguments, '' + i);
@@ -645,7 +645,7 @@
// defined on an object belong to it.
_.bindAll = function(obj) {
var funcs = slice.call(arguments, 1);
- if (funcs.length === 0) throw new Error("bindAll must be passed function names");
+ if (funcs.length === 0) throw new Error('bindAll must be passed function names');
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
return obj;
};
Please sign in to comment.
Something went wrong with that request. Please try again.