forked from mozilla/nunjucks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python slice support to jinja-compat. fixes mozilla#188
- Loading branch information
Showing
6 changed files
with
270 additions
and
11 deletions.
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
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
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
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 |
---|---|---|
|
@@ -1294,5 +1294,6 @@ module.exports = { | |
p.extensions = extensions; | ||
} | ||
return p.parseAsRoot(); | ||
} | ||
}, | ||
Parser: Parser | ||
}; |
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,100 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
var nunjucks, util; | ||
|
||
if(typeof require !== 'undefined') { | ||
nunjucks = require('../index.js'); | ||
util = require('./util'); | ||
} | ||
else { | ||
nunjucks = window.nunjucks; | ||
util = window.util; | ||
} | ||
|
||
var equal = util.jinjaEqual; | ||
var finish = util.finish; | ||
|
||
describe('jinja-compat', function() { | ||
var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; | ||
|
||
it('should support array slices with start and stop', function(done) { | ||
equal('{% for i in arr[1:4] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'bcd'); | ||
finish(done); | ||
}); | ||
it('should support array slices using expressions', function(done) { | ||
equal('{% for i in arr[n:n+3] %}{{ i }}{% endfor %}', | ||
{ n: 1, arr: arr }, | ||
'bcd'); | ||
finish(done); | ||
}); | ||
it('should support array slices with start', function(done) { | ||
equal('{% for i in arr[3:] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'defgh'); | ||
finish(done); | ||
}); | ||
it('should support array slices with negative start', function(done) { | ||
equal('{% for i in arr[-3:] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'fgh'); | ||
finish(done); | ||
}); | ||
it('should support array slices with stop', function(done) { | ||
equal('{% for i in arr[:4] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'abcd'); | ||
finish(done); | ||
}); | ||
it('should support array slices with negative stop', function(done) { | ||
equal('{% for i in arr[:-3] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'abcde'); | ||
finish(done); | ||
}); | ||
it('should support array slices with step', function(done) { | ||
equal('{% for i in arr[::2] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'aceg'); | ||
finish(done); | ||
}); | ||
it('should support array slices with negative step', function(done) { | ||
equal('{% for i in arr[::-1] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'hgfedcba'); | ||
finish(done); | ||
}); | ||
it('should support array slices with start and negative step', function(done) { | ||
equal('{% for i in arr[4::-1] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'edcba'); | ||
finish(done); | ||
}); | ||
it('should support array slices with negative start and negative step', function(done) { | ||
equal('{% for i in arr[-5::-1] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'dcba'); | ||
finish(done); | ||
}); | ||
it('should support array slices with stop and negative step', function(done) { | ||
equal('{% for i in arr[:3:-1] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'hgfe'); | ||
finish(done); | ||
}); | ||
it('should support array slices with start and step', function(done) { | ||
equal('{% for i in arr[1::2] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'bdfh'); | ||
finish(done); | ||
}); | ||
it('should support array slices with start, stop, and step', function(done) { | ||
equal('{% for i in arr[1:7:2] %}{{ i }}{% endfor %}', | ||
{ arr: arr }, | ||
'bdf'); | ||
finish(done); | ||
}); | ||
}); | ||
})(); |
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