slige/compiler/test_diagnostics.ts

65 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-01-23 09:28:48 +00:00
import { Ctx } from "./ctx.ts";
import { prettyPrintReport } from "./diagnostics.ts";
const ctx = new Ctx();
const text = `
make an error here
`;
2025-01-23 12:58:07 +00:00
const biggerText = `
dont make error here
not here but start error here
and here
also here but not here
or here
`
2025-01-23 09:28:48 +00:00
const file = ctx.addFile(
"root",
"path/file.ts",
"path/file.ts",
undefined,
text,
);
2025-01-23 12:58:07 +00:00
const biggerFile = ctx.addFile(
"root",
"path/file.ts",
"path/file.ts",
undefined,
biggerText,
);
2025-01-23 09:28:48 +00:00
prettyPrintReport(ctx, {
file,
msg: "an error",
2025-01-23 12:58:07 +00:00
severity: "fatal",
2025-01-23 09:28:48 +00:00
origin: "compiler",
span: {
2025-01-23 12:58:07 +00:00
begin: { idx: 5, line: 2, col: 5 },
2025-01-23 09:28:48 +00:00
end: { idx: 13, line: 2, col: 13 },
},
});
2025-01-23 12:58:07 +00:00
prettyPrintReport(ctx, {
file: biggerFile,
msg: "an error",
severity: "error",
origin: "compiler",
span: {
begin: { idx: 6, line: 3, col: 14 },
end: { idx: 13, line: 5, col: 13 },
},
});
prettyPrintReport(ctx, {
file,
msg: "an error",
severity: "warning",
origin: "compiler",
pos: {
idx: 6, line: 2, col: 8
},
});