Skip to content

Commit 8183066

Browse files
committed
Added tests for Runner invokeBranch
1 parent e99cdf1 commit 8183066

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/Runtime.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ class Runner {
9090
else if (statement.type === PARSER_TYPE_BRANCH) {
9191
this.invokeBranch(statement);
9292
}
93-
throw new RuntimeError(`Unexpected statement: ${statement}`);
93+
else {
94+
throw new RuntimeError(`Unexpected statement: ${statement}`);
95+
}
9496
}
9597
}
9698

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const expect = require('chai').expect;
4+
const Runtime = require('../../src/Runtime');
5+
const nb = require('../nodeBuilder');
6+
7+
describe('Runtime.invokeBranch', function() {
8+
let runtime;
9+
10+
beforeEach(function() {
11+
runtime = new Runtime();
12+
});
13+
14+
it('should invoke on true condition', function() {
15+
runtime.invokeBranch(
16+
nb.branch([
17+
nb.conditional(nb.value(false), nb.root(nb.literal('aaa'))),
18+
nb.conditional(nb.value(true), nb.root(nb.literal('bbb')))
19+
])
20+
);
21+
expect(runtime.result).to.deep.equal([ 'bbb' ]);
22+
});
23+
24+
it('should invoke else', function() {
25+
runtime.invokeBranch(
26+
nb.branch([
27+
nb.conditional(nb.value(false), nb.root(nb.literal('aaa'))),
28+
nb.constantConditional(nb.root(nb.literal('bbb')))
29+
])
30+
);
31+
expect(runtime.result).to.deep.equal([ 'bbb' ]);
32+
});
33+
34+
35+
it('should not invoke on false condition', function() {
36+
runtime.invokeBranch(
37+
nb.branch(
38+
nb.conditional(nb.value(false), nb.root(nb.literal('foo')))
39+
)
40+
);
41+
expect(runtime.result).to.deep.equal([]);
42+
});
43+
});

0 commit comments

Comments
 (0)