unit test more stepToBranch scenarios

This commit is contained in:
Michael "Z" Goddard 2019-06-03 18:13:41 -04:00
parent e1254bd8c7
commit 832cfda56b
No known key found for this signature in database
GPG key ID: 762CD40DD5349872

View file

@ -120,15 +120,39 @@ test('stepToBranch', t => {
const r = new Runtime(); const r = new Runtime();
const s = new Sequencer(r); const s = new Sequencer(r);
const th = generateThread(r); const th = generateThread(r);
// Push substack 2 (null).
s.stepToBranch(th, 2, false); s.stepToBranch(th, 2, false);
t.strictEquals(th.peekStack(), null); t.strictEquals(th.peekStack(), null);
th.popStack(); th.popStack();
t.strictEquals(th.peekStackFrame().isLoop, false);
// Push substack 1 (null).
s.stepToBranch(th, 1, false); s.stepToBranch(th, 1, false);
t.strictEquals(th.peekStack(), null); t.strictEquals(th.peekStack(), null);
th.popStack(); th.popStack();
t.strictEquals(th.peekStackFrame().isLoop, false);
// Push loop substack (null).
s.stepToBranch(th, 1, true);
t.strictEquals(th.peekStack(), null);
th.popStack(); th.popStack();
t.strictEquals(th.peekStackFrame().isLoop, true);
// isLoop resets when thread goes to next block.
th.goToNextBlock();
t.strictEquals(th.peekStackFrame().isLoop, false);
th.popStack();
// Push substack 1 (not null).
s.stepToBranch(th, 1, false); s.stepToBranch(th, 1, false);
t.notEquals(th.peekStack(), null); t.notEquals(th.peekStack(), null);
th.popStack();
t.strictEquals(th.peekStackFrame().isLoop, false);
// Push loop substack (not null).
s.stepToBranch(th, 1, true);
t.notEquals(th.peekStack(), null);
th.popStack();
t.strictEquals(th.peekStackFrame().isLoop, true);
// isLoop resets when thread goes to next block.
th.goToNextBlock();
t.strictEquals(th.peekStackFrame().isLoop, false);
t.end(); t.end();
}); });