-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab82a26
commit 73afc85
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; |