@informalsystems/quint
Version:
Core tool for the Quint specification language
99 lines • 4.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mocha_1 = require("mocha");
const chai_1 = require("chai");
const trace_1 = require("../../src/runtime/trace");
const verbosity_1 = require("../../src/verbosity");
const rng_1 = require("../../src/rng");
const either_1 = require("@sweet-monads/either");
const emptyFrameError = { code: 'QNT501', message: 'empty frame' };
(0, mocha_1.describe)('newTraceRecorder', () => {
(0, mocha_1.it)('one layer', () => {
const rec = (0, trace_1.newTraceRecorder)(verbosity_1.verbosity.maxVerbosity, (0, rng_1.newRng)());
const A = { id: 0n, kind: 'app', opcode: 'A', args: [] };
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
const trace = rec.currentFrame;
(0, chai_1.assert)(trace.subframes.length === 2);
(0, chai_1.assert)(trace.subframes[0].app === A);
(0, chai_1.assert)(trace.subframes[0].subframes.length === 0);
(0, chai_1.assert)(trace.subframes[1].app === A);
(0, chai_1.assert)(trace.subframes[1].subframes.length === 0);
});
(0, mocha_1.it)('two layers', () => {
const rec = (0, trace_1.newTraceRecorder)(verbosity_1.verbosity.maxVerbosity, (0, rng_1.newRng)());
const A = { id: 0n, kind: 'app', opcode: 'A', args: [] };
const B = { id: 0n, kind: 'app', opcode: 'B', args: [] };
// (A calls (B, after that it calls A)), after that another A is called
rec.onUserOperatorCall(A);
rec.onUserOperatorCall(B);
rec.onUserOperatorReturn(B, [], (0, either_1.left)(emptyFrameError));
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
const trace = rec.currentFrame;
(0, chai_1.assert)(trace.subframes.length === 2);
(0, chai_1.assert)(trace.subframes[0].app === A);
(0, chai_1.assert)(trace.subframes[0].subframes.length === 2);
(0, chai_1.assert)(trace.subframes[0].subframes[0].app === B);
(0, chai_1.assert)(trace.subframes[0].subframes[1].app === A);
(0, chai_1.assert)(trace.subframes[1].app === A);
(0, chai_1.assert)(trace.subframes[1].subframes.length === 0);
});
(0, mocha_1.it)('any {...} mixed', () => {
const rec = (0, trace_1.newTraceRecorder)(verbosity_1.verbosity.maxVerbosity, (0, rng_1.newRng)());
const A = { id: 0n, kind: 'app', opcode: 'A', args: [] };
const B = { id: 0n, kind: 'app', opcode: 'B', args: [] };
const C = { id: 0n, kind: 'app', opcode: 'C', args: [] };
const anyEx = {
id: 0n,
kind: 'app',
opcode: 'any',
args: [A, B, C],
};
// A()
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
// any {
rec.onAnyOptionCall(anyEx, 0);
// A()
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
rec.onAnyOptionReturn(anyEx, 0);
rec.onAnyOptionCall(anyEx, 1);
// B()
rec.onUserOperatorCall(B);
rec.onUserOperatorReturn(B, [], (0, either_1.left)(emptyFrameError));
// C()
rec.onUserOperatorCall(C);
rec.onUserOperatorReturn(C, [], (0, either_1.left)(emptyFrameError));
rec.onAnyOptionReturn(anyEx, 1);
rec.onAnyOptionCall(anyEx, 2);
// C()
rec.onUserOperatorCall(C);
rec.onUserOperatorReturn(C, [], (0, either_1.left)(emptyFrameError));
rec.onAnyOptionReturn(anyEx, 2);
rec.onAnyReturn(3, 1);
// } // any
rec.onUserOperatorCall(A);
rec.onUserOperatorReturn(A, [], (0, either_1.left)(emptyFrameError));
const trace = rec.currentFrame;
(0, chai_1.assert)(trace.subframes.length === 4);
// A() is the operator before `any { ... }`
(0, chai_1.assert)(trace.subframes[0].app === A);
(0, chai_1.assert)(trace.subframes[0].subframes.length === 0);
// A() and C() are from option 1
(0, chai_1.assert)(trace.subframes[1].app === B);
(0, chai_1.assert)(trace.subframes[1].subframes.length === 0);
(0, chai_1.assert)(trace.subframes[2].app === C);
(0, chai_1.assert)(trace.subframes[2].subframes.length === 0);
// A() is the operator after `any { ... }`
(0, chai_1.assert)(trace.subframes[3].app === A);
(0, chai_1.assert)(trace.subframes[3].subframes.length === 0);
});
});
//# sourceMappingURL=trace.test.js.map