From a22f6a55ae65ca3675f7c97a030560e91d5b4d1f Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 9 Sep 2018 19:43:43 -0400 Subject: js: update api, add luigi-compat.js and test/compat --- js/test/compat/default-filters.js | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 js/test/compat/default-filters.js (limited to 'js/test/compat/default-filters.js') diff --git a/js/test/compat/default-filters.js b/js/test/compat/default-filters.js new file mode 100644 index 0000000..f897485 --- /dev/null +++ b/js/test/compat/default-filters.js @@ -0,0 +1,73 @@ +(function() { + 'use strict'; + var assert = chai.assert; + + [{ + filter: 'uc', + template: 'foo%{bar|uc}', + args: { + bar: 'foo', + }, + expect: 'fooFOO', + }, { + filter: 'lc', + template: 'foo%{bar|lc}', + args: { + bar: 'FOO' + }, + expect: 'foofoo', + }, { + filter: 'h', + template: '%{bar|h}', + args: { + bar: '<>&"\'', + }, + expect: '<>&"'', + }, { + filter: 'u', + template: '%{bar|u}', + args: { + bar: 'asdf<>&"\' \u000f', + }, + expect: 'asdf%3C%3E%26%22%27+%0F' + }, { + filter: 'json', + template: '%{bar|json}', + args: { + bar: { + true: true, + false: false, + null: null, + number: 5, + string: 'foo', + hash: { 'foo': 'bar' }, + array: [0, 1], + }, + }, + expect: '{"true":true,"false":false,"null":null,"number":5,"string":"foo","hash":{"foo":"bar"},"array":[0,1]}', + }, { + filter: 'trim', + template: '%{bar|trim}', + args: { bar: ' \t\v\r\nfoo \t\v\r\n' }, + expect: 'foo' + }, { + filter: 's', + template: 'one foo%{foo|s}, two bar%{bar|s}', + args: { + foo: 1, + bar: 2, + }, + expect: 'one foo, two bars' + }, { + filter: 'length', + template: 'length of bar: %{bar|length}', + args: { + bar: [0, 1, 2], + }, + expect: 'length of bar: 3' + }].forEach(function(row) { + it('default filter: ' + row.filter, function() { + assert.equal(LuigiTemplate.run(row.template, row.args), row.expect); + }); + }); +})(); -- cgit v1.2.3