@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 122 lines 3.14 KB
Raw
1 import { describe, expect, test } from "@alchemy.run/test";
2 import * as S from "effect/Schema";
3 import {
4 getSetValueAST,
5 isBooleanSchema,
6 isListSchema,
7 isMapSchema,
8 isNullishSchema,
9 isNullSchema,
10 isNumberSchema,
11 isRecordLikeSchema,
12 isSetSchema,
13 isStringSchema,
14 isUndefinedSchema,
15 } from "@/Schema";
16
17 describe("isStringSchema", { tags: ["unit", "local"] }, () => {
18 test("string", () => {
19 expect(isStringSchema(S.String)).toBe(true);
20 });
21 test("not string", () => {
22 expect(isStringSchema(S.Number)).toBe(false);
23 });
24 });
25
26 describe("isNumberSchema", { tags: ["unit", "local"] }, () => {
27 test("number", () => {
28 expect(isNumberSchema(S.Number)).toBe(true);
29 });
30 test("not number", () => {
31 expect(isNumberSchema(S.String)).toBe(false);
32 });
33 });
34
35 describe("isMapSchema", { tags: ["unit", "local"] }, () => {
36 test("map", () => {
37 expect(isMapSchema(S.ReadonlyMap(S.String, S.String))).toBe(true);
38 });
39 test("not map", () => {
40 expect(isMapSchema(S.Record(S.String, S.String))).toBe(false);
41 });
42 });
43
44 describe("isRecordLikeSchema", { tags: ["unit", "local"] }, () => {
45 for (const [key, value] of Object.entries({
46 map: S.ReadonlyMap(S.String, S.String),
47 struct: S.Struct({
48 key: S.String,
49 value: S.String,
50 }),
51 class: class Self extends S.Class<Self>("Self")({
52 key: S.String,
53 value: S.String,
54 }) {},
55 })) {
56 test(key, () => {
57 expect(isRecordLikeSchema(value)).toBe(true);
58 });
59 }
60 });
61
62 describe("isListSchema", { tags: ["unit", "local"] }, () => {
63 test("list", () => {
64 expect(isListSchema(S.Array(S.String))).toBe(true);
65 });
66 test("Map type is not list", () => {
67 expect(isListSchema(S.ReadonlyMap(S.String, S.String))).toBe(false);
68 });
69 });
70
71 describe("isSetSchema", { tags: ["unit", "local"] }, () => {
72 test("set", () => {
73 expect(isSetSchema(S.ReadonlySet(S.String))).toBe(true);
74 });
75 test("getSetValueAST", () => {
76 const ast = getSetValueAST(S.ReadonlySet(S.String));
77 expect(ast).toBeDefined();
78 expect(isStringSchema(S.make(ast!))).toBe(true);
79 });
80 });
81
82 describe("isNullSchema", { tags: ["unit", "local"] }, () => {
83 test("null", () => {
84 expect(isNullSchema(S.Null)).toBe(true);
85 });
86 test("undefined", () => {
87 expect(isNullSchema(S.Undefined)).toBe(false);
88 });
89 test("not null", () => {
90 expect(isNullSchema(S.String)).toBe(false);
91 });
92 });
93
94 describe("isUndefinedSchema", { tags: ["unit", "local"] }, () => {
95 test("undefined", () => {
96 expect(isUndefinedSchema(S.Undefined)).toBe(true);
97 });
98 test("not undefined", () => {
99 expect(isUndefinedSchema(S.String)).toBe(false);
100 });
101 });
102
103 describe("isNullishSchema", { tags: ["unit", "local"] }, () => {
104 test("null", () => {
105 expect(isNullishSchema(S.Null)).toBe(true);
106 });
107 test("undefined", () => {
108 expect(isNullishSchema(S.Undefined)).toBe(true);
109 });
110 test("not nullish", () => {
111 expect(isNullishSchema(S.String)).toBe(false);
112 });
113 });
114
115 describe("isBooleanSchema", { tags: ["unit", "local"] }, () => {
116 test("boolean", () => {
117 expect(isBooleanSchema(S.Boolean)).toBe(true);
118 });
119 test("not boolean", () => {
120 expect(isBooleanSchema(S.String)).toBe(false);
121 });
122 });