aboutsummaryrefslogtreecommitdiff
path: root/js/test/compat/default-filters.js
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-09 19:43:43 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-09 19:43:43 -0400
commita22f6a55ae65ca3675f7c97a030560e91d5b4d1f (patch)
treef1c73f2aa3203a3c375190ae3fb8402594d18af5 /js/test/compat/default-filters.js
parenta498f0b7f0e3b498519160e516d4e4d7c87575e6 (diff)
downloadluigi-template-a22f6a55ae65ca3675f7c97a030560e91d5b4d1f.tar.bz2
luigi-template-a22f6a55ae65ca3675f7c97a030560e91d5b4d1f.zip
js: update api, add luigi-compat.js and test/compat
Diffstat (limited to 'js/test/compat/default-filters.js')
-rw-r--r--js/test/compat/default-filters.js73
1 files changed, 73 insertions, 0 deletions
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: '&lt;&gt;&amp;&quot;&apos;',
+ }, {
+ 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);
+ });
+ });
+})();