Skip to content

Commit 521891c

Browse files
committed
add more tests on expr precedence
1 parent a07fe16 commit 521891c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/exprTests.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,11 @@ describe('Test expressions', function() {
200200
ast.children[2].right.what.kind.should.be.exactly('class');
201201
});
202202

203-
it('test nested expressions', function() {
203+
it('test nested expressions precedence', function() {
204204
var ast = parser.parseEval([
205205
'$a = 5 * 2 + 1;', // same as (1 + (5 * 2))
206206
'$b = 5 * (2 + 1);',
207+
'$c = 1 + 2 / 3 + 4;', // same as (1 + (4 + (2 / 3)))
207208
].join('\n'), {
208209
parser: { debug: false }
209210
});
@@ -226,6 +227,20 @@ describe('Test expressions', function() {
226227
bExpr.right.inner.type.should.be.exactly('+');
227228
bExpr.right.inner.right.value.should.be.exactly('1');
228229

230+
var cExpr = ast.children[2].right;
231+
cExpr.kind.should.be.exactly('bin');
232+
cExpr.left.value.should.be.exactly('1');
233+
cExpr.type.should.be.exactly('+');
234+
235+
cExpr.right.kind.should.be.exactly('bin');
236+
cExpr.right.left.value.should.be.exactly('4');
237+
cExpr.right.type.should.be.exactly('+');
238+
239+
cExpr.right.right.kind.should.be.exactly('bin');
240+
cExpr.right.right.left.value.should.be.exactly('2');
241+
cExpr.right.right.type.should.be.exactly('/');
242+
cExpr.right.right.right.value.should.be.exactly('3');
243+
229244
});
230245

231246
});

0 commit comments

Comments
 (0)