Download:
child 23:803ba407e901
parent 21:c038e14e96a5
22:03d3495b69d9
Anton Shestakov <av6@dwimlabs.net>, Wed, 22 Jun 2016 13:32:26 +0800
test: remove trailing spaces

4 файлов изменено, 39 вставок(+), 39 удалений(-) [+]
test/basic-filters.js file | annotate | diff | comparison | revisions
test/changing-models.js file | annotate | diff | comparison | revisions
test/sensible-filters.js file | annotate | diff | comparison | revisions
test/underscore-methods.js file | annotate | diff | comparison | revisions
--- a/test/basic-filters.js Wed Jun 22 13:31:18 2016 +0800
+++ b/test/basic-filters.js Wed Jun 22 13:32:26 2016 +0800
@@ -7,7 +7,7 @@
c = new Backbone.Model({data: 'c'});
col = new Backbone.Collection([a, b, c]);
otherCol = new Backbone.Collection();
-
+
additions = 0;
removals = 0;
resets = 0;
@@ -19,7 +19,7 @@
collection: col,
filter: function() { return false; }
});
-
+
equal(shard.size(), 0, 'shard is empty');
equal(shard.first(), undefined, 'nothing is the first element');
equal(shard.last(), undefined, 'nothing is the last element');
@@ -30,7 +30,7 @@
collection: otherCol,
filter: function() { return false; }
});
-
+
shard.on('add', function() {
additions++;
}).on('remove', function() {
@@ -38,15 +38,15 @@
}).on('reset', function() {
resets++;
});
-
+
otherCol.add([a, b, c]);
equal(additions, 0, 'adding models not matching shard filter to collection does not trigger add events');
equal(shard.size(), 0, '... and the shard is empty');
-
+
otherCol.remove([a, b, c]);
equal(removals, 0, 'removing models not matching shard filter from collection does not trigger remove events');
equal(shard.size(), 0, '... and the shard is empty');
-
+
otherCol.reset([a, b, c]);
equal(resets, 1, 'resetting collection triggers reset events');
equal(shard.size(), 0, '... and the shard is empty');
@@ -57,7 +57,7 @@
collection: col,
filter: function() { return true; }
});
-
+
equal(shard.size(), 3, 'shard has 3 items');
equal(shard.first(), a, 'a is the first element');
equal(shard.indexOf(b), 1, 'b is the second element');
@@ -69,7 +69,7 @@
collection: otherCol,
filter: function() { return true; }
});
-
+
shard.on('add', function() {
additions++;
}).on('remove', function() {
@@ -77,11 +77,11 @@
}).on('reset', function() {
resets++;
});
-
+
otherCol.add([a, b, c]);
equal(additions, 3, 'adding models matching shard filter to collection triggers add events');
equal(shard.size(), 3, '... and the shard has 3 items');
-
+
otherCol.remove([a, b, c]);
equal(removals, 3, 'removing models matching shard filter from collection triggers remove events');
equal(shard.size(), 0, '... and the shard is empty');
--- a/test/changing-models.js Wed Jun 22 13:31:18 2016 +0800
+++ b/test/changing-models.js Wed Jun 22 13:32:26 2016 +0800
@@ -7,22 +7,22 @@
c = new Backbone.Model({data: 'c', read: false, like: false});
d = new Backbone.Model({data: 'd', read: false, like: false});
col = new Backbone.Collection([a, b, c, d]);
-
+
readShard = new Backbone.Shard({
collection: col,
filter: function(model) { return model.get('read'); }
});
-
+
unreadShard = new Backbone.Shard({
collection: col,
filter: function(model) { return !model.get('read'); }
});
-
+
additions = {read: 0, unread: 0};
removals = {read: 0, unread: 0};
changes = {read: 0, unread: 0};
likechanges = {read: 0, unread: 0};
-
+
readShard.on('add', function() {
additions.read++;
}).on('remove', function() {
@@ -32,7 +32,7 @@
}).on('change:like', function() {
likechanges.read++;
});
-
+
unreadShard.on('add', function() {
additions.unread++;
}).on('remove', function() {
--- a/test/sensible-filters.js Wed Jun 22 13:31:18 2016 +0800
+++ b/test/sensible-filters.js Wed Jun 22 13:32:26 2016 +0800
@@ -16,7 +16,7 @@
collection: col,
filter: function(model) { return _(['a', 'c']).contains(model.get('data')); }
});
-
+
equal(shard.size(), 2, 'shard has 2 items');
equal(shard.first(), a, 'a is the first element');
equal(shard.last(), c, 'c is the last element');
@@ -27,11 +27,11 @@
collection: otherCol,
filter: function(model) { return _(['a', 'c']).contains(model.get('data')); }
});
-
+
var additions = 0;
var removals = 0;
var resets = 0;
-
+
shard.on('add', function() {
additions++;
}).on('remove', function() {
@@ -39,19 +39,19 @@
}).on('reset', function() {
resets++;
});
-
+
otherCol.add([a, b, c, d]);
equal(additions, 2, 'adding models matching shard filter to collection triggers add events');
equal(shard.size(), 2, '... and the shard has 2 items');
-
+
otherCol.remove([b, d]);
equal(removals, 0, 'removing models not matching shard filter from collection does not trigger remove events');
equal(shard.size(), 2, '... and the shard has 2 items');
-
+
otherCol.remove([a, c]);
equal(removals, 2, 'removing models matching shard filter from collection triggers remove events');
equal(shard.size(), 0, '... and the shard is empty');
-
+
otherCol.reset([a, b, c, d]);
equal(resets, 1, 'resetting collection triggers reset events');
equal(shard.size(), 2, '... and the shard has 2 items');
--- a/test/underscore-methods.js Wed Jun 22 13:31:18 2016 +0800
+++ b/test/underscore-methods.js Wed Jun 22 13:32:26 2016 +0800
@@ -19,26 +19,26 @@
strictEqual(shard.last(), c, 'last() works');
deepEqual(shard.initial(), [a, b], 'initial() works');
deepEqual(shard.rest(), [b, c], 'rest() works');
-
+
equal(shard.indexOf(c), 2, 'indexOf() works');
equal(shard.lastIndexOf(c), 2, 'lastIndexOf() works');
equal(shard.isEmpty(), false, 'isEmpty() works');
deepEqual(shard.toArray(), [a, b, c], 'toArray() works');
-
+
equal(shard.contains(b), true, 'contains() works');
deepEqual(shard.without(b), [a, c], 'without() works');
-
+
equal(shard.all(_.identity), true, 'all() works');
equal(shard.any(), true, 'any() works');
-
+
deepEqual(shard.sortBy(function(model) {
return -model.get('data').charCodeAt(0);
}), [c, b, a], 'sortBy() works');
-
+
deepEqual(shard.groupBy(function(model) {
return model.get('data').charCodeAt(0) % 2;
}), {0: [b], 1: [a, c]}, 'groupBy() works');
-
+
var sh = shard.shuffle().reduce(function(memo, model) { return memo += model.get('data'); }, '');
ok(sh.length == 3 && _(sh).contains('a') && _(sh).contains('b') && _(sh).contains('c'), 'shuffle() works');
});
@@ -47,19 +47,19 @@
strictEqual(shard.min(function(model) {
return model.get('data').charCodeAt(0);
}), a, 'min() works');
-
+
strictEqual(shard.max(function(model) {
return model.get('data').charCodeAt(0);
}), c, 'max() works');
-
+
strictEqual(shard.find(function(model) {
return model.get('data') == 'b';
}), b, 'find() works');
-
+
deepEqual(shard.filter(function(model) {
return model.get('data') != 'b';
}), [a, c], 'filter() works');
-
+
deepEqual(shard.reject(function(model) {
return model.get('data') == 'b';
}), [a, c], 'reject() works');
@@ -69,28 +69,28 @@
var sdata = '';
shard.each(function(model) { sdata += model.get('data'); });
equal(sdata, 'abc', 'each() works');
-
+
equal(shard.map(function(model) {
return model.get('data');
}).join(' '), 'a b c', 'map() works');
-
+
shard.invoke('set', 'updated', true);
equal(_.all(shard.pluck('updated')), true, 'invoke() works');
});
test('Underscore methods: data hunt', function() {
equal(shard.pluck('data').join(' '), 'a b c', 'pluck() works');
-
+
equal(shard
.chain()
.map(function(model) { return model.get('data'); })
.first()
.value(), 'a', 'chain() works');
-
+
equal(shard.reduce(function(memo, model) {
return memo += model.get('data');
}, ''), 'abc', 'reduce() works');
-
+
equal(shard.reduceRight(function(memo, model) {
return memo += model.get('data');
}, ''), 'cba', 'reduceRight() works');
@@ -101,11 +101,11 @@
deepEqual(shard.tail(), [b, c], 'tail() works');
deepEqual(shard.drop(), [b, c], 'drop() works');
deepEqual(shard.countBy('data'), {a: 1, b: 1, c: 1}, 'countBy() works');
-
+
deepEqual(shard.select(function(model) {
return model.get('data') != 'b';
}), [a, c], 'select() works');
-
+
equal(shard.foldl(function(memo, model) {
return memo += model.get('data');
}, ''), 'abc', 'foldl() works');