From 2cff700e3e59adc2bfcd4b2c536675dfdeb96312 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 9 Sep 2018 03:50:48 -0400 Subject: js: rm test.js, add test/{test.html,*.js} based on mocha/chai --- js/test/filters.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 js/test/filters.js (limited to 'js/test/filters.js') diff --git a/js/test/filters.js b/js/test/filters.js new file mode 100644 index 0000000..c9ba21a --- /dev/null +++ b/js/test/filters.js @@ -0,0 +1,59 @@ +(function() { + 'use strict'; + var assert = chai.assert; + + it('filter', function() { + var t = new LuigiTemplate('foo%{bar|h}'), + r = t.run({ bar: '<' }); + + assert.equal(r, 'foo<'); + }); + + it('filter chain', function() { + var r = LuigiTemplate.run('foo%{bar|uc|lc}', { + bar: 'foo' + }); + + assert.equal(r, 'foofoo'); + }); + + it('custom global filter', function() { + LuigiTemplate.FILTERS.barify = function(s) { + return 'bar-' + s + '-bar'; + }; + + var r = LuigiTemplate.run('foo%{bar | barify}', { + bar: 'foo' + }); + + assert.equal(r, 'foobar-foo-bar'); + }); + + it('custom template filter', function() { + var r = LuigiTemplate.run('foo%{bar | barify}', { + bar: 'foo' + }, { + barify: function(s) { + return 'bar-' + s + '-bar'; + }, + }); + + assert.equal(r, 'foobar-foo-bar'); + }); + + it('filter args', function() { + var r = LuigiTemplate.run('foo%{bar | wrap bar}', { + bar: 'foo' + }, { + wrap: function(s, args) { + if (args.length == 1) { + return [args[0], s, args[0]].join('-'); + } else { + return s; + } + }, + }); + + assert.equal(r, 'foobar-foo-bar'); + }); +})(); -- cgit v1.2.3