2026-10-11 04:11:11 +00:00
|
|
|
import * as assert from 'assert';
|
2026-10-12 19:43:46 +00:00
|
|
|
import * as vscode from 'vscode';
|
2026-10-11 04:11:11 +00:00
|
|
|
import { LinterContext } from '../../core/LinterContext';
|
|
|
|
|
import { SyntaxRule } from '../../core/rules/SyntaxRule';
|
2026-10-12 19:43:46 +00:00
|
|
|
import { BlockRule } from '../../core/rules/BlockRule';
|
2026-10-11 04:11:11 +00:00
|
|
|
|
2026-10-12 19:43:46 +00:00
|
|
|
suite('Linter Test Suite', () => {
|
|
|
|
|
test('SyntaxRule: Warnt bei "=" Zuweisung außerhalb von Bedingungen', () => {
|
2026-10-11 04:11:11 +00:00
|
|
|
const rule = new SyntaxRule();
|
|
|
|
|
const ctx = new LinterContext();
|
2026-10-12 19:43:46 +00:00
|
|
|
ctx.activePhaseName = 'body'; // Kontext setzen, damit der strict-mode nicht meckert
|
2026-10-11 04:11:11 +00:00
|
|
|
|
|
|
|
|
const rawLine = " my_var = 123;";
|
2026-10-12 19:43:46 +00:00
|
|
|
// 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");
|
2026-10-11 04:11:11 +00:00
|
|
|
});
|
|
|
|
|
|
2026-10-12 19:43:46 +00:00
|
|
|
test('SyntaxRule: Akzeptiert "=" als Vergleich in Bedingungen', () => {
|
2026-10-11 04:11:11 +00:00
|
|
|
const rule = new SyntaxRule();
|
|
|
|
|
const ctx = new LinterContext();
|
2026-10-12 19:43:46 +00:00
|
|
|
ctx.activePhaseName = 'body';
|
2026-10-11 04:11:11 +00:00
|
|
|
|
|
|
|
|
const rawLine = " if my_var = 123 then";
|
2026-10-12 19:43:46 +00:00
|
|
|
rule.checkLine(rawLine.trim(), rawLine, 0, ctx, [rawLine]);
|
|
|
|
|
|
|
|
|
|
// Darf keinen Fehler werfen, da inConditionBlock automatisch auf true geht
|
2026-10-11 04:11:11 +00:00
|
|
|
assert.strictEqual(ctx.diagnostics.length, 0);
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-12 19:43:46 +00:00
|
|
|
test('SyntaxRule: Findet fehlendes Semikolon', () => {
|
2026-10-11 04:11:11 +00:00
|
|
|
const rule = new SyntaxRule();
|
|
|
|
|
const ctx = new LinterContext();
|
2026-10-12 19:43:46 +00:00
|
|
|
ctx.activePhaseName = 'body';
|
2026-10-11 04:11:11 +00:00
|
|
|
|
2026-10-12 19:43:46 +00:00
|
|
|
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");
|
|
|
|
|
});
|
2026-10-11 04:11:11 +00:00
|
|
|
|
2026-10-12 19:43:46 +00:00
|
|
|
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]);
|
|
|
|
|
|
2026-10-11 04:11:11 +00:00
|
|
|
assert.strictEqual(ctx.diagnostics.length, 1);
|
2026-10-12 19:43:46 +00:00
|
|
|
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");
|
2026-10-11 04:11:11 +00:00
|
|
|
});
|
|
|
|
|
});
|