import { refkey, StatementList } from "@alloy-js/core";
import { expect, it } from "vitest";
import { TestFile } from "../../test/utils.js";
import { CatchClause, FinallyClause, TryStatement } from "./TryStatement.jsx";
import { VarDeclaration } from "./VarDeclaration.jsx";
it("works with try-catch", () => {
expect(
// try something
// handle error
,
).toRenderTo(`
try {
// try something
} catch (error) {
// handle error
}
`);
});
it("works with try-catch-finally", () => {
expect(
// try something
// handle error
// cleanup
,
).toRenderTo(`
try {
// try something
} catch (error) {
// handle error
} finally {
// cleanup
}
`);
});
it("works with try-finally", () => {
expect(
// try something
// cleanup
,
).toRenderTo(`
try {
// try something
} finally {
// cleanup
}
`);
});
it("works with catch without parameter", () => {
expect(
// try something
// handle error without parameter
,
).toRenderTo(`
try {
// try something
} catch {
// handle error without parameter
}
`);
});
it("works with typed catch parameter", () => {
expect(
// try something
// handle typed error
,
).toRenderTo(`
try {
// try something
} catch (error: Error) {
// handle typed error
}
`);
});
it("creates symbols for catch parameters", () => {
const rk = refkey();
expect(
// try something
{rk}
{rk}.message
,
).toRenderTo(`
try {
// try something
} catch (error: Error) {
error;
const message: string = error.message;
}
`);
});