import { describe, expect, it } from "vitest";
import { resultTypeForValidation, effectiveReturnType } from "./validation.js";
describe("applyValidationFlag", () => {
    const person = {
        type: "typeAliasVariable",
        aliasName: "Person",
    };
    const stringT = { type: "primitiveType", value: "string" };
    it("returns the type unchanged when validated is false/undefined", () => {
        expect(resultTypeForValidation(person, false)).toEqual(person);
        expect(resultTypeForValidation(person, undefined)).toEqual(person);
    });
    it("wraps a non-Result type in Result<T, string> when validated", () => {
        expect(resultTypeForValidation(person, true)).toEqual({
            type: "resultType",
            successType: person,
            failureType: stringT,
        });
    });
    it("does not rewrap a Result type", () => {
        const result = {
            type: "resultType",
            successType: person,
            failureType: stringT,
        };
        expect(resultTypeForValidation(result, true)).toEqual(result);
    });
    it("wraps an array type in Result<T[], string>", () => {
        const arr = { type: "arrayType", elementType: person };
        expect(resultTypeForValidation(arr, true)).toEqual({
            type: "resultType",
            successType: arr,
            failureType: stringT,
        });
    });
});
describe("effectiveReturnType", () => {
    const person = {
        type: "typeAliasVariable",
        aliasName: "Person",
    };
    const stringT = { type: "primitiveType", value: "string" };
    function fn(returnType, validated) {
        return {
            type: "function",
            functionName: "f",
            parameters: [],
            body: [],
            returnType: returnType,
            returnTypeValidated: validated,
        };
    }
    it("returns undefined / null unchanged", () => {
        expect(effectiveReturnType(fn(undefined))).toBeUndefined();
        expect(effectiveReturnType(fn(null))).toBeNull();
    });
    it("returns the type unchanged when not validated", () => {
        expect(effectiveReturnType(fn(person))).toEqual(person);
    });
    it("wraps in Result when returnTypeValidated", () => {
        expect(effectiveReturnType(fn(person, true))).toEqual({
            type: "resultType",
            successType: person,
            failureType: stringT,
        });
    });
});
