UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

280 lines 10.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mocha_1 = require("mocha"); const chai_1 = require("chai"); const parser_1 = require("../../src/effects/parser"); (0, mocha_1.describe)('parseEffect', () => { (0, mocha_1.it)('parses read and update effect', () => { const effect = (0, parser_1.parseEffect)("Read['x', 'y'] & Update[v]"); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'concrete', stateVariables: [ { name: 'x', reference: 1n }, { name: 'y', reference: 2n }, ], }, }, { kind: 'update', entity: { kind: 'variable', name: 'v' } }, ], }); } }); (0, mocha_1.it)('parses read and temporal effect', () => { const effect = (0, parser_1.parseEffect)("Read['x', 'y'] & Temporal[v]"); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'concrete', stateVariables: [ { name: 'x', reference: 1n }, { name: 'y', reference: 2n }, ], }, }, { kind: 'temporal', entity: { kind: 'variable', name: 'v' } }, ], }); } }); (0, mocha_1.it)('parses temporal effect', () => { const effect = (0, parser_1.parseEffect)('Temporal[v]'); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'concrete', components: [ { kind: 'temporal', entity: { kind: 'variable', name: 'v' }, }, ], }); } }); (0, mocha_1.it)('parses arrow effect', () => { const effect = (0, parser_1.parseEffect)('(Read[v]) => Update[v]'); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'arrow', params: [ { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'variable', name: 'v' }, }, ], }, ], result: { kind: 'concrete', components: [ { kind: 'update', entity: { kind: 'variable', name: 'v' }, }, ], }, }); } }); (0, mocha_1.it)('parses nested arrow effect', () => { const effect = (0, parser_1.parseEffect)('((Pure) => Read[v], (Pure) => E) => Update[v]'); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'arrow', params: [ { kind: 'arrow', params: [{ kind: 'concrete', components: [] }], result: { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'variable', name: 'v' }, }, ], }, }, { kind: 'arrow', params: [{ kind: 'concrete', components: [] }], result: { kind: 'variable', name: 'E' }, }, ], result: { kind: 'concrete', components: [ { kind: 'update', entity: { kind: 'variable', name: 'v' }, }, ], }, }); } }); (0, mocha_1.it)('parses union effect', () => { const effect = (0, parser_1.parseEffect)('(Read[v, w]) => Update[v]'); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'arrow', params: [ { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'union', entities: [ { kind: 'variable', name: 'v' }, { kind: 'variable', name: 'w' }, ], }, }, ], }, ], result: { kind: 'concrete', components: [ { kind: 'update', entity: { kind: 'variable', name: 'v' }, }, ], }, }); } }); (0, mocha_1.it)('parses union effect with concrete vars', () => { const effect = (0, parser_1.parseEffect)("(Read[v, 'x']) => Update[v, 'y']"); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'arrow', params: [ { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'union', entities: [ { kind: 'variable', name: 'v' }, { kind: 'concrete', stateVariables: [{ name: 'x', reference: 1n }] }, ], }, }, ], }, ], result: { kind: 'concrete', components: [ { kind: 'update', entity: { kind: 'union', entities: [ { kind: 'variable', name: 'v' }, { kind: 'concrete', stateVariables: [{ name: 'y', reference: 2n }] }, ], }, }, ], }, }); } }); (0, mocha_1.it)('parses arrow effect with empty args', () => { const effect = (0, parser_1.parseEffect)('() => Update[v]'); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'arrow', params: [], result: { kind: 'concrete', components: [ { kind: 'update', entity: { kind: 'variable', name: 'v' }, }, ], }, }); } }); (0, mocha_1.it)('parses concrete effects with empty vars', () => { const effect = (0, parser_1.parseEffect)('(Read[]) => Update[]'); chai_1.assert.isTrue(effect.isRight()); if (effect.isRight()) { const { value } = effect; chai_1.assert.deepEqual(value, { kind: 'arrow', params: [ { kind: 'concrete', components: [ { kind: 'read', entity: { kind: 'concrete', stateVariables: [] }, }, ], }, ], result: { kind: 'concrete', components: [ { kind: 'update', entity: { kind: 'concrete', stateVariables: [] }, }, ], }, }); } }); (0, mocha_1.it)('throws error when effect is invalid', () => { const effect = (0, parser_1.parseEffect)('Read[v] & Read[w]'); chai_1.assert.isTrue(effect.isLeft()); if (effect.isLeft()) { const { value } = effect; chai_1.assert.sameDeepMembers(value, [ { explanation: "no viable alternative at input 'Read[v]&Read'", locs: [{ start: { line: 0, col: 10, index: 10 }, end: { line: 0, col: 13, index: 13 } }], }, ]); } }); }); //# sourceMappingURL=parser.test.js.map