mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
$(document).ready(function() {
|
|
|
|
module("Utility functions (uniqueId, template)");
|
|
|
|
test("utility: noConflict", function() {
|
|
var underscore = _.noConflict();
|
|
ok(underscore.isUndefined(_), "The '_' variable has been returned to its previous state.");
|
|
var intersection = underscore.intersect([-1, 0, 1, 2], [1, 2, 3, 4]);
|
|
equals(intersection.join(', '), '1, 2', 'but the intersection function still works');
|
|
window._ = underscore;
|
|
});
|
|
|
|
test("utility: uniqueId", function() {
|
|
var ids = [], i = 0;
|
|
while(i++ < 100) ids.push(_.uniqueId());
|
|
equals(_.uniq(ids).length, ids.length, 'can generate a globally-unique stream of ids');
|
|
});
|
|
|
|
test("utility: template", function() {
|
|
var basicTemplate = _.template("<%= thing %> is gettin' on my noives!");
|
|
var result = basicTemplate({thing : 'This'});
|
|
equals(result, "This is gettin' on my noives!", 'can do basic attribute interpolation');
|
|
var fancyTemplate = _.template("<% for (key in people) { %><li><%= people[key] %></li><% } %>");
|
|
result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
|
|
equals(result, "<li>Moe</li><li>Larry</li><li>Curly</li>", 'can run arbitrary javascript in templates');
|
|
});
|
|
|
|
});
|