Files
SnowLuma/.pnpm-store/v11/files/6f/2e77ce17b69295141dd776b00d32093e523d59d79c1aecac9baa805912ce1e6d3774f49626294099a3ced44e02e8b715f24faaa759ee24cbc26462ba50b501
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

46 lines
1.4 KiB
Plaintext

import { describe, expect, it } from "vitest";
import * as z from "zod/v4";
describe("Recursive Tuples Regression #5089", () => {
it("creates recursive tuple without crash", () => {
expect(() => {
const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
}).not.toThrow();
});
it("parses recursive tuple data correctly", () => {
const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
// Base case
expect(y.parse("hello")).toBe("hello");
// Recursive cases
expect(() => y.parse(["a", "b"])).not.toThrow();
expect(() => y.parse(["a", ["b", "c"]])).not.toThrow();
});
it("matches #5089 expected behavior", () => {
// Exact code from the issue
expect(() => {
const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
y.parse(["a", ["b", "c"]]);
}).not.toThrow();
});
it("handles workaround pattern", () => {
// Alternative pattern from issue discussion
expect(() => {
const y = z.lazy((): any => z.string().or(z.lazy(() => z.tuple([y, y]))));
y.parse(["a", ["b", "c"]]);
}).not.toThrow();
});
it("recursive arrays still work (comparison)", () => {
const y = z.lazy((): any => z.array(y).or(z.string()));
expect(y.parse("hello")).toBe("hello");
expect(y.parse(["hello", "world"])).toEqual(["hello", "world"]);
expect(y.parse(["a", ["b", "c"]])).toEqual(["a", ["b", "c"]]);
});
});