Skip to content

Commit 0f89d56

Browse files
committed
Added more Runtime tests
1 parent f891d60 commit 0f89d56

4 files changed

Lines changed: 38 additions & 13 deletions

File tree

src/Runtime.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,10 @@ class Runner {
9898
}
9999

100100
invokeInclude(statement) {
101-
let path;
101+
const path = statement.value.type === PARSER_TYPE_VARIABLE
102+
? this.getValueFromVariable(statement.value.name)
103+
: statement.value.value;
102104

103-
if (statement.value.type === PARSER_TYPE_VARIABLE) {
104-
path = this.getValueFromVariable(statement.value.name);
105-
}
106-
else {
107-
path = statement.value.value;
108-
}
109105
if (this.astCache[path]) {
110106
this.invokeStatements(this.astCache[path].statements);
111107
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const expect = require('chai').expect;
4+
const Runtime = require('../../src/Runtime');
5+
6+
describe('Runtime.evaluateEquals', function() {
7+
it('should get matching input data', function() {
8+
const runtime = new Runtime();
9+
10+
runtime.input = { foo: 'bar' };
11+
expect(runtime.getValueFromVariable('foo')).to.equal('bar');
12+
});
13+
14+
it('should error on missing input data', function() {
15+
const runtime = new Runtime();
16+
17+
runtime.input = {};
18+
expect(() => runtime.getValueFromVariable('foo')).to.throw(/Unset variable/);
19+
});
20+
});

test/Runtime/Runtime.getValueFromVariable.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
const expect = require('chai').expect;
44
const Runtime = require('../../src/Runtime');
5+
const nb = require('../nodeBuilder');
56

67
describe('Runtime.getValueFromVariable', function() {
7-
it('should get matching input data', function() {
8+
it('should return on not operator', function() {
89
const runtime = new Runtime();
10+
const expression = nb.notConditional(nb.value(true));
911

10-
runtime.input = { foo: 'bar' };
11-
expect(runtime.getValueFromVariable('foo')).to.equal('bar');
12+
expect(runtime.evaluateUnaryExpression(expression)).to.be.false;
1213
});
1314

14-
it('should error on missing input data', function() {
15+
it('should error on unknown operator', function() {
1516
const runtime = new Runtime();
17+
const expression = nb.invalidExpression();
1618

17-
runtime.input = {};
18-
expect(() => runtime.getValueFromVariable('foo')).to.throw(/Unset variable/);
19+
expect(() => runtime.evaluateUnaryExpression(expression)).to.throw(/Unknown operator/);
1920
});
2021
});

test/nodeBuilder.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,13 @@ module.exports = {
8282
condition,
8383
consequent
8484
};
85+
},
86+
invalidExpression() {
87+
return {
88+
type: 'INVALID_EXPRESSION',
89+
left: 'left',
90+
right: 'right',
91+
operator: 'INVALID'
92+
};
8593
}
8694
};

0 commit comments

Comments
 (0)