Merge pull request from towerofnix/while-vm

Implement "while" block
This commit is contained in:
kchadha 2018-04-09 13:48:08 -04:00 committed by GitHub
commit b794e19c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View file

@ -52,6 +52,28 @@ test('repeatUntil', t => {
t.end();
});
test('repeatWhile', t => {
const rt = new Runtime();
const c = new Control(rt);
// Test harness (mocks `util`)
let i = 0;
const repeat = 10;
const util = {
stackFrame: Object.create(null),
startBranch: function () {
i++;
// Note !== instead of ===
c.repeatWhile({CONDITION: (i !== repeat)}, util);
}
};
// Execute test
c.repeatWhile({CONDITION: (i !== repeat)}, util);
t.strictEqual(i, repeat);
t.end();
});
test('forEach', t => {
const rt = new Runtime();
const c = new Control(rt);