import { describe, test, expectTypeOf } from "vitest"; import type { Value, AllValues, PartialValues, RequiredProps } from "./types"; import type { Intrinsic } from "./intrinsic"; describe("Value", () => { test("accepts concrete value", () => { expectTypeOf().toMatchTypeOf>(); expectTypeOf().toMatchTypeOf>(); expectTypeOf().toMatchTypeOf>(); }); test("accepts Intrinsic", () => { expectTypeOf().toMatchTypeOf>(); expectTypeOf().toMatchTypeOf>(); expectTypeOf().toMatchTypeOf>(); }); }); describe("AllValues", () => { test("converts all properties to Value types", () => { interface Props { name: string; count: number; enabled: boolean; } type ValueProps = AllValues; expectTypeOf().toEqualTypeOf<{ name: Value; count: Value; enabled: Value; }>(); }); test("preserves optional properties", () => { interface Props { required: string; optional?: number; } type ValueProps = AllValues; expectTypeOf().toEqualTypeOf<{ required: Value; optional?: Value; }>(); }); test("handles complex types", () => { interface Props { arr: string[]; obj: { key: string }; union: string | number; } type ValueProps = AllValues; expectTypeOf().toEqualTypeOf<{ arr: Value; obj: Value<{ key: string }>; union: Value; }>(); }); test("handles empty interface", () => { interface Props {} type ValueProps = AllValues; expectTypeOf().toEqualTypeOf<{}>(); }); test("handles nested objects", () => { interface Props { config: { host: string; port: number; }; } type ValueProps = AllValues; expectTypeOf().toEqualTypeOf<{ config: Value<{ host: string; port: number; }>; }>(); }); }); describe("PartialValues", () => { test("converts specified properties to Value types", () => { interface Props { name: string; count: number; enabled: boolean; } type ValueProps = PartialValues; expectTypeOf().toEqualTypeOf<{ name: Value; count: Value; enabled: boolean; }>(); }); test("converts single property to Value type", () => { interface Props { name: string; count: number; } type ValueProps = PartialValues; expectTypeOf().toEqualTypeOf<{ name: Value; count: number; }>(); }); test("preserves optional properties", () => { interface Props { name: string; count?: number; } type ValueProps = PartialValues; expectTypeOf().toEqualTypeOf<{ name: Value; count?: number; }>(); }); test("handles complex types", () => { interface Props { arr: string[]; obj: { key: string }; primitive: string; } type ValueProps = PartialValues; expectTypeOf().toEqualTypeOf<{ arr: Value; obj: Value<{ key: string }>; primitive: string; }>(); }); test("works with all properties", () => { interface Props { name: string; count: number; } type ValueProps = PartialValues; expectTypeOf().toEqualTypeOf<{ name: Value; count: Value; }>(); }); test("works with no conversion (unrealistic but valid)", () => { interface Props { name: string; count: number; } type ValueProps = PartialValues; expectTypeOf().toEqualTypeOf<{ name: string; count: number; }>(); }); }); describe("RequiredProps", () => { test("makes specified properties required", () => { interface Props { name?: string; count?: number; enabled?: boolean; } type RequiredNameProps = RequiredProps; expectTypeOf().toEqualTypeOf<{ name: string; count?: number; enabled?: boolean; }>(); }); test("makes multiple properties required", () => { interface Props { name?: string; count?: number; enabled?: boolean; } type RequiredMultiProps = RequiredProps; expectTypeOf().toEqualTypeOf<{ name: string; count: number; enabled?: boolean; }>(); }); test("handles already required properties", () => { interface Props { name: string; count?: number; } type RequiredNameProps = RequiredProps; expectTypeOf().toEqualTypeOf<{ name: string; count?: number; }>(); }); test("makes all properties required", () => { interface Props { name?: string; count?: number; } type AllRequiredProps = RequiredProps; expectTypeOf().toEqualTypeOf<{ name: string; count: number; }>(); }); test("handles complex types", () => { interface Props { arr?: string[]; obj?: { key: string }; primitive?: string; } type RequiredArrProps = RequiredProps; expectTypeOf().toEqualTypeOf<{ arr: string[]; obj?: { key: string }; primitive?: string; }>(); }); test("handles mixed required and optional", () => { interface Props { required: string; optional1?: number; optional2?: boolean; } type PartiallyRequired = RequiredProps; expectTypeOf().toEqualTypeOf<{ required: string; optional1: number; optional2?: boolean; }>(); }); }); describe("Combined usage", () => { test("AllValues and RequiredProps can be combined", () => { interface Props { name?: string; count?: number; } type Combined = AllValues>; expectTypeOf().toEqualTypeOf<{ name: Value; count?: Value; }>(); }); test("PartialValues and RequiredProps can be combined", () => { interface Props { name?: string; count?: number; enabled?: boolean; } type Combined = PartialValues, "count">; expectTypeOf().toEqualTypeOf<{ name: string; count?: Value; enabled?: boolean; }>(); }); });