@informalsystems/quint
Version:
Core tool for the Quint specification language
95 lines • 3.55 kB
JavaScript
"use strict";
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 errorReporter_1 = require("../src/errorReporter");
const line_column_1 = __importDefault(require("line-column"));
(0, mocha_1.describe)('errorReporter', () => {
const text = `module test {
def op = "value"
}`;
const sourceCode = new Map([['file', text]]);
const finder = new Map([['file', (0, line_column_1.default)(text)]]);
(0, mocha_1.it)('highlights the middle line', () => {
const message = {
explanation: 'error explanation',
locs: [
{
source: 'file',
start: { line: 1, col: 4, index: 17 },
end: { line: 1, col: 7, index: 21 },
},
],
};
const expectedError = `file:2:5 - error: error explanation
2: def op = "value"
^^^^`;
const error = (0, errorReporter_1.formatError)(sourceCode, finder, message).trim();
chai_1.assert.equal(error, expectedError);
});
(0, mocha_1.it)('highlights the first 2 lines', () => {
const message = {
explanation: 'error explanation',
locs: [
{
source: 'file',
start: { line: 0, col: 4, index: 4 },
end: { line: 1, col: 7, index: 21 },
},
],
};
const expectedError = `file:1:5 - error: error explanation
1: module test {
^^^^^^^^^
2: def op = "value"
^^^^^^^^`;
const error = (0, errorReporter_1.formatError)(sourceCode, finder, message).trim();
chai_1.assert.equal(error, expectedError);
});
(0, mocha_1.it)('highlights a single char when loc has no end', () => {
const message = {
explanation: 'error explanation',
locs: [
{
source: 'file',
start: { line: 1, col: 4, index: 17 },
},
],
};
const expectedError = `file:2:5 - error: error explanation
2: def op = "value"
^`;
const error = (0, errorReporter_1.formatError)(sourceCode, finder, message).trim();
chai_1.assert.equal(error, expectedError);
});
(0, mocha_1.it)('uses column information when index is 0', () => {
const message = {
explanation: 'error explanation',
locs: [
{
source: 'file',
start: { line: 1, col: 4, index: 0 },
end: { line: 1, col: 7, index: 0 },
},
],
};
const expectedError = `file:2:5 - error: error explanation
2: def op = "value"
^^^^`;
const error = (0, errorReporter_1.formatError)(sourceCode, finder, message).trim();
chai_1.assert.equal(error, expectedError);
});
(0, mocha_1.it)('outputs just explanation when there are no locs', () => {
const message = {
explanation: 'error explanation',
locs: [],
};
const expectedError = 'error: error explanation';
const error = (0, errorReporter_1.formatError)(sourceCode, finder, message).trim();
chai_1.assert.equal(error, expectedError);
});
});
//# sourceMappingURL=errorReporter.test.js.map