Team Ai
Datasetpublic

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.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
object.test.ts435 linesDownload Raw Back to tests
1// @ts-ignore TS61332import { expect, test } from "vitest";3 4import * as z from "zod/v3";5import { util } from "../helpers/util.js";6 7const Test = z.object({8  f1: z.number(),9  f2: z.string().optional(),10  f3: z.string().nullable(),11  f4: z.array(z.object({ t: z.union([z.string(), z.boolean()]) })),12});13 14test("object type inference", () => {15  type TestType = {16    f1: number;17    f2?: string | undefined;18    f3: string | null;19    f4: { t: string | boolean }[];20  };21 22  util.assertEqual<z.TypeOf<typeof Test>, TestType>(true);23});24 25test("unknown throw", () => {26  const asdf: unknown = 35;27  expect(() => Test.parse(asdf)).toThrow();28});29 30test("shape() should return schema of particular key", () => {31  const f1Schema = Test.shape.f1;32  const f2Schema = Test.shape.f2;33  const f3Schema = Test.shape.f3;34  const f4Schema = Test.shape.f4;35 36  expect(f1Schema).toBeInstanceOf(z.ZodNumber);37  expect(f2Schema).toBeInstanceOf(z.ZodOptional);38  expect(f3Schema).toBeInstanceOf(z.ZodNullable);39  expect(f4Schema).toBeInstanceOf(z.ZodArray);40});41 42test("correct parsing", () => {43  Test.parse({44    f1: 12,45    f2: "string",46    f3: "string",47    f4: [48      {49        t: "string",50      },51    ],52  });53 54  Test.parse({55    f1: 12,56    f3: null,57    f4: [58      {59        t: false,60      },61    ],62  });63});64 65test("incorrect #1", () => {66  expect(() => Test.parse({} as any)).toThrow();67});68 69test("nonstrict by default", () => {70  z.object({ points: z.number() }).parse({71    points: 2314,72    unknown: "asdf",73  });74});75 76const data = {77  points: 2314,78  unknown: "asdf",79};80 81test("strip by default", () => {82  const val = z.object({ points: z.number() }).parse(data);83  expect(val).toEqual({ points: 2314 });84});85 86test("unknownkeys override", () => {87  const val = z.object({ points: z.number() }).strict().passthrough().strip().nonstrict().parse(data);88 89  expect(val).toEqual(data);90});91 92test("passthrough unknown", () => {93  const val = z.object({ points: z.number() }).passthrough().parse(data);94 95  expect(val).toEqual(data);96});97 98test("strip unknown", () => {99  const val = z.object({ points: z.number() }).strip().parse(data);100 101  expect(val).toEqual({ points: 2314 });102});103 104test("strict", () => {105  const val = z.object({ points: z.number() }).strict().safeParse(data);106 107  expect(val.success).toEqual(false);108});109 110test("catchall inference", () => {111  const o1 = z112    .object({113      first: z.string(),114    })115    .catchall(z.number());116 117  const d1 = o1.parse({ first: "asdf", num: 1243 });118  util.assertEqual<number, (typeof d1)["asdf"]>(true);119  util.assertEqual<string, (typeof d1)["first"]>(true);120});121 122test("catchall overrides strict", () => {123  const o1 = z.object({ first: z.string().optional() }).strict().catchall(z.number());124 125  // should run fine126  // setting a catchall overrides the unknownKeys behavior127  o1.parse({128    asdf: 1234,129  });130 131  // should only run catchall validation132  // against unknown keys133  o1.parse({134    first: "asdf",135    asdf: 1234,136  });137});138 139test("catchall overrides strict", () => {140  const o1 = z141    .object({142      first: z.string(),143    })144    .strict()145    .catchall(z.number());146 147  // should run fine148  // setting a catchall overrides the unknownKeys behavior149  o1.parse({150    first: "asdf",151    asdf: 1234,152  });153});154 155test("test that optional keys are unset", () => {156  const SNamedEntity = z.object({157    id: z.string(),158    set: z.string().optional(),159    unset: z.string().optional(),160  });161  const result = SNamedEntity.parse({162    id: "asdf",163    set: undefined,164  });165  // eslint-disable-next-line ban/ban166  expect(Object.keys(result)).toEqual(["id", "set"]);167});168 169test("test catchall parsing", async () => {170  const result = z.object({ name: z.string() }).catchall(z.number()).parse({ name: "Foo", validExtraKey: 61 });171 172  expect(result).toEqual({ name: "Foo", validExtraKey: 61 });173 174  const result2 = z175    .object({ name: z.string() })176    .catchall(z.number())177    .safeParse({ name: "Foo", validExtraKey: 61, invalid: "asdf" });178 179  expect(result2.success).toEqual(false);180});181 182test("test nonexistent keys", async () => {183  const Schema = z.union([z.object({ a: z.string() }), z.object({ b: z.number() })]);184  const obj = { a: "A" };185  const result = await Schema.spa(obj); // Works with 1.11.10, breaks with 2.0.0-beta.21186  expect(result.success).toBe(true);187});188 189test("test async union", async () => {190  const Schema2 = z.union([191    z.object({192      ty: z.string(),193    }),194    z.object({195      ty: z.number(),196    }),197  ]);198 199  const obj = { ty: "A" };200  const result = await Schema2.spa(obj); // Works with 1.11.10, breaks with 2.0.0-beta.21201  expect(result.success).toEqual(true);202});203 204test("test inferred merged type", async () => {205  const asdf = z.object({ a: z.string() }).merge(z.object({ a: z.number() }));206  type asdf = z.infer<typeof asdf>;207  util.assertEqual<asdf, { a: number }>(true);208});209 210test("inferred merged object type with optional properties", async () => {211  const Merged = z212    .object({ a: z.string(), b: z.string().optional() })213    .merge(z.object({ a: z.string().optional(), b: z.string() }));214  type Merged = z.infer<typeof Merged>;215  util.assertEqual<Merged, { a?: string | undefined; b: string }>(true);216  // todo217  // util.assertEqual<Merged, { a?: string | undefined; b: string }>(true);218});219 220test("inferred unioned object type with optional properties", async () => {221  const Unioned = z.union([222    z.object({ a: z.string(), b: z.string().optional() }),223    z.object({ a: z.string().optional(), b: z.string() }),224  ]);225  type Unioned = z.infer<typeof Unioned>;226  util.assertEqual<Unioned, { a: string; b?: string | undefined } | { a?: string | undefined; b: string }>(true);227});228 229test("inferred enum type", async () => {230  const Enum = z.object({ a: z.string(), b: z.string().optional() }).keyof();231 232  expect(Enum.Values).toEqual({233    a: "a",234    b: "b",235  });236  expect(Enum.enum).toEqual({237    a: "a",238    b: "b",239  });240  expect(Enum._def.values).toEqual(["a", "b"]);241  type Enum = z.infer<typeof Enum>;242  util.assertEqual<Enum, "a" | "b">(true);243});244 245test("inferred partial object type with optional properties", async () => {246  const Partial = z.object({ a: z.string(), b: z.string().optional() }).partial();247  type Partial = z.infer<typeof Partial>;248  util.assertEqual<Partial, { a?: string | undefined; b?: string | undefined }>(true);249});250 251test("inferred picked object type with optional properties", async () => {252  const Picked = z.object({ a: z.string(), b: z.string().optional() }).pick({ b: true });253  type Picked = z.infer<typeof Picked>;254  util.assertEqual<Picked, { b?: string | undefined }>(true);255});256 257test("inferred type for unknown/any keys", () => {258  const myType = z.object({259    anyOptional: z.any().optional(),260    anyRequired: z.any(),261    unknownOptional: z.unknown().optional(),262    unknownRequired: z.unknown(),263  });264  type myType = z.infer<typeof myType>;265  util.assertEqual<266    myType,267    {268      anyOptional?: any;269      anyRequired?: any;270      unknownOptional?: unknown;271      unknownRequired?: unknown;272    }273  >(true);274});275 276test("setKey", () => {277  const base = z.object({ name: z.string() });278  const withNewKey = base.setKey("age", z.number());279 280  type withNewKey = z.infer<typeof withNewKey>;281  util.assertEqual<withNewKey, { name: string; age: number }>(true);282  withNewKey.parse({ name: "asdf", age: 1234 });283});284 285test("strictcreate", async () => {286  const strictObj = z.strictObject({287    name: z.string(),288  });289 290  const syncResult = strictObj.safeParse({ name: "asdf", unexpected: 13 });291  expect(syncResult.success).toEqual(false);292 293  const asyncResult = await strictObj.spa({ name: "asdf", unexpected: 13 });294  expect(asyncResult.success).toEqual(false);295});296 297test("object with refine", async () => {298  const schema = z299    .object({300      a: z.string().default("foo"),301      b: z.number(),302    })303    .refine(() => true);304  expect(schema.parse({ b: 5 })).toEqual({ b: 5, a: "foo" });305  const result = await schema.parseAsync({ b: 5 });306  expect(result).toEqual({ b: 5, a: "foo" });307});308 309test("intersection of object with date", async () => {310  const schema = z.object({311    a: z.date(),312  });313  expect(schema.and(schema).parse({ a: new Date(1637353595983) })).toEqual({314    a: new Date(1637353595983),315  });316  const result = await schema.parseAsync({ a: new Date(1637353595983) });317  expect(result).toEqual({ a: new Date(1637353595983) });318});319 320test("intersection of object with refine with date", async () => {321  const schema = z322    .object({323      a: z.date(),324    })325    .refine(() => true);326  expect(schema.and(schema).parse({ a: new Date(1637353595983) })).toEqual({327    a: new Date(1637353595983),328  });329  const result = await schema.parseAsync({ a: new Date(1637353595983) });330  expect(result).toEqual({ a: new Date(1637353595983) });331});332 333test("constructor key", () => {334  const person = z335    .object({336      name: z.string(),337    })338    .strict();339 340  expect(() =>341    person.parse({342      name: "bob dylan",343      constructor: 61,344    })345  ).toThrow();346});347 348test("constructor key", () => {349  const Example = z.object({350    prop: z.string(),351    opt: z.number().optional(),352    arr: z.string().array(),353  });354 355  type Example = z.infer<typeof Example>;356  util.assertEqual<keyof Example, "prop" | "opt" | "arr">(true);357});358 359test("unknownkeys merging", () => {360  // This one is "strict"361  const schemaA = z362    .object({363      a: z.string(),364    })365    .strict();366 367  // This one is "strip"368  const schemaB = z369    .object({370      b: z.string(),371    })372    .catchall(z.string());373 374  const mergedSchema = schemaA.merge(schemaB);375  type mergedSchema = typeof mergedSchema;376  util.assertEqual<mergedSchema["_def"]["unknownKeys"], "strip">(true);377  expect(mergedSchema._def.unknownKeys).toEqual("strip");378 379  util.assertEqual<mergedSchema["_def"]["catchall"], z.ZodString>(true);380  expect(mergedSchema._def.catchall instanceof z.ZodString).toEqual(true);381});382 383const personToExtend = z.object({384  firstName: z.string(),385  lastName: z.string(),386});387 388test("extend() should return schema with new key", () => {389  const PersonWithNickname = personToExtend.extend({ nickName: z.string() });390  type PersonWithNickname = z.infer<typeof PersonWithNickname>;391 392  const expected = { firstName: "f", nickName: "n", lastName: "l" };393  const actual = PersonWithNickname.parse(expected);394 395  expect(actual).toEqual(expected);396  util.assertEqual<keyof PersonWithNickname, "firstName" | "lastName" | "nickName">(true);397  util.assertEqual<PersonWithNickname, { firstName: string; lastName: string; nickName: string }>(true);398});399 400test("extend() should have power to override existing key", () => {401  const PersonWithNumberAsLastName = personToExtend.extend({402    lastName: z.number(),403  });404  type PersonWithNumberAsLastName = z.infer<typeof PersonWithNumberAsLastName>;405 406  const expected = { firstName: "f", lastName: 42 };407  const actual = PersonWithNumberAsLastName.parse(expected);408 409  expect(actual).toEqual(expected);410  util.assertEqual<PersonWithNumberAsLastName, { firstName: string; lastName: number }>(true);411});412 413test("passthrough index signature", () => {414  const a = z.object({ a: z.string() });415  type a = z.infer<typeof a>;416  util.assertEqual<{ a: string }, a>(true);417  const b = a.passthrough();418  type b = z.infer<typeof b>;419  util.assertEqual<{ a: string } & { [k: string]: unknown }, b>(true);420});421 422test("xor", () => {423  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };424  type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;425 426  type A = { name: string; a: number };427  type B = { name: string; b: number };428  type C = XOR<A, B>;429  type Outer = { data: C };430 431  const _Outer: z.ZodType<Outer> = z.object({432    data: z.union([z.object({ name: z.string(), a: z.number() }), z.object({ name: z.string(), b: z.number() })]),433  });434});435 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai