diff --git a/test/tags/include.js b/test/tags/include.js index d76f9a009..58a5e48bc 100644 --- a/test/tags/include.js +++ b/test/tags/include.js @@ -6,15 +6,76 @@ const ParseError = Liquid.Types.ParseError; chai.use(require("chai-as-promised")); describe('tags/include', function() { - var liquid, ctx; + var liquid; before(function() { liquid = Liquid({ root: '/', extname: '.html' }); }); - beforeEach(function() { - ctx = { + afterEach(function() { + mock.restore(); + }); + it('should support include', function() { + mock({ + '/current.html': 'bar{% include "bar/foo.html" %}bar', + '/bar/foo.html': 'foo' + }); + return expect(liquid.renderFile('/current.html')).to. + eventually.equal('barfoobar'); + }); + + it('should throw when illegal', function() { + mock({ + '/illegal.html': '{%include%}', + }); + return expect(liquid.renderFile('/illegal.html')).to. + be.rejectedWith(ParseError, /illegal token {%include%}/); + }); + + it('should support include with relative path', function() { + mock({ + '/bar/foo.html': 'foo', + '/foo/relative.html': 'bar{% include "../bar/foo.html" %}bar', + }); + return expect(liquid.renderFile('foo/relative.html')).to. + eventually.equal('barfoobar'); + }); + + it('should support include: hash list', function() { + mock({ + '/hash.html': '{% assign name="harttle" %}{% include "user.html", role: "admin", alias: name %}', + '/user.html': '{{name}} : {{role}} : {{alias}}', + }); + return expect(liquid.renderFile('hash.html')).to. + eventually.equal('harttle : admin : harttle'); + }); + + it('should support include: parent scope', function() { + mock({ + '/scope.html': '{% assign shape="triangle" %}{% assign color="yellow" %}{% include "color.html" %}', + '/color.html': 'color:{{color}}, shape:{{shape}}', + }); + return expect(liquid.renderFile('scope.html')).to. + eventually.equal('color:yellow, shape:triangle'); + }); + + it('should support include: with', function() { + mock({ + '/with.html': '{% include "color" with "red", shape: "rect" %}', + '/color.html': 'color:{{color}}, shape:{{shape}}', + }); + return expect(liquid.renderFile('with.html')).to. + eventually.equal('color:red, shape:rect'); + }); + + it('should support nested includes', function() { + mock({ + '/personInfo.html': 'This is a person {% include "card.html" %}', + '/card.html': '
{{person.firstName}} {{person.lastName}}
{% include "address" %}
{{person.firstName}} {{person.lastName}}
{% include "address" %}
Joe Shmoe
City: Dallas