UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

68 lines (57 loc) 2.38 kB
import { describe, it } from 'mocha' import { assert } from 'chai' import { newIdGenerator } from '../../src/idGenerator' import { generateFreshIds } from '../../src/ir/idRefresher' import { SourceLookupPath } from '../../src/parsing/sourceResolver' import { parse } from '../../src/parsing/quintParserFrontend' import { analyzeModules } from '../../src/quintAnalyzer' import { collectIds } from '../util' import { QuintModule, isDef } from '../../src/ir/quintIr' import JSONbig from 'json-bigint' describe('generateFreshIds', () => { // Generate ids starting from 100, so that we can easily distinguish them from // the ids generated in the parser const mockGenerator = 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 = newIdGenerator() const fake_path: SourceLookupPath = { normalizedPath: 'fake_path', toSourceName: () => 'fake_path' } const quintModules: string = `module A { ${defs.join('\n')} }` const { modules, table, sourceMap, errors } = parse(idGenerator, 'fake_location', fake_path, quintModules) assert.isEmpty(errors, 'Failed to parse mocked up module') const [module] = modules const [analysisErrors, analysisOutput] = analyzeModules(table, modules) it('should analyze the mocked up module', () => { assert.isEmpty(analysisErrors) }) const result = module.declarations .filter(isDef) .map(def => generateFreshIds(def, mockGenerator, sourceMap, analysisOutput)) const newModule: QuintModule = { ...module, declarations: result, id: 200n } it('does not repeat ids', () => { const ids = collectIds(newModule) assert.isTrue( ids.every(id => id >= 100n), `ids should be greater than 100 if they were generated by the mock generator: ${JSONbig.stringify(newModule)}` ) assert.sameDeepMembers(ids, [...new Set(ids)]) }) it('adds new entries to the source map', () => { assert.includeDeepMembers( [...sourceMap.keys()], newModule.declarations.map(def => def.id) ) }) it('adds new entries to the types map', () => { assert.includeDeepMembers( [...analysisOutput.types.keys()], newModule.declarations.filter(def => def.kind !== 'typedef').map(def => def.id) ) }) })