twigg-app 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/javascripts/_bootstrap.js +7 -0
- data/assets/javascripts/_jquery.js +19 -0
- data/assets/javascripts/_tables.js +3 -0
- data/assets/javascripts/_views.js +10 -0
- data/assets/javascripts/application.js +9 -0
- data/{public/application.js → assets/javascripts/views/_commit_set_bar_chart.js} +32 -34
- data/assets/javascripts/views/_russia.js +61 -0
- data/assets/javascripts/views/_tags.js +56 -0
- data/assets/javascripts/views/_tags_word_cloud.js +51 -0
- data/assets/stylesheets/_bootstrap_overrides.scss +15 -0
- data/assets/stylesheets/_footer.scss +28 -0
- data/assets/stylesheets/_global.scss +14 -0
- data/assets/stylesheets/_tables.scss +20 -0
- data/assets/stylesheets/application.scss +10 -0
- data/assets/stylesheets/d3/_bar_chart.scss +25 -0
- data/assets/stylesheets/d3/_bubble_chart.scss +22 -0
- data/lib/twigg-app/app/routes.rb +4 -0
- data/lib/twigg-app/app/server.rb +78 -21
- data/lib/twigg-app/app/version.rb +1 -1
- data/public/vendor/bootstrap/Gruntfile.js +32 -10
- data/public/vendor/bootstrap/README.md +2 -0
- data/public/vendor/bootstrap/_config.yml +5 -10
- data/public/vendor/bootstrap/_includes/footer.html +2 -1
- data/public/vendor/bootstrap/_includes/nav-components.html +33 -31
- data/public/vendor/bootstrap/_includes/nav-css.html +32 -22
- data/public/vendor/bootstrap/_includes/nav-getting-started.html +17 -1
- data/public/vendor/bootstrap/_includes/nav-javascript.html +1 -1
- data/public/vendor/bootstrap/_includes/nav-main.html +1 -1
- data/public/vendor/bootstrap/_includes/social-buttons.html +1 -1
- data/public/vendor/bootstrap/_layouts/default.html +18 -14
- data/public/vendor/bootstrap/_layouts/home.html +9 -6
- data/public/vendor/bootstrap/assets/css/docs.css +584 -396
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/favicon.png +0 -0
- data/public/vendor/bootstrap/assets/js/application.js +2 -1
- data/public/vendor/bootstrap/assets/js/customizer.js +160 -45
- data/public/vendor/bootstrap/assets/js/filesaver.js +169 -0
- data/public/vendor/bootstrap/assets/js/jquery.js +6 -5
- data/public/vendor/bootstrap/assets/js/raw-files.js +3 -0
- data/public/vendor/bootstrap/bower.json +1 -1
- data/public/vendor/bootstrap/components.html +787 -364
- data/public/vendor/bootstrap/composer.json +1 -1
- data/public/vendor/bootstrap/css.html +413 -248
- data/public/vendor/bootstrap/customize.html +413 -447
- data/public/vendor/bootstrap/dist/css/bootstrap-theme.css +384 -0
- data/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css +1 -0
- data/public/vendor/bootstrap/dist/css/bootstrap.css +3033 -1807
- data/public/vendor/bootstrap/dist/css/bootstrap.min.css +1 -1
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +228 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/vendor/bootstrap/dist/js/bootstrap.js +18 -12
- data/public/vendor/bootstrap/dist/js/bootstrap.min.js +1 -1
- data/public/vendor/bootstrap/examples/carousel/carousel.css +128 -0
- data/public/vendor/bootstrap/examples/carousel/index.html +201 -0
- data/public/vendor/bootstrap/examples/grid/grid.css +28 -0
- data/public/vendor/bootstrap/examples/grid/index.html +119 -0
- data/public/vendor/bootstrap/examples/jumbotron/index.html +111 -0
- data/public/vendor/bootstrap/examples/jumbotron/jumbotron.css +5 -0
- data/public/vendor/bootstrap/examples/jumbotron-narrow/index.html +78 -0
- data/public/vendor/bootstrap/examples/jumbotron-narrow/jumbotron-narrow.css +79 -0
- data/public/vendor/bootstrap/examples/justified-nav/index.html +79 -0
- data/public/vendor/bootstrap/examples/justified-nav/justified-nav.css +88 -0
- data/public/vendor/bootstrap/examples/navbar/index.html +83 -0
- data/public/vendor/bootstrap/examples/navbar/navbar.css +7 -0
- data/public/vendor/bootstrap/examples/navbar-fixed-top/index.html +86 -0
- data/public/vendor/bootstrap/examples/navbar-fixed-top/navbar-fixed-top.css +4 -0
- data/public/vendor/bootstrap/examples/navbar-static-top/index.html +87 -0
- data/public/vendor/bootstrap/examples/navbar-static-top/navbar-static-top.css +7 -0
- data/public/vendor/bootstrap/examples/non-responsive/index.html +96 -0
- data/public/vendor/bootstrap/examples/non-responsive/non-responsive.css +117 -0
- data/public/vendor/bootstrap/examples/offcanvas/index.html +127 -0
- data/public/vendor/bootstrap/examples/offcanvas/offcanvas.css +48 -0
- data/public/vendor/bootstrap/examples/offcanvas/offcanvas.js +5 -0
- data/public/vendor/bootstrap/examples/screenshots/carousel.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/grid.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/jumbotron-narrow.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/jumbotron.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/justified-nav.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar-fixed.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar-static.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/non-responsive.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/offcanvas.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sign-in.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/starter-template.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sticky-footer-navbar.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sticky-footer.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/theme.jpg +0 -0
- data/public/vendor/bootstrap/examples/signin/index.html +46 -0
- data/public/vendor/bootstrap/examples/signin/signin.css +40 -0
- data/public/vendor/bootstrap/examples/starter-template/index.html +63 -0
- data/public/vendor/bootstrap/examples/starter-template/starter-template.css +7 -0
- data/public/vendor/bootstrap/examples/sticky-footer/index.html +51 -0
- data/public/vendor/bootstrap/examples/sticky-footer/sticky-footer.css +39 -0
- data/public/vendor/bootstrap/examples/sticky-footer-navbar/index.html +86 -0
- data/public/vendor/bootstrap/examples/sticky-footer-navbar/sticky-footer-navbar.css +46 -0
- data/public/vendor/bootstrap/examples/theme/index.html +387 -0
- data/public/vendor/bootstrap/examples/theme/theme.css +14 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +228 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/vendor/bootstrap/getting-started.html +513 -22
- data/public/vendor/bootstrap/index.html +3 -4
- data/public/vendor/bootstrap/javascript.html +123 -115
- data/public/vendor/bootstrap/js/dropdown.js +3 -3
- data/public/vendor/bootstrap/js/modal.js +5 -3
- data/public/vendor/bootstrap/js/tests/unit/modal.js +19 -0
- data/public/vendor/bootstrap/js/tests/vendor/jquery.js +6 -5
- data/public/vendor/bootstrap/js/tooltip.js +9 -5
- data/public/vendor/bootstrap/js/transition.js +1 -1
- data/public/vendor/bootstrap/less/alerts.less +7 -11
- data/public/vendor/bootstrap/less/bootstrap.less +17 -21
- data/public/vendor/bootstrap/less/button-groups.less +14 -10
- data/public/vendor/bootstrap/less/buttons.less +3 -2
- data/public/vendor/bootstrap/less/carousel.less +6 -1
- data/public/vendor/bootstrap/less/dropdowns.less +22 -5
- data/public/vendor/bootstrap/less/forms.less +36 -15
- data/public/vendor/bootstrap/less/glyphicons.less +232 -0
- data/public/vendor/bootstrap/less/grid.less +9 -3
- data/public/vendor/bootstrap/less/input-groups.less +1 -1
- data/public/vendor/bootstrap/less/jumbotron.less +16 -5
- data/public/vendor/bootstrap/less/labels.less +9 -5
- data/public/vendor/bootstrap/less/mixins.less +73 -43
- data/public/vendor/bootstrap/less/modals.less +8 -0
- data/public/vendor/bootstrap/less/navbar.less +251 -189
- data/public/vendor/bootstrap/less/navs.less +13 -12
- data/public/vendor/bootstrap/less/pager.less +1 -1
- data/public/vendor/bootstrap/less/pagination.less +20 -9
- data/public/vendor/bootstrap/less/panels.less +28 -8
- data/public/vendor/bootstrap/less/progress-bars.less +6 -10
- data/public/vendor/bootstrap/less/responsive-utilities.less +120 -49
- data/public/vendor/bootstrap/less/scaffolding.less +37 -18
- data/public/vendor/bootstrap/less/tables.less +84 -59
- data/public/vendor/bootstrap/less/theme.less +232 -0
- data/public/vendor/bootstrap/less/thumbnails.less +8 -19
- data/public/vendor/bootstrap/less/type.less +2 -2
- data/public/vendor/bootstrap/less/variables.less +63 -50
- data/public/vendor/bootstrap/package.json +2 -1
- data/public/vendor/components-backbone/LICENSE +22 -0
- data/public/vendor/components-backbone/README.md +10 -0
- data/public/vendor/components-backbone/backbone-min.js +4 -0
- data/public/vendor/components-backbone/backbone.js +1571 -0
- data/public/vendor/components-backbone/bower.json +17 -0
- data/public/vendor/components-backbone/component.json +21 -0
- data/public/vendor/components-backbone/composer.json +37 -0
- data/public/vendor/components-backbone/package.json +24 -0
- data/public/vendor/d3.layout.cloud.js +401 -0
- data/public/vendor/replacejs/CHANGELOG.md +4 -0
- data/public/vendor/replacejs/replace.js +21 -2
- data/public/vendor/underscore/CNAME +1 -0
- data/public/vendor/underscore/CONTRIBUTING.md +9 -0
- data/public/vendor/underscore/LICENSE +22 -0
- data/public/vendor/underscore/README.md +19 -0
- data/public/vendor/underscore/Rakefile +10 -0
- data/public/vendor/underscore/docs/docco.css +192 -0
- data/public/vendor/underscore/docs/favicon.ico +0 -0
- data/public/vendor/underscore/docs/images/background.png +0 -0
- data/public/vendor/underscore/docs/images/underscore.png +0 -0
- data/public/vendor/underscore/docs/underscore.html +823 -0
- data/public/vendor/underscore/favicon.ico +0 -0
- data/public/vendor/underscore/index.html +2467 -0
- data/public/vendor/underscore/index.js +1 -0
- data/public/vendor/underscore/package.json +16 -0
- data/public/vendor/underscore/test/arrays.js +200 -0
- data/public/vendor/underscore/test/chaining.js +59 -0
- data/public/vendor/underscore/test/collections.js +453 -0
- data/public/vendor/underscore/test/functions.js +265 -0
- data/public/vendor/underscore/test/index.html +44 -0
- data/public/vendor/underscore/test/objects.js +570 -0
- data/public/vendor/underscore/test/speed.js +75 -0
- data/public/vendor/underscore/test/utility.js +266 -0
- data/public/vendor/underscore/test/vendor/jquery.js +9404 -0
- data/public/vendor/underscore/test/vendor/jslitmus.js +670 -0
- data/public/vendor/underscore/test/vendor/qunit.css +235 -0
- data/public/vendor/underscore/test/vendor/qunit.js +1977 -0
- data/public/vendor/underscore/test/vendor/runner.js +98 -0
- data/public/vendor/underscore/underscore-min.js +1 -0
- data/public/vendor/underscore/underscore.js +1226 -0
- data/views/dashboard.haml +1 -1
- data/views/layout.haml +8 -4
- metadata +132 -25
- data/public/vendor/bootstrap/_layouts/customize.html +0 -52
- data/public/vendor/bootstrap/assets/js/jquery.bbq.min.js +0 -1287
- data/public/vendor/bootstrap-glyphicons/CHANGELOG.md +0 -3
- data/public/vendor/bootstrap-glyphicons/CNAME +0 -1
- data/public/vendor/bootstrap-glyphicons/CONTRIBUTING.md +0 -54
- data/public/vendor/bootstrap-glyphicons/LICENSE +0 -19
- data/public/vendor/bootstrap-glyphicons/README.md +0 -61
- data/public/vendor/bootstrap-glyphicons/_config.yml +0 -12
- data/public/vendor/bootstrap-glyphicons/composer.json +0 -9
- data/public/vendor/bootstrap-glyphicons/css/bootstrap-glyphicons.css +0 -2
- data/public/vendor/bootstrap-glyphicons/css/bootstrap.css +0 -9
- data/public/vendor/bootstrap-glyphicons/css/docs.css +0 -160
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.eot +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.otf +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.svg +0 -175
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.ttf +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.woff +0 -0
- data/public/vendor/bootstrap-glyphicons/index.html +0 -255
- data/public/vendor/bootstrap-glyphicons/less/bootstrap-glyphicons.less +0 -201
- data/public/vendor/bootstrap-glyphicons/package.json +0 -18
@@ -0,0 +1,453 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
module("Collections");
|
4
|
+
|
5
|
+
test("each", function() {
|
6
|
+
_.each([1, 2, 3], function(num, i) {
|
7
|
+
equal(num, i + 1, 'each iterators provide value and iteration count');
|
8
|
+
});
|
9
|
+
|
10
|
+
var answers = [];
|
11
|
+
_.each([1, 2, 3], function(num){ answers.push(num * this.multiplier);}, {multiplier : 5});
|
12
|
+
equal(answers.join(', '), '5, 10, 15', 'context object property accessed');
|
13
|
+
|
14
|
+
answers = [];
|
15
|
+
_.forEach([1, 2, 3], function(num){ answers.push(num); });
|
16
|
+
equal(answers.join(', '), '1, 2, 3', 'aliased as "forEach"');
|
17
|
+
|
18
|
+
answers = [];
|
19
|
+
var obj = {one : 1, two : 2, three : 3};
|
20
|
+
obj.constructor.prototype.four = 4;
|
21
|
+
_.each(obj, function(value, key){ answers.push(key); });
|
22
|
+
equal(answers.join(", "), 'one, two, three', 'iterating over objects works, and ignores the object prototype.');
|
23
|
+
delete obj.constructor.prototype.four;
|
24
|
+
|
25
|
+
var answer = null;
|
26
|
+
_.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; });
|
27
|
+
ok(answer, 'can reference the original collection from inside the iterator');
|
28
|
+
|
29
|
+
answers = 0;
|
30
|
+
_.each(null, function(){ ++answers; });
|
31
|
+
equal(answers, 0, 'handles a null properly');
|
32
|
+
});
|
33
|
+
|
34
|
+
test('map', function() {
|
35
|
+
var doubled = _.map([1, 2, 3], function(num){ return num * 2; });
|
36
|
+
equal(doubled.join(', '), '2, 4, 6', 'doubled numbers');
|
37
|
+
|
38
|
+
doubled = _.collect([1, 2, 3], function(num){ return num * 2; });
|
39
|
+
equal(doubled.join(', '), '2, 4, 6', 'aliased as "collect"');
|
40
|
+
|
41
|
+
var tripled = _.map([1, 2, 3], function(num){ return num * this.multiplier; }, {multiplier : 3});
|
42
|
+
equal(tripled.join(', '), '3, 6, 9', 'tripled numbers with context');
|
43
|
+
|
44
|
+
var doubled = _([1, 2, 3]).map(function(num){ return num * 2; });
|
45
|
+
equal(doubled.join(', '), '2, 4, 6', 'OO-style doubled numbers');
|
46
|
+
|
47
|
+
if (document.querySelectorAll) {
|
48
|
+
var ids = _.map(document.querySelectorAll('#map-test *'), function(n){ return n.id; });
|
49
|
+
deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on NodeLists.');
|
50
|
+
}
|
51
|
+
|
52
|
+
var ids = _.map($('#map-test').children(), function(n){ return n.id; });
|
53
|
+
deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on jQuery Array-likes.');
|
54
|
+
|
55
|
+
var ids = _.map(document.images, function(n){ return n.id; });
|
56
|
+
ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections');
|
57
|
+
|
58
|
+
var ifnull = _.map(null, function(){});
|
59
|
+
ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly');
|
60
|
+
});
|
61
|
+
|
62
|
+
test('reduce', function() {
|
63
|
+
var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; }, 0);
|
64
|
+
equal(sum, 6, 'can sum up an array');
|
65
|
+
|
66
|
+
var context = {multiplier : 3};
|
67
|
+
sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num * this.multiplier; }, 0, context);
|
68
|
+
equal(sum, 18, 'can reduce with a context object');
|
69
|
+
|
70
|
+
sum = _.inject([1, 2, 3], function(sum, num){ return sum + num; }, 0);
|
71
|
+
equal(sum, 6, 'aliased as "inject"');
|
72
|
+
|
73
|
+
sum = _([1, 2, 3]).reduce(function(sum, num){ return sum + num; }, 0);
|
74
|
+
equal(sum, 6, 'OO-style reduce');
|
75
|
+
|
76
|
+
var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; });
|
77
|
+
equal(sum, 6, 'default initial value');
|
78
|
+
|
79
|
+
var ifnull;
|
80
|
+
try {
|
81
|
+
_.reduce(null, function(){});
|
82
|
+
} catch (ex) {
|
83
|
+
ifnull = ex;
|
84
|
+
}
|
85
|
+
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
|
86
|
+
|
87
|
+
ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
|
88
|
+
equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
|
89
|
+
raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
|
90
|
+
});
|
91
|
+
|
92
|
+
test('reduceRight', function() {
|
93
|
+
var list = _.reduceRight(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, '');
|
94
|
+
equal(list, 'bazbarfoo', 'can perform right folds');
|
95
|
+
|
96
|
+
var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, '');
|
97
|
+
equal(list, 'bazbarfoo', 'aliased as "foldr"');
|
98
|
+
|
99
|
+
var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; });
|
100
|
+
equal(list, 'bazbarfoo', 'default initial value');
|
101
|
+
|
102
|
+
var ifnull;
|
103
|
+
try {
|
104
|
+
_.reduceRight(null, function(){});
|
105
|
+
} catch (ex) {
|
106
|
+
ifnull = ex;
|
107
|
+
}
|
108
|
+
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
|
109
|
+
|
110
|
+
var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; });
|
111
|
+
equal(sum, 6, 'default initial value on object');
|
112
|
+
|
113
|
+
ok(_.reduceRight(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
|
114
|
+
|
115
|
+
equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
|
116
|
+
raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
|
117
|
+
|
118
|
+
// Assert that the correct arguments are being passed.
|
119
|
+
|
120
|
+
var args,
|
121
|
+
memo = {},
|
122
|
+
object = {a: 1, b: 2},
|
123
|
+
lastKey = _.keys(object).pop();
|
124
|
+
|
125
|
+
var expected = lastKey == 'a'
|
126
|
+
? [memo, 1, 'a', object]
|
127
|
+
: [memo, 2, 'b', object];
|
128
|
+
|
129
|
+
_.reduceRight(object, function() {
|
130
|
+
args || (args = _.toArray(arguments));
|
131
|
+
}, memo);
|
132
|
+
|
133
|
+
deepEqual(args, expected);
|
134
|
+
|
135
|
+
// And again, with numeric keys.
|
136
|
+
|
137
|
+
object = {'2': 'a', '1': 'b'};
|
138
|
+
lastKey = _.keys(object).pop();
|
139
|
+
args = null;
|
140
|
+
|
141
|
+
expected = lastKey == '2'
|
142
|
+
? [memo, 'a', '2', object]
|
143
|
+
: [memo, 'b', '1', object];
|
144
|
+
|
145
|
+
_.reduceRight(object, function() {
|
146
|
+
args || (args = _.toArray(arguments));
|
147
|
+
}, memo);
|
148
|
+
|
149
|
+
deepEqual(args, expected);
|
150
|
+
});
|
151
|
+
|
152
|
+
test('find', function() {
|
153
|
+
var array = [1, 2, 3, 4];
|
154
|
+
strictEqual(_.find(array, function(n) { return n > 2; }), 3, 'should return first found `value`');
|
155
|
+
strictEqual(_.find(array, function() { return false; }), void 0, 'should return `undefined` if `value` is not found');
|
156
|
+
});
|
157
|
+
|
158
|
+
test('detect', function() {
|
159
|
+
var result = _.detect([1, 2, 3], function(num){ return num * 2 == 4; });
|
160
|
+
equal(result, 2, 'found the first "2" and broke the loop');
|
161
|
+
});
|
162
|
+
|
163
|
+
test('select', function() {
|
164
|
+
var evens = _.select([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
|
165
|
+
equal(evens.join(', '), '2, 4, 6', 'selected each even number');
|
166
|
+
|
167
|
+
evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
|
168
|
+
equal(evens.join(', '), '2, 4, 6', 'aliased as "filter"');
|
169
|
+
});
|
170
|
+
|
171
|
+
test('reject', function() {
|
172
|
+
var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
|
173
|
+
equal(odds.join(', '), '1, 3, 5', 'rejected each even number');
|
174
|
+
|
175
|
+
var context = "obj";
|
176
|
+
|
177
|
+
var evens = _.reject([1, 2, 3, 4, 5, 6], function(num){
|
178
|
+
equal(context, "obj");
|
179
|
+
return num % 2 != 0;
|
180
|
+
}, context);
|
181
|
+
equal(evens.join(', '), '2, 4, 6', 'rejected each odd number');
|
182
|
+
});
|
183
|
+
|
184
|
+
test('all', function() {
|
185
|
+
ok(_.all([], _.identity), 'the empty set');
|
186
|
+
ok(_.all([true, true, true], _.identity), 'all true values');
|
187
|
+
ok(!_.all([true, false, true], _.identity), 'one false value');
|
188
|
+
ok(_.all([0, 10, 28], function(num){ return num % 2 == 0; }), 'even numbers');
|
189
|
+
ok(!_.all([0, 11, 28], function(num){ return num % 2 == 0; }), 'an odd number');
|
190
|
+
ok(_.all([1], _.identity) === true, 'cast to boolean - true');
|
191
|
+
ok(_.all([0], _.identity) === false, 'cast to boolean - false');
|
192
|
+
ok(_.every([true, true, true], _.identity), 'aliased as "every"');
|
193
|
+
ok(!_.all([undefined, undefined, undefined], _.identity), 'works with arrays of undefined');
|
194
|
+
});
|
195
|
+
|
196
|
+
test('any', function() {
|
197
|
+
var nativeSome = Array.prototype.some;
|
198
|
+
Array.prototype.some = null;
|
199
|
+
ok(!_.any([]), 'the empty set');
|
200
|
+
ok(!_.any([false, false, false]), 'all false values');
|
201
|
+
ok(_.any([false, false, true]), 'one true value');
|
202
|
+
ok(_.any([null, 0, 'yes', false]), 'a string');
|
203
|
+
ok(!_.any([null, 0, '', false]), 'falsy values');
|
204
|
+
ok(!_.any([1, 11, 29], function(num){ return num % 2 == 0; }), 'all odd numbers');
|
205
|
+
ok(_.any([1, 10, 29], function(num){ return num % 2 == 0; }), 'an even number');
|
206
|
+
ok(_.any([1], _.identity) === true, 'cast to boolean - true');
|
207
|
+
ok(_.any([0], _.identity) === false, 'cast to boolean - false');
|
208
|
+
ok(_.some([false, false, true]), 'aliased as "some"');
|
209
|
+
Array.prototype.some = nativeSome;
|
210
|
+
});
|
211
|
+
|
212
|
+
test('include', function() {
|
213
|
+
ok(_.include([1,2,3], 2), 'two is in the array');
|
214
|
+
ok(!_.include([1,3,9], 2), 'two is not in the array');
|
215
|
+
ok(_.contains({moe:1, larry:3, curly:9}, 3) === true, '_.include on objects checks their values');
|
216
|
+
ok(_([1,2,3]).include(2), 'OO-style include');
|
217
|
+
});
|
218
|
+
|
219
|
+
test('invoke', function() {
|
220
|
+
var list = [[5, 1, 7], [3, 2, 1]];
|
221
|
+
var result = _.invoke(list, 'sort');
|
222
|
+
equal(result[0].join(', '), '1, 5, 7', 'first array sorted');
|
223
|
+
equal(result[1].join(', '), '1, 2, 3', 'second array sorted');
|
224
|
+
});
|
225
|
+
|
226
|
+
test('invoke w/ function reference', function() {
|
227
|
+
var list = [[5, 1, 7], [3, 2, 1]];
|
228
|
+
var result = _.invoke(list, Array.prototype.sort);
|
229
|
+
equal(result[0].join(', '), '1, 5, 7', 'first array sorted');
|
230
|
+
equal(result[1].join(', '), '1, 2, 3', 'second array sorted');
|
231
|
+
});
|
232
|
+
|
233
|
+
// Relevant when using ClojureScript
|
234
|
+
test('invoke when strings have a call method', function() {
|
235
|
+
String.prototype.call = function() {
|
236
|
+
return 42;
|
237
|
+
};
|
238
|
+
var list = [[5, 1, 7], [3, 2, 1]];
|
239
|
+
var s = "foo";
|
240
|
+
equal(s.call(), 42, "call function exists");
|
241
|
+
var result = _.invoke(list, 'sort');
|
242
|
+
equal(result[0].join(', '), '1, 5, 7', 'first array sorted');
|
243
|
+
equal(result[1].join(', '), '1, 2, 3', 'second array sorted');
|
244
|
+
delete String.prototype.call;
|
245
|
+
equal(s.call, undefined, "call function removed");
|
246
|
+
});
|
247
|
+
|
248
|
+
test('pluck', function() {
|
249
|
+
var people = [{name : 'moe', age : 30}, {name : 'curly', age : 50}];
|
250
|
+
equal(_.pluck(people, 'name').join(', '), 'moe, curly', 'pulls names out of objects');
|
251
|
+
});
|
252
|
+
|
253
|
+
test('where', function() {
|
254
|
+
var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}];
|
255
|
+
var result = _.where(list, {a: 1});
|
256
|
+
equal(result.length, 3);
|
257
|
+
equal(result[result.length - 1].b, 4);
|
258
|
+
result = _.where(list, {b: 2});
|
259
|
+
equal(result.length, 2);
|
260
|
+
equal(result[0].a, 1);
|
261
|
+
});
|
262
|
+
|
263
|
+
test('findWhere', function() {
|
264
|
+
var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 4}];
|
265
|
+
var result = _.findWhere(list, {a: 1});
|
266
|
+
deepEqual(result, {a: 1, b: 2});
|
267
|
+
result = _.findWhere(list, {b: 4});
|
268
|
+
deepEqual(result, {a: 1, b: 4});
|
269
|
+
});
|
270
|
+
|
271
|
+
test('max', function() {
|
272
|
+
equal(3, _.max([1, 2, 3]), 'can perform a regular Math.max');
|
273
|
+
|
274
|
+
var neg = _.max([1, 2, 3], function(num){ return -num; });
|
275
|
+
equal(neg, 1, 'can perform a computation-based max');
|
276
|
+
|
277
|
+
equal(-Infinity, _.max({}), 'Maximum value of an empty object');
|
278
|
+
equal(-Infinity, _.max([]), 'Maximum value of an empty array');
|
279
|
+
equal(_.max({'a': 'a'}), -Infinity, 'Maximum value of a non-numeric collection');
|
280
|
+
|
281
|
+
equal(299999, _.max(_.range(1,300000)), "Maximum value of a too-big array");
|
282
|
+
});
|
283
|
+
|
284
|
+
test('min', function() {
|
285
|
+
equal(1, _.min([1, 2, 3]), 'can perform a regular Math.min');
|
286
|
+
|
287
|
+
var neg = _.min([1, 2, 3], function(num){ return -num; });
|
288
|
+
equal(neg, 3, 'can perform a computation-based min');
|
289
|
+
|
290
|
+
equal(Infinity, _.min({}), 'Minimum value of an empty object');
|
291
|
+
equal(Infinity, _.min([]), 'Minimum value of an empty array');
|
292
|
+
equal(_.min({'a': 'a'}), Infinity, 'Minimum value of a non-numeric collection');
|
293
|
+
|
294
|
+
var now = new Date(9999999999);
|
295
|
+
var then = new Date(0);
|
296
|
+
equal(_.min([now, then]), then);
|
297
|
+
|
298
|
+
equal(1, _.min(_.range(1,300000)), "Minimum value of a too-big array");
|
299
|
+
});
|
300
|
+
|
301
|
+
test('sortBy', function() {
|
302
|
+
var people = [{name : 'curly', age : 50}, {name : 'moe', age : 30}];
|
303
|
+
people = _.sortBy(people, function(person){ return person.age; });
|
304
|
+
equal(_.pluck(people, 'name').join(', '), 'moe, curly', 'stooges sorted by age');
|
305
|
+
|
306
|
+
var list = [undefined, 4, 1, undefined, 3, 2];
|
307
|
+
equal(_.sortBy(list, _.identity).join(','), '1,2,3,4,,', 'sortBy with undefined values');
|
308
|
+
|
309
|
+
var list = ["one", "two", "three", "four", "five"];
|
310
|
+
var sorted = _.sortBy(list, 'length');
|
311
|
+
equal(sorted.join(' '), 'one two four five three', 'sorted by length');
|
312
|
+
|
313
|
+
function Pair(x, y) {
|
314
|
+
this.x = x;
|
315
|
+
this.y = y;
|
316
|
+
}
|
317
|
+
|
318
|
+
var collection = [
|
319
|
+
new Pair(1, 1), new Pair(1, 2),
|
320
|
+
new Pair(1, 3), new Pair(1, 4),
|
321
|
+
new Pair(1, 5), new Pair(1, 6),
|
322
|
+
new Pair(2, 1), new Pair(2, 2),
|
323
|
+
new Pair(2, 3), new Pair(2, 4),
|
324
|
+
new Pair(2, 5), new Pair(2, 6),
|
325
|
+
new Pair(undefined, 1), new Pair(undefined, 2),
|
326
|
+
new Pair(undefined, 3), new Pair(undefined, 4),
|
327
|
+
new Pair(undefined, 5), new Pair(undefined, 6)
|
328
|
+
];
|
329
|
+
|
330
|
+
var actual = _.sortBy(collection, function(pair) {
|
331
|
+
return pair.x;
|
332
|
+
});
|
333
|
+
|
334
|
+
deepEqual(actual, collection, 'sortBy should be stable');
|
335
|
+
});
|
336
|
+
|
337
|
+
test('groupBy', function() {
|
338
|
+
var parity = _.groupBy([1, 2, 3, 4, 5, 6], function(num){ return num % 2; });
|
339
|
+
ok('0' in parity && '1' in parity, 'created a group for each value');
|
340
|
+
equal(parity[0].join(', '), '2, 4, 6', 'put each even number in the right group');
|
341
|
+
|
342
|
+
var list = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
|
343
|
+
var grouped = _.groupBy(list, 'length');
|
344
|
+
equal(grouped['3'].join(' '), 'one two six ten');
|
345
|
+
equal(grouped['4'].join(' '), 'four five nine');
|
346
|
+
equal(grouped['5'].join(' '), 'three seven eight');
|
347
|
+
|
348
|
+
var context = {};
|
349
|
+
_.groupBy([{}], function(){ ok(this === context); }, context);
|
350
|
+
|
351
|
+
grouped = _.groupBy([4.2, 6.1, 6.4], function(num) {
|
352
|
+
return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor';
|
353
|
+
});
|
354
|
+
equal(grouped.constructor.length, 1);
|
355
|
+
equal(grouped.hasOwnProperty.length, 2);
|
356
|
+
|
357
|
+
var array = [{}];
|
358
|
+
_.groupBy(array, function(value, index, obj){ ok(obj === array); });
|
359
|
+
|
360
|
+
var array = [1, 2, 1, 2, 3];
|
361
|
+
var grouped = _.groupBy(array);
|
362
|
+
equal(grouped['1'].length, 2);
|
363
|
+
equal(grouped['3'].length, 1);
|
364
|
+
});
|
365
|
+
|
366
|
+
test('countBy', function() {
|
367
|
+
var parity = _.countBy([1, 2, 3, 4, 5], function(num){ return num % 2 == 0; });
|
368
|
+
equal(parity['true'], 2);
|
369
|
+
equal(parity['false'], 3);
|
370
|
+
|
371
|
+
var list = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
|
372
|
+
var grouped = _.countBy(list, 'length');
|
373
|
+
equal(grouped['3'], 4);
|
374
|
+
equal(grouped['4'], 3);
|
375
|
+
equal(grouped['5'], 3);
|
376
|
+
|
377
|
+
var context = {};
|
378
|
+
_.countBy([{}], function(){ ok(this === context); }, context);
|
379
|
+
|
380
|
+
grouped = _.countBy([4.2, 6.1, 6.4], function(num) {
|
381
|
+
return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor';
|
382
|
+
});
|
383
|
+
equal(grouped.constructor, 1);
|
384
|
+
equal(grouped.hasOwnProperty, 2);
|
385
|
+
|
386
|
+
var array = [{}];
|
387
|
+
_.countBy(array, function(value, index, obj){ ok(obj === array); });
|
388
|
+
|
389
|
+
var array = [1, 2, 1, 2, 3];
|
390
|
+
var grouped = _.countBy(array);
|
391
|
+
equal(grouped['1'], 2);
|
392
|
+
equal(grouped['3'], 1);
|
393
|
+
});
|
394
|
+
|
395
|
+
test('sortedIndex', function() {
|
396
|
+
var numbers = [10, 20, 30, 40, 50], num = 35;
|
397
|
+
var indexForNum = _.sortedIndex(numbers, num);
|
398
|
+
equal(indexForNum, 3, '35 should be inserted at index 3');
|
399
|
+
|
400
|
+
var indexFor30 = _.sortedIndex(numbers, 30);
|
401
|
+
equal(indexFor30, 2, '30 should be inserted at index 2');
|
402
|
+
|
403
|
+
var objects = [{x: 10}, {x: 20}, {x: 30}, {x: 40}];
|
404
|
+
var iterator = function(obj){ return obj.x; };
|
405
|
+
strictEqual(_.sortedIndex(objects, {x: 25}, iterator), 2);
|
406
|
+
strictEqual(_.sortedIndex(objects, {x: 35}, 'x'), 3);
|
407
|
+
|
408
|
+
var context = {1: 2, 2: 3, 3: 4};
|
409
|
+
iterator = function(obj){ return this[obj]; };
|
410
|
+
strictEqual(_.sortedIndex([1, 3], 2, iterator, context), 1);
|
411
|
+
});
|
412
|
+
|
413
|
+
test('shuffle', function() {
|
414
|
+
var numbers = _.range(10);
|
415
|
+
var shuffled = _.shuffle(numbers).sort();
|
416
|
+
notStrictEqual(numbers, shuffled, 'original object is unmodified');
|
417
|
+
equal(shuffled.join(','), numbers.join(','), 'contains the same members before and after shuffle');
|
418
|
+
});
|
419
|
+
|
420
|
+
test('toArray', function() {
|
421
|
+
ok(!_.isArray(arguments), 'arguments object is not an array');
|
422
|
+
ok(_.isArray(_.toArray(arguments)), 'arguments object converted into array');
|
423
|
+
var a = [1,2,3];
|
424
|
+
ok(_.toArray(a) !== a, 'array is cloned');
|
425
|
+
equal(_.toArray(a).join(', '), '1, 2, 3', 'cloned array contains same elements');
|
426
|
+
|
427
|
+
var numbers = _.toArray({one : 1, two : 2, three : 3});
|
428
|
+
equal(numbers.join(', '), '1, 2, 3', 'object flattened into array');
|
429
|
+
|
430
|
+
// test in IE < 9
|
431
|
+
try {
|
432
|
+
var actual = _.toArray(document.childNodes);
|
433
|
+
} catch(ex) { }
|
434
|
+
|
435
|
+
ok(_.isArray(actual), 'should not throw converting a node list');
|
436
|
+
});
|
437
|
+
|
438
|
+
test('size', function() {
|
439
|
+
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
|
440
|
+
equal(_.size([1, 2, 3]), 3, 'can compute the size of an array');
|
441
|
+
|
442
|
+
var func = function() {
|
443
|
+
return _.size(arguments);
|
444
|
+
};
|
445
|
+
|
446
|
+
equal(func(1, 2, 3, 4), 4, 'can test the size of the arguments object');
|
447
|
+
|
448
|
+
equal(_.size('hello'), 5, 'can compute the size of a string');
|
449
|
+
|
450
|
+
equal(_.size(null), 0, 'handles nulls');
|
451
|
+
});
|
452
|
+
|
453
|
+
});
|