aboutsummaryrefslogtreecommitdiff
path: root/js/test/compat/cache.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/cache.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/cache.js')
-rw-r--r--js/test/compat/cache.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/js/test/compat/cache.js b/js/test/compat/cache.js
new file mode 100644
index 0000000..22490c1
--- /dev/null
+++ b/js/test/compat/cache.js
@@ -0,0 +1,58 @@
+(function() {
+ 'use strict';
+ var assert = chai.assert;
+
+ it('cache', function() {
+ var cache = new LuigiTemplate.Cache({
+ foo: 'foo%{bar}',
+ });
+
+ var r = cache.run('foo', {
+ bar: 'foo',
+ });
+
+ assert.equal(r, 'foofoo');
+ });
+
+ it('cache with array', function() {
+ var cache = new LuigiTemplate.Cache({
+ foo: ['foo%{bar}'],
+ });
+
+ var r = cache.run('foo', {
+ bar: 'foo',
+ });
+
+ assert.equal(r, 'foofoo');
+ });
+
+ it('cache singleton', function() {
+ var cache = LuigiTemplate.cache({
+ foo: 'foo%{bar}',
+ });
+
+ var r = cache.run('foo', {
+ bar: 'foo',
+ });
+
+ assert.equal(r, 'foofoo');
+ });
+
+
+ it('cache with custom filters', function() {
+ var cache = LuigiTemplate.cache({
+ foo: ['foo%{bar | cache-barify}'],
+ }, {
+ 'cache-barify': function(s) {
+ return 'bar-' + s + '-bar';
+ },
+ });
+
+ // run template from cache, get result
+ var r = cache.run('foo', {
+ bar: 'foo',
+ });
+
+ assert.equal(r, 'foobar-foo-bar');
+ });
+})();