describe('last', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= last() %>', imports)(), ''); }); it('should return the last item in an array.', function() { assert.equal(template('<%= last(arr) %>', imports)(context), 'h'); }); it('should return an array with the last two items in an array.', function() { assert.deepEqual(template('<%= last(arr, 2) %>', imports)(context), ['g', 'h'].toString()); }); });
describe('first', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= first() %>', imports)(), ''); }); it('should return the first item in an array.', function() { var fn = template('<%= first(foo) %>', imports); assert.equal(fn({foo: ['a', 'b', 'c']}), 'a'); }); it('should return an array with the first two items in an array.', function() { var fn = template('<%= first(foo, 2) %>', imports); assert.deepEqual(fn({foo: ['a', 'b', 'c']}), ['a', 'b'].toString()); }); });
describe('before', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= before() %>', imports)(), ''); }); it('should return all of the items in an array before the given index.', function() { var fn = template('<%= before(arr, 5) %>', imports); assert.deepEqual(fn(context), ['a', 'b', 'c'].toString()); }); });
describe('length', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= length() %>', imports)(), ''); }); it('should return zero when the value is not an array.', function() { var fn = template('<%= length("foo") %>', imports); assert.equal(fn(context), '0'); }); it('should return the length of an array.', function() { var fn = template('<%= length(["b", "c", "a"]) %>', imports); assert.equal(fn(context), '3'); }); });
describe('titlecase', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= titlecase("foo") %>', imports)(), 'Foo'); }); it('should upper case the characters in a string.', function() { var fn = template('<%= titlecase("one two three") %>', imports); assert.equal(fn(), 'One Two Three'); }); });
describe('after', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= after() %>', imports)(), ''); }); it('should return all of the items in an array after the given index.', function() { var fn = template('<%= after(arr, 5) %>', imports); assert.deepEqual(fn(context), ['f', 'g', 'h'].toString()); }); });
describe('compact', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= compact() %>', imports)(), ''); }); it('should remove falsey values from an array.', function() { var fn = template('<%= compact([null, "a", undefined, 0, false, "b", "c", ""]) %>', imports); assert.equal(fn(context), 'a,b,c'); }); });
describe('trim', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= trim() %>', imports)(), ''); }); it('should strip leading whitespace from a string.', function() { var fn = template('<%= trim(" abc") %>', imports); assert.equal(fn(), 'abc'); }); it('should strip trailing whitespace from a string.', function() { var fn = template('<%= trim("abc ") %>', imports); assert.equal(fn(), 'abc'); }); });
describe('unique', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= unique() %>', imports)(), ''); }); it('should unique items from multiple arrays:', function() { var fn = template('<%= unique(["a", "b", "c", "c"]) %>', imports); assert.equal(fn(context), 'a,b,c'); }); });