Improve compiler output for line validation

This commit improves feedback when a line is too long to enhance
developer/maintainer productivity.

- Trim long lines in output to 500 characters
- Show character count exceeding max line length
- Refactor line formatting for better readability
This commit is contained in:
undergroundwires
2024-09-16 12:39:52 +02:00
parent 98e8dc0a67
commit 8b6067f83f
4 changed files with 197 additions and 140 deletions

View File

@@ -1,11 +1,32 @@
import { expect } from 'vitest';
import type { InvalidCodeLine } from '@/application/Parser/Executable/Script/Validation/Analyzers/CodeValidationAnalyzer';
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
export function expectSameInvalidCodeLines(
expected: readonly InvalidCodeLine[],
actual: readonly InvalidCodeLine[],
) {
expect(sort(expected)).to.deep.equal(sort(actual));
const sortedExpected = sort(expected);
const sortedActual = sort(actual);
expect(sortedActual).to.deep.equal(sortedExpected, formatAssertionMessage([
'Invalid code lines do not match',
`Expected: ${JSON.stringify(sortedExpected, null, 2)}`,
`Actual: ${JSON.stringify(sortedActual, null, 2)}`,
]));
}
export function expectInvalidCodeLines(
actual: readonly InvalidCodeLine[],
expectedInvalidLineNumbers: readonly number[],
) {
const sortedActualLineNumbers = actual.map((a) => a.lineNumber).sort();
const sortedExpectedLineNumbers = [...expectedInvalidLineNumbers].sort();
expect(sortedActualLineNumbers).to.deep.equal(sortedExpectedLineNumbers, formatAssertionMessage([
'Invalid line numbers do not match.',
`Expected (${sortedExpectedLineNumbers.length}): ${sortedExpectedLineNumbers.join(', ')}`,
`Actual (${sortedActualLineNumbers.length}): ${sortedActualLineNumbers.join(', ')}`,
]));
}
function sort(lines: readonly InvalidCodeLine[]) { // To ignore order