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

45 lines
1.8 KiB
TypeScript
Raw Normal View History

import * as assert from 'assert';
import { LinterContext } from '../../core/LinterContext';
import { SyntaxRule } from '../../core/rules/SyntaxRule';
suite('Linter SyntaxRule Test Suite', () => {
test('Zuweisung: Warnt bei "=" statt ":="', () => {
const rule = new SyntaxRule();
const ctx = new LinterContext();
// Wir simulieren eine Code-Zeile
const rawLine = " my_var = 123;";
rule.checkLine(rawLine.trim(), rawLine, 0, ctx);
// Erwartung: Ein Fehler wegen falscher Zuweisung
assert.strictEqual(ctx.diagnostics.length, 1);
assert.ok(ctx.diagnostics[0].message.includes("In TPL wird ':=' für Zuweisungen genutzt"));
});
test('Zuweisung: Akzeptiert "=" als Vergleich in if-Bedingung', () => {
const rule = new SyntaxRule();
const ctx = new LinterContext();
// Wir simulieren eine if-Zeile (setzt ctx.inConditionBlock intern auf true)
const rawLine = " if my_var = 123 then";
rule.checkLine(rawLine.trim(), rawLine, 0, ctx);
// Erwartung: Kein Fehler, da das = als Vergleich legitim ist
assert.strictEqual(ctx.diagnostics.length, 0);
});
test('Klammern: Findet ungeschlossene runde Klammern', () => {
const rule = new SyntaxRule();
const ctx = new LinterContext();
// Wir öffnen eine Klammer, schließen sie aber nicht
const rawLine = " my_func(parameter;";
rule.checkLine(rawLine.trim(), rawLine, 0, ctx);
// checkEnd wird am Ende der Datei aufgerufen
rule.checkEnd(['', rawLine], ctx);
assert.strictEqual(ctx.diagnostics.length, 1);
assert.ok(ctx.diagnostics[0].message.includes("Öffnende Klammer '(' wird nicht geschlossen!"));
});
});