Skip to content

Commit

Permalink
test: iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Nov 1, 2016
1 parent ab82a26 commit 73afc85
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"license": "MIT",
"scripts": {
"test": "nyc mocha"
"test": "nyc mocha test/*.test.js"
},
"dependencies": {},
"devDependencies": {
Expand Down
File renamed without changes.
42 changes: 42 additions & 0 deletions test/iteration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

var test = require('./util').test;
var assert = require('assert')
var doT = require('../doT');


describe('iteration', function() {
describe('without index', function() {
it('should repeat string N times', function() {
test([
'{{~it.arr:x}}*{{~}}',
'{{~ it.arr:x }}*{{~}}',
'{{~ it.arr: x }}*{{~}}',
'{{~ it.arr :x }}*{{~}}'
], {arr: Array(3)}, '***');
});

it('should concatenate items', function() {
test(['{{~it.arr:x}}{{=x}}{{~}}'], {arr: [1,2,3]}, '123');
});
});

describe('with index', function() {
it('should repeat string N times', function() {
test([
'{{~it.arr:x:i}}*{{~}}',
'{{~ it.arr : x : i }}*{{~}}'
], {arr: Array(3)}, '***');
});

it('should concatenate indices', function() {
test(['{{~it.arr:x:i}}{{=i}}{{~}}'], {arr: Array(3)}, '012');
});

it('should concatenate indices and items', function() {
test([
'{{~it.arr:x:i}}{{?i}}, {{?}}{{=i}}:{{=x}}{{~}}'
], {arr: [10,20,30]}, '0:10, 1:20, 2:30');
});
});
});
11 changes: 11 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

var assert = require('assert')
var doT = require('../doT');

exports.test = function (templates, data, result) {
templates.forEach(function (tmpl) {
var fn = doT.template(tmpl);
assert.strictEqual(fn(data), result);
});
};

0 comments on commit 73afc85

Please sign in to comment.