diff options
Diffstat (limited to 'addons/web/static/lib/py.js/test/parser.js')
| -rw-r--r-- | addons/web/static/lib/py.js/test/parser.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/addons/web/static/lib/py.js/test/parser.js b/addons/web/static/lib/py.js/test/parser.js index ca74d2bebc8..bbbd5d7663d 100644 --- a/addons/web/static/lib/py.js/test/parser.js +++ b/addons/web/static/lib/py.js/test/parser.js @@ -11,6 +11,14 @@ expect.Assertion.prototype.tokens = function (n) { 'expected ' + this.obj + ' to not have an end token'); }; +expect.Assertion.prototype.named = function (value) { + this.assert(this.obj.id === '(name)', + 'expected ' + this.obj + ' to be a name token', + 'expected ' + this.obj + ' not to be a name token'); + this.assert(this.obj.value === value, + 'expected ' + this.obj + ' to have tokenized ' + value, + 'expected ' + this.obj + ' not to have tokenized ' + value); +}; expect.Assertion.prototype.constant = function (value) { this.assert(this.obj.id === '(constant)', 'expected ' + this.obj + ' to be a constant token', @@ -98,4 +106,27 @@ describe('Tokenizer', function () { expect(toks[1].id).to.be(')'); }); }); + describe('functions', function () { + it('tokenizes kwargs', function () { + var toks = py.tokenize('foo(bar=3, qux=4)'); + expect(toks).to.have.tokens(10); + }); + }); +}); + +describe('Parser', function () { + describe('functions', function () { + var ast = py.parse(py.tokenize('foo(bar=3, qux=4)')); + expect(ast.id).to.be('('); + expect(ast.first).to.be.named('foo'); + + args = ast.second; + expect(args[0].id).to.be('='); + expect(args[0].first).to.be.named('bar'); + expect(args[0].second).to.be.number(3); + + expect(args[1].id).to.be('='); + expect(args[1].first).to.be.named('qux'); + expect(args[1].second).to.be.number(4); + }); });
\ No newline at end of file |
