Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1// @ts-ignore TS61332import { expect, test } from "vitest";3 4import { z } from "zod/v3";5import { util } from "../helpers/util.js";6 7test("basic defaults", () => {8 expect(z.string().default("default").parse(undefined)).toBe("default");9});10 11test("default with transform", () => {12 const stringWithDefault = z13 .string()14 .transform((val) => val.toUpperCase())15 .default("default");16 expect(stringWithDefault.parse(undefined)).toBe("DEFAULT");17 expect(stringWithDefault).toBeInstanceOf(z.ZodDefault);18 expect(stringWithDefault._def.innerType).toBeInstanceOf(z.ZodEffects);19 expect(stringWithDefault._def.innerType._def.schema).toBeInstanceOf(z.ZodSchema);20 21 type inp = z.input<typeof stringWithDefault>;22 util.assertEqual<inp, string | undefined>(true);23 type out = z.output<typeof stringWithDefault>;24 util.assertEqual<out, string>(true);25});26 27test("default on existing optional", () => {28 const stringWithDefault = z.string().optional().default("asdf");29 expect(stringWithDefault.parse(undefined)).toBe("asdf");30 expect(stringWithDefault).toBeInstanceOf(z.ZodDefault);31 expect(stringWithDefault._def.innerType).toBeInstanceOf(z.ZodOptional);32 expect(stringWithDefault._def.innerType._def.innerType).toBeInstanceOf(z.ZodString);33 34 type inp = z.input<typeof stringWithDefault>;35 util.assertEqual<inp, string | undefined>(true);36 type out = z.output<typeof stringWithDefault>;37 util.assertEqual<out, string>(true);38});39 40test("optional on default", () => {41 const stringWithDefault = z.string().default("asdf").optional();42 43 type inp = z.input<typeof stringWithDefault>;44 util.assertEqual<inp, string | undefined>(true);45 type out = z.output<typeof stringWithDefault>;46 util.assertEqual<out, string | undefined>(true);47});48 49test("complex chain example", () => {50 const complex = z51 .string()52 .default("asdf")53 .transform((val) => val.toUpperCase())54 .default("qwer")55 .removeDefault()56 .optional()57 .default("asdfasdf");58 59 expect(complex.parse(undefined)).toBe("ASDFASDF");60});61 62test("removeDefault", () => {63 const stringWithRemovedDefault = z.string().default("asdf").removeDefault();64 65 type out = z.output<typeof stringWithRemovedDefault>;66 util.assertEqual<out, string>(true);67});68 69test("nested", () => {70 const inner = z.string().default("asdf");71 const outer = z.object({ inner }).default({72 inner: undefined,73 });74 type input = z.input<typeof outer>;75 util.assertEqual<input, { inner?: string | undefined } | undefined>(true);76 type out = z.output<typeof outer>;77 util.assertEqual<out, { inner: string }>(true);78 expect(outer.parse(undefined)).toEqual({ inner: "asdf" });79 expect(outer.parse({})).toEqual({ inner: "asdf" });80 expect(outer.parse({ inner: undefined })).toEqual({ inner: "asdf" });81});82 83test("chained defaults", () => {84 const stringWithDefault = z.string().default("inner").default("outer");85 const result = stringWithDefault.parse(undefined);86 expect(result).toEqual("outer");87});88 89test("factory", () => {90 expect(z.ZodDefault.create(z.string(), { default: "asdf" }).parse(undefined)).toEqual("asdf");91});92 93test("native enum", () => {94 enum Fruits {95 apple = "apple",96 orange = "orange",97 }98 99 const schema = z.object({100 fruit: z.nativeEnum(Fruits).default(Fruits.apple),101 });102 103 expect(schema.parse({})).toEqual({ fruit: Fruits.apple });104});105 106test("enum", () => {107 const schema = z.object({108 fruit: z.enum(["apple", "orange"]).default("apple"),109 });110 111 expect(schema.parse({})).toEqual({ fruit: "apple" });112});113 