[TEST] add a bunch of tests for conditional expressions, fix definition of the 'or' operator

bzr revid: xmo@openerp.com-20110310111925-u3wgbmlz0tgcfwrv
This commit is contained in:
Xavier Morel 2011-03-10 12:19:25 +01:00
parent 3d442a1119
commit 6f48b2a3cc
3 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,33 @@
<templates>
<t t-name="literal-conditional">
<t t-if="true">ok</t>
</t>
<t t-name="boolean-value-conditional">
<t t-if="value">ok</t>
</t>
<t t-name="boolean-value-conditional-false">
<t t-if="value">fail</t>
</t>
<t t-name="negify">
<t t-if="!false">ok</t>
</t>
<t t-name="equality">
<t t-if="1 == 1">ok</t>
</t>
<t t-name="difference">
<t t-if="1 != 2">ok</t>
</t>
<t t-name="and">
<t t-if="true and true">ok</t>
</t>
<t t-name="and-js">
<t t-if="true &amp;&amp; true">ok</t>
</t>
<t t-name="or">
<t t-if="false or true">ok</t>
</t>
<t t-name="or-js">
<t t-if="false || true">ok</t>
</t>
</templates>

View File

@ -77,6 +77,41 @@
equals(render('set-from-body-lookup', {value: 'ok'}), 'ok',
"Set a value looked up in context via @t-set body and @t-esc");
});
module("Conditionals", {
setup: function () {
QWeb.add_template('qweb-test-conditionals.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test('Basic (single boolean) conditionals', function () {
equals(render('literal-conditional', {}), 'ok',
"Test on a literal value");
equals(render('boolean-value-conditional', {value: true}), 'ok',
"Test on a truthy variable value");
equals(render('boolean-value-conditional-false', {value: false}), '',
"Test on a falsy variable value");
});
test('Boolean expressions in conditionals', function () {
equals(render('negify', {}), 'ok',
"Negative");
equals(render('equality', {}), 'ok',
"Equality");
equals(render('difference', {}), 'ok',
"Difference");
equals(render('and', {}), 'ok',
"Boolean and");
equals(render('and-js', {}), 'ok',
"Boolean and via manually escaped JS operator");
equals(render('or', {}), 'ok',
"Boolean or");
equals(render('or-js', {}), 'ok',
"Boolean or using JS operator");
});
});
</script>

View File

@ -48,7 +48,7 @@ var QWeb = {
// 'hi boys and girls' != '' and 1 == 1 -- will be replaced to : 'hi boys && girls' != '' && 1 == 1
// try to find a solution without tokenizing
e = e.replace(/\Wand\W/g, " && ");
e = e.replace(/\Wor\W/g, " and ");
e = e.replace(/\Wor\W/g, " || ");
e = e.replace(/\Wgt\W/g, " > ");
e = e.replace(/\Wgte\W/g, " >= ");
e = e.replace(/\Wlt\W/g, " < ");