bmc-tpl-code-all-around/src/test/suite/linter.test.ts

69 lines
2.8 KiB
TypeScript
Raw Normal View History

import * as assert from 'assert';
import * as vscode from 'vscode';
import { LinterContext } from '../../core/LinterContext';
import { SyntaxRule } from '../../core/rules/SyntaxRule';
import { BlockRule } from '../../core/rules/BlockRule';
suite('Linter Test Suite', () => {
test('SyntaxRule: Warnt bei "=" Zuweisung außerhalb von Bedingungen', () => {
const rule = new SyntaxRule();
const ctx = new LinterContext();
ctx.activePhaseName = 'body'; // Kontext setzen, damit der strict-mode nicht meckert
const rawLine = " my_var = 123;";
// HIER GEFIXT: Wir übergeben ein Array als 5. Argument
rule.checkLine(rawLine.trim(), rawLine, 0, ctx, [rawLine]);
const diag = ctx.diagnostics.find(d => d.message.includes("':=' für Zuweisungen"));
assert.ok(diag !== undefined, "Fehler für falsche Zuweisung erwartet");
});
test('SyntaxRule: Akzeptiert "=" als Vergleich in Bedingungen', () => {
const rule = new SyntaxRule();
const ctx = new LinterContext();
ctx.activePhaseName = 'body';
const rawLine = " if my_var = 123 then";
rule.checkLine(rawLine.trim(), rawLine, 0, ctx, [rawLine]);
// Darf keinen Fehler werfen, da inConditionBlock automatisch auf true geht
assert.strictEqual(ctx.diagnostics.length, 0);
});
test('SyntaxRule: Findet fehlendes Semikolon', () => {
const rule = new SyntaxRule();
const ctx = new LinterContext();
ctx.activePhaseName = 'body';
const rawLine = " my_var := 123";
rule.checkLine(rawLine.trim(), rawLine, 0, ctx, [rawLine]);
const diag = ctx.diagnostics.find(d => d.message.includes("Fehlendes Semikolon"));
assert.ok(diag !== undefined, "Fehler für fehlendes Semikolon erwartet");
});
test('BlockRule: Erzwingt Module-Header', () => {
const rule = new BlockRule();
const ctx = new LinterContext();
const rawLine = "pattern Test 1.0";
rule.checkLine(rawLine.trim(), rawLine, 0, ctx, [rawLine]);
assert.strictEqual(ctx.diagnostics.length, 1);
assert.ok(ctx.diagnostics[0].message.includes("tpl 1.x module"));
});
test('BlockRule: Findet fehlendes Pattern-Log im Body', () => {
const rule = new BlockRule();
const ctx = new LinterContext();
ctx.hasModuleDef = true;
ctx.inBlock = 'pattern';
ctx.currentPatternName = 'TestPattern';
const lines = ['body', ' x := 1;', 'end body;'];
rule.checkLine('body', 'body', 0, ctx, lines);
const logDiag = ctx.diagnostics.find(d => d.code === 'missing_log_start');
assert.ok(logDiag !== undefined, "Erwartet Fehler für fehlendes Log-Statement");
});
});