UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

114 lines 4.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mocha_1 = require("mocha"); const chai_1 = require("chai"); const parser_1 = require("../../src/types/parser"); (0, mocha_1.describe)('parseType', () => { (0, mocha_1.it)('parses tuple of literal types', () => { const type = (0, parser_1.parseType)('(bool, int, str)'); chai_1.assert.isTrue(type.isRight()); type.map(value => chai_1.assert.deepEqual(value, { kind: 'tup', fields: { kind: 'row', fields: [ { fieldName: '0', fieldType: { kind: 'bool', id: 1n } }, { fieldName: '1', fieldType: { kind: 'int', id: 2n } }, { fieldName: '2', fieldType: { kind: 'str', id: 3n } }, ], other: { kind: 'empty' }, }, id: 4n, })); }); (0, mocha_1.it)('parses operator with type vars', () => { const type = (0, parser_1.parseType)('(a, b) => ((a) => b)'); chai_1.assert.isTrue(type.isRight()); type.map(value => chai_1.assert.deepEqual(value, { kind: 'oper', args: [ { kind: 'var', name: 'a', id: 1n }, { kind: 'var', name: 'b', id: 2n }, ], res: { kind: 'oper', args: [{ kind: 'var', name: 'a', id: 3n }], res: { kind: 'var', name: 'b', id: 4n }, id: 5n, }, id: 6n, })); }); // Regression test for https://github.com/informalsystems/quint/issues/1336 (0, mocha_1.it)('parses qualified type constants', () => { const type = (0, parser_1.parseType)('modname::TypeConstructor'); chai_1.assert.isTrue(type.isRight()); type.map(value => { (0, chai_1.assert)(value.kind === 'const'); chai_1.assert.deepEqual(value.name, 'modname::TypeConstructor'); }); }); (0, mocha_1.it)('parses function of const types', () => { const type = (0, parser_1.parseType)('T1 -> (T2 -> T1)'); chai_1.assert.isTrue(type.isRight()); type.map(value => chai_1.assert.deepEqual(value, { kind: 'fun', arg: { kind: 'const', name: 'T1', id: 1n }, res: { kind: 'fun', arg: { kind: 'const', name: 'T2', id: 2n }, res: { kind: 'const', name: 'T1', id: 3n }, id: 4n, }, id: 5n, })); }); (0, mocha_1.it)('parses records of sets and lists', () => { const type = (0, parser_1.parseType)('{ mySet: Set[a], mySeq: List[a] | r }'); chai_1.assert.isTrue(type.isRight()); type.map(value => chai_1.assert.deepEqual(value, { kind: 'rec', fields: { kind: 'row', fields: [ { fieldName: 'mySet', fieldType: { kind: 'set', elem: { kind: 'var', name: 'a', id: 1n }, id: 2n } }, { fieldName: 'mySeq', fieldType: { kind: 'list', elem: { kind: 'var', name: 'a', id: 3n }, id: 4n } }, ], other: { kind: 'var', name: 'r' }, }, id: 5n, })); }); (0, mocha_1.it)('parses type application', () => { const type = (0, parser_1.parseType)('Foo[int, bool, str]'); chai_1.assert.isTrue(type.isRight()); type.map(value => chai_1.assert.deepEqual(value, { kind: 'app', ctor: { kind: 'const', name: 'Foo', id: 5n }, args: [ { kind: 'int', id: 1n }, { kind: 'bool', id: 2n }, { kind: 'str', id: 3n }, ], id: 4n, })); }); (0, mocha_1.it)('throws error when type is invalid', () => { const type = (0, parser_1.parseType)('Set(int, bool)'); chai_1.assert.isTrue(type.isLeft()); type.mapLeft(error => chai_1.assert.deepEqual(error[0].explanation, '[QNT009] Use square brackets instead of parenthesis for type application: Set[int, bool]')); }); (0, mocha_1.it)('throws error when row separators are invalid', () => { const type = (0, parser_1.parseType)('{ f1: int, | r }'); chai_1.assert.isTrue(type.isLeft()); type.mapLeft(error => chai_1.assert.sameDeepMembers(error, [ { // TODO We should not expect a '=>' here, // but do because of https://github.com/informalsystems/quint/issues/456 explanation: "mismatched input '|' expecting '}'", locs: [{ start: { line: 0, col: 11, index: 11 }, end: { line: 0, col: 11, index: 11 } }], }, ])); }); }); //# sourceMappingURL=parser.test.js.map