/**
 * Shared helper for validator test modules.
 *
 * Provides `createTestProgram` which constructs a TsonicProgram from
 * an inline source string, suitable for feeding into `validateProgram`.
 */
import * as ts from "typescript";
import { DotnetMetadataRegistry } from "../dotnet-metadata.js";
import { BindingRegistry } from "../program/bindings.js";
import { createClrBindingsResolver } from "../resolver/clr-bindings-resolver.js";
import { createBinding } from "../ir/binding/index.js";
export const createTestProgram = (source, fileName = "test.ts") => {
    const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
    const compilerOptions = {
        target: ts.ScriptTarget.ES2022,
        module: ts.ModuleKind.NodeNext,
        strict: true,
        noEmit: true,
    };
    const host = ts.createCompilerHost(compilerOptions);
    const originalGetSourceFile = host.getSourceFile;
    host.getSourceFile = (name, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
        if (name === fileName) {
            return sourceFile;
        }
        return originalGetSourceFile.call(host, name, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
    };
    const program = ts.createProgram([fileName], compilerOptions, host);
    const checker = program.getTypeChecker();
    return {
        program,
        checker,
        options: {
            projectRoot: "/test",
            sourceRoot: "/test",
            rootNamespace: "Test",
        },
        sourceFiles: [sourceFile],
        declarationSourceFiles: [],
        metadata: new DotnetMetadataRegistry(),
        bindings: new BindingRegistry(),
        clrResolver: createClrBindingsResolver("/test"),
        binding: createBinding(checker),
    };
};
//# sourceMappingURL=helpers.js.map