@informalsystems/quint
Version:
Core tool for the Quint specification language
53 lines • 2.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mocha_1 = require("mocha");
const chai_1 = require("chai");
const idGenerator_1 = require("../../src/idGenerator");
const idRefresher_1 = require("../../src/ir/idRefresher");
const quintParserFrontend_1 = require("../../src/parsing/quintParserFrontend");
const quintAnalyzer_1 = require("../../src/quintAnalyzer");
const util_1 = require("../util");
const quintIr_1 = require("../../src/ir/quintIr");
const json_bigint_1 = __importDefault(require("json-bigint"));
(0, mocha_1.describe)('generateFreshIds', () => {
// Generate ids starting from 100, so that we can easily distinguish them from
// the ids generated in the parser
const mockGenerator = (0, idGenerator_1.newIdGenerator)(100n);
const defs = [
'var a: int',
'const N: int',
'type MY_TYPE = int',
'assume _ = N > 1',
'val f = Set(1, 2).filter(x => x > 1)',
'def l = val x = false { x }',
];
const idGenerator = (0, idGenerator_1.newIdGenerator)();
const fake_path = { normalizedPath: 'fake_path', toSourceName: () => 'fake_path' };
const quintModules = `module A { ${defs.join('\n')} }`;
const { modules, table, sourceMap, errors } = (0, quintParserFrontend_1.parse)(idGenerator, 'fake_location', fake_path, quintModules);
chai_1.assert.isEmpty(errors, 'Failed to parse mocked up module');
const [module] = modules;
const [analysisErrors, analysisOutput] = (0, quintAnalyzer_1.analyzeModules)(table, modules);
(0, mocha_1.it)('should analyze the mocked up module', () => {
chai_1.assert.isEmpty(analysisErrors);
});
const result = module.declarations
.filter(quintIr_1.isDef)
.map(def => (0, idRefresher_1.generateFreshIds)(def, mockGenerator, sourceMap, analysisOutput));
const newModule = { ...module, declarations: result, id: 200n };
(0, mocha_1.it)('does not repeat ids', () => {
const ids = (0, util_1.collectIds)(newModule);
chai_1.assert.isTrue(ids.every(id => id >= 100n), `ids should be greater than 100 if they were generated by the mock generator: ${json_bigint_1.default.stringify(newModule)}`);
chai_1.assert.sameDeepMembers(ids, [...new Set(ids)]);
});
(0, mocha_1.it)('adds new entries to the source map', () => {
chai_1.assert.includeDeepMembers([...sourceMap.keys()], newModule.declarations.map(def => def.id));
});
(0, mocha_1.it)('adds new entries to the types map', () => {
chai_1.assert.includeDeepMembers([...analysisOutput.types.keys()], newModule.declarations.filter(def => def.kind !== 'typedef').map(def => def.id));
});
});
//# sourceMappingURL=idRefresher.test.js.map