import { test } from "node:test"; import assert from "node:assert/strict"; import { explainDiagnostic } from "../src/training/diagnostics.js"; test("explanation includes the actual location and a relevant repair", () => { assert.match(explainDiagnostic("main.c:4:12: error: expected ';' after return statement"), /line 4.*semicolon is missing.*marks the end/); assert.match(explainDiagnostic("main.c:3:8: error: use of undeclared identifier 'duck'"), /Declare this variable/); assert.match(explainDiagnostic("wasm-ld: error: undefined symbol: main"), /entry point/); assert.match(explainDiagnostic("main.c:2:1: error: unusual diagnostic"), /detailed diagnostic is available/); }); test("misspelled scanf is explained without reading compiler boilerplate", () => { const raw = "main.c:17:5: error: call to undeclared function 'scnaf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]"; const speech = explainDiagnostic(raw, '#include '); assert.match(speech, /does not recognize 'scnaf'/); assert.match(speech, /Did you mean 'scanf'/); assert.doesNotMatch(speech, /ISO C99|Wimplicit|Include stdio/); assert.match(explainDiagnostic("main.c:3:1: error: call to undeclared function 'printf'"), /Include stdio/); }); test("assessment help explains compiler errors in French", () => { assert.match(explainDiagnostic("main.c:4:12: error: expected ';' after return statement", "", "fr"), /^La compilation a échoué\. À la ligne 4\. Il manque un point-virgule/); assert.match(explainDiagnostic("main.c:3:1: error: call to undeclared function 'printf'", "", "fr"), /#include /); });