Skip to content

Commit

Permalink
Adding tests for using extends with context vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Taka Kojima committed Jul 28, 2012
1 parent 17a684d commit d1deac2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ exports.compileFile = testCase({
test.done();
},

'using context var with extends tag' : function (test) {
swig.init({
root: __dirname + '/tests/templates',
allowErrors: true
});

var tpl, r1, r2, r3, r4;

tpl = swig.compileFile('extends_dynamic.html');
r1 = tpl.render({baseTmpl: "extends_base.html"});
r2 = tpl.render({baseTmpl: "extends_base2.html"});
r3 = tpl.render({baseTmpl: "extends_base.html"});
r4 = tpl.render({baseTmpl: "extends_base2.html"});

test.strictEqual(r1,r3, "this should not throw");
test.strictEqual(r2,r4, "this should not throw");

test.notEqual(r1, r2, "these should not be equal, as they use different base templates.");

test.done();
},

'absolute path': function (test) {
swig.init({
root: __dirname + '/tests/templates',
Expand Down
9 changes: 9 additions & 0 deletions tests/templates/extends_base2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is from the "extends_base2.html" template.

{% block one %}
This is the default content in block 'one'
{% endblock %}

{% block two %}
This is the default content in block 'two'
{% endblock %}
6 changes: 6 additions & 0 deletions tests/templates/extends_dynamic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends baseTmpl %}
This is content from "extends_dynamic.html", you should not see it

{% block one %}
This is the "extends_dynamic.html" content in block 'one'
{% endblock %}

0 comments on commit d1deac2

Please sign in to comment.