schematox 1.2.2-alpha → 1.2.3-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,741 +0,0 @@
1
- import * as x from '../../'
2
- import * as fixture from '../fixtures'
3
-
4
- import type { StructSharedKeys } from '../type'
5
-
6
- describe('Type inference and parse by schema/construct/struct (foldA)', () => {
7
- it('required', () => {
8
- const schema = { type: 'boolean' } as const satisfies x.Schema
9
- const struct = x.boolean()
10
-
11
- type ExpectedSubj = boolean
12
-
13
- const subjects: Array<ExpectedSubj> = [true, false]
14
-
15
- foldA: {
16
- const construct = x.makeStruct(schema)
17
-
18
- /* ensure that schema/construct/struct/~standard subject types are identical */
19
-
20
- type ConstructSchemaSubj = x.Infer<typeof construct.__schema>
21
-
22
- x.tCh<ConstructSchemaSubj, ExpectedSubj>()
23
- x.tCh<ExpectedSubj, ConstructSchemaSubj>()
24
-
25
- type SchemaSubj = x.Infer<typeof schema>
26
-
27
- x.tCh<SchemaSubj, ExpectedSubj>()
28
- x.tCh<ExpectedSubj, SchemaSubj>()
29
-
30
- type StructSubj = x.Infer<typeof struct.__schema>
31
-
32
- x.tCh<StructSubj, ExpectedSubj>()
33
- x.tCh<ExpectedSubj, StructSubj>()
34
-
35
- type StandardSubj = NonNullable<
36
- (typeof struct)['~standard']['types']
37
- >['output']
38
-
39
- x.tCh<StandardSubj, ExpectedSubj>()
40
- x.tCh<ExpectedSubj, StandardSubj>()
41
-
42
- /* parsed either type check */
43
-
44
- type ExpectedParsed = x.ParseResult<ExpectedSubj>
45
-
46
- const parsed = x.parse(schema, undefined)
47
-
48
- type SchemaParsed = typeof parsed
49
-
50
- x.tCh<SchemaParsed, ExpectedParsed>()
51
- x.tCh<ExpectedParsed, SchemaParsed>()
52
-
53
- type ConstructParsed = ReturnType<typeof construct.parse>
54
-
55
- x.tCh<ConstructParsed, ExpectedParsed>()
56
- x.tCh<ExpectedParsed, ConstructParsed>()
57
-
58
- type StructParsed = ReturnType<typeof struct.parse>
59
-
60
- x.tCh<StructParsed, ExpectedParsed>()
61
- x.tCh<ExpectedParsed, StructParsed>()
62
-
63
- type StandardParsed = Extract<
64
- ReturnType<(typeof struct)['~standard']['validate']>,
65
- { value: unknown }
66
- >['value']
67
-
68
- x.tCh<StandardParsed, ExpectedSubj>()
69
- x.tCh<ExpectedSubj, StandardParsed>()
70
-
71
- /* runtime schema check */
72
-
73
- expect(struct.__schema).toStrictEqual(schema)
74
- expect(construct.__schema).toStrictEqual(schema)
75
- expect(construct.__schema === schema).toBe(false)
76
-
77
- /* parse result check */
78
-
79
- for (const subj of subjects) {
80
- const schemaParsed = x.parse(schema, subj)
81
-
82
- expect(schemaParsed.error).toBe(undefined)
83
- expect(schemaParsed.data).toStrictEqual(subj)
84
-
85
- const constructParsed = construct.parse(subj)
86
-
87
- expect(constructParsed.error).toBe(undefined)
88
- expect(constructParsed.data).toStrictEqual(subj)
89
-
90
- const structParsed = struct.parse(subj)
91
-
92
- expect(structParsed.error).toBe(undefined)
93
- expect(structParsed.data).toStrictEqual(subj)
94
-
95
- const standardParsed = struct['~standard'].validate(subj)
96
-
97
- if (standardParsed instanceof Promise) {
98
- throw Error('Not expected')
99
- }
100
-
101
- if (standardParsed.issues !== undefined) {
102
- throw Error('not expected')
103
- }
104
-
105
- expect(standardParsed.value).toStrictEqual(subj)
106
- }
107
- }
108
- })
109
-
110
- it('optional', () => {
111
- const schema = {
112
- type: 'boolean',
113
- optional: true,
114
- } as const satisfies x.Schema
115
- const struct = x.boolean().optional()
116
-
117
- type ExpectedSubj = boolean | undefined
118
-
119
- const subjects: Array<ExpectedSubj> = [true, false, undefined]
120
-
121
- foldA: {
122
- const construct = x.makeStruct(schema)
123
-
124
- /* ensure that schema/construct/struct/~standard subject types are identical */
125
-
126
- type ConstructSchemaSubj = x.Infer<typeof construct.__schema>
127
-
128
- x.tCh<ConstructSchemaSubj, ExpectedSubj>()
129
- x.tCh<ExpectedSubj, ConstructSchemaSubj>()
130
-
131
- type SchemaSubj = x.Infer<typeof schema>
132
-
133
- x.tCh<SchemaSubj, ExpectedSubj>()
134
- x.tCh<ExpectedSubj, SchemaSubj>()
135
-
136
- type StructSubj = x.Infer<typeof struct.__schema>
137
-
138
- x.tCh<StructSubj, ExpectedSubj>()
139
- x.tCh<ExpectedSubj, StructSubj>()
140
-
141
- type StandardSubj = NonNullable<
142
- (typeof struct)['~standard']['types']
143
- >['output']
144
-
145
- x.tCh<StandardSubj, ExpectedSubj>()
146
- x.tCh<ExpectedSubj, StandardSubj>()
147
-
148
- /* parsed either type check */
149
-
150
- type ExpectedParsed = x.ParseResult<ExpectedSubj>
151
-
152
- const parsed = x.parse(schema, undefined)
153
-
154
- type SchemaParsed = typeof parsed
155
-
156
- x.tCh<SchemaParsed, ExpectedParsed>()
157
- x.tCh<ExpectedParsed, SchemaParsed>()
158
-
159
- type ConstructParsed = ReturnType<typeof construct.parse>
160
-
161
- x.tCh<ConstructParsed, ExpectedParsed>()
162
- x.tCh<ExpectedParsed, ConstructParsed>()
163
-
164
- type StructParsed = ReturnType<typeof struct.parse>
165
-
166
- x.tCh<StructParsed, ExpectedParsed>()
167
- x.tCh<ExpectedParsed, StructParsed>()
168
-
169
- type StandardParsed = Extract<
170
- ReturnType<(typeof struct)['~standard']['validate']>,
171
- { value: unknown }
172
- >['value']
173
-
174
- x.tCh<StandardParsed, ExpectedSubj>()
175
- x.tCh<ExpectedSubj, StandardParsed>()
176
-
177
- /* runtime schema check */
178
-
179
- expect(struct.__schema).toStrictEqual(schema)
180
- expect(construct.__schema).toStrictEqual(schema)
181
- expect(construct.__schema === schema).toBe(false)
182
-
183
- /* parse result check */
184
-
185
- for (const subj of subjects) {
186
- const schemaParsed = x.parse(schema, subj)
187
-
188
- expect(schemaParsed.error).toBe(undefined)
189
- expect(schemaParsed.data).toStrictEqual(subj)
190
-
191
- const constructParsed = construct.parse(subj)
192
-
193
- expect(constructParsed.error).toBe(undefined)
194
- expect(constructParsed.data).toStrictEqual(subj)
195
-
196
- const structParsed = struct.parse(subj)
197
-
198
- expect(structParsed.error).toBe(undefined)
199
- expect(structParsed.data).toStrictEqual(subj)
200
-
201
- const standardParsed = struct['~standard'].validate(subj)
202
-
203
- if (standardParsed instanceof Promise) {
204
- throw Error('Not expected')
205
- }
206
-
207
- if (standardParsed.issues !== undefined) {
208
- throw Error('not expected')
209
- }
210
-
211
- expect(standardParsed.value).toStrictEqual(subj)
212
- }
213
- }
214
- })
215
-
216
- it('nullable', () => {
217
- const schema = {
218
- type: 'boolean',
219
- nullable: true,
220
- } as const satisfies x.Schema
221
- const struct = x.boolean().nullable()
222
-
223
- type ExpectedSubj = boolean | null
224
-
225
- const subjects: Array<ExpectedSubj> = [true, false, null]
226
-
227
- foldA: {
228
- const construct = x.makeStruct(schema)
229
-
230
- /* ensure that schema/construct/struct/~standard subject types are identical */
231
-
232
- type ConstructSchemaSubj = x.Infer<typeof construct.__schema>
233
-
234
- x.tCh<ConstructSchemaSubj, ExpectedSubj>()
235
- x.tCh<ExpectedSubj, ConstructSchemaSubj>()
236
-
237
- type SchemaSubj = x.Infer<typeof schema>
238
-
239
- x.tCh<SchemaSubj, ExpectedSubj>()
240
- x.tCh<ExpectedSubj, SchemaSubj>()
241
-
242
- type StructSubj = x.Infer<typeof struct.__schema>
243
-
244
- x.tCh<StructSubj, ExpectedSubj>()
245
- x.tCh<ExpectedSubj, StructSubj>()
246
-
247
- type StandardSubj = NonNullable<
248
- (typeof struct)['~standard']['types']
249
- >['output']
250
-
251
- x.tCh<StandardSubj, ExpectedSubj>()
252
- x.tCh<ExpectedSubj, StandardSubj>()
253
-
254
- /* parsed either type check */
255
-
256
- type ExpectedParsed = x.ParseResult<ExpectedSubj>
257
-
258
- const parsed = x.parse(schema, undefined)
259
-
260
- type SchemaParsed = typeof parsed
261
-
262
- x.tCh<SchemaParsed, ExpectedParsed>()
263
- x.tCh<ExpectedParsed, SchemaParsed>()
264
-
265
- type ConstructParsed = ReturnType<typeof construct.parse>
266
-
267
- x.tCh<ConstructParsed, ExpectedParsed>()
268
- x.tCh<ExpectedParsed, ConstructParsed>()
269
-
270
- type StructParsed = ReturnType<typeof struct.parse>
271
-
272
- x.tCh<StructParsed, ExpectedParsed>()
273
- x.tCh<ExpectedParsed, StructParsed>()
274
-
275
- type StandardParsed = Extract<
276
- ReturnType<(typeof struct)['~standard']['validate']>,
277
- { value: unknown }
278
- >['value']
279
-
280
- x.tCh<StandardParsed, ExpectedSubj>()
281
- x.tCh<ExpectedSubj, StandardParsed>()
282
-
283
- /* runtime schema check */
284
-
285
- expect(struct.__schema).toStrictEqual(schema)
286
- expect(construct.__schema).toStrictEqual(schema)
287
- expect(construct.__schema === schema).toBe(false)
288
-
289
- /* parse result check */
290
-
291
- for (const subj of subjects) {
292
- const schemaParsed = x.parse(schema, subj)
293
-
294
- expect(schemaParsed.error).toBe(undefined)
295
- expect(schemaParsed.data).toStrictEqual(subj)
296
-
297
- const constructParsed = construct.parse(subj)
298
-
299
- expect(constructParsed.error).toBe(undefined)
300
- expect(constructParsed.data).toStrictEqual(subj)
301
-
302
- const structParsed = struct.parse(subj)
303
-
304
- expect(structParsed.error).toBe(undefined)
305
- expect(structParsed.data).toStrictEqual(subj)
306
-
307
- const standardParsed = struct['~standard'].validate(subj)
308
-
309
- if (standardParsed instanceof Promise) {
310
- throw Error('Not expected')
311
- }
312
-
313
- if (standardParsed.issues !== undefined) {
314
- throw Error('not expected')
315
- }
316
-
317
- expect(standardParsed.value).toStrictEqual(subj)
318
- }
319
- }
320
- })
321
-
322
- it('optional + nullable', () => {
323
- const schema = {
324
- type: 'boolean',
325
- optional: true,
326
- nullable: true,
327
- } as const satisfies x.Schema
328
- const struct = x.boolean().optional().nullable()
329
-
330
- type ExpectedSubj = boolean | undefined | null
331
-
332
- const subjects: Array<ExpectedSubj> = [true, false, null, undefined]
333
-
334
- foldA: {
335
- const construct = x.makeStruct(schema)
336
-
337
- /* ensure that schema/construct/struct/~standard subject types are identical */
338
-
339
- type ConstructSchemaSubj = x.Infer<typeof construct.__schema>
340
-
341
- x.tCh<ConstructSchemaSubj, ExpectedSubj>()
342
- x.tCh<ExpectedSubj, ConstructSchemaSubj>()
343
-
344
- type SchemaSubj = x.Infer<typeof schema>
345
-
346
- x.tCh<SchemaSubj, ExpectedSubj>()
347
- x.tCh<ExpectedSubj, SchemaSubj>()
348
-
349
- type StructSubj = x.Infer<typeof struct.__schema>
350
-
351
- x.tCh<StructSubj, ExpectedSubj>()
352
- x.tCh<ExpectedSubj, StructSubj>()
353
-
354
- type StandardSubj = NonNullable<
355
- (typeof struct)['~standard']['types']
356
- >['output']
357
-
358
- x.tCh<StandardSubj, ExpectedSubj>()
359
- x.tCh<ExpectedSubj, StandardSubj>()
360
-
361
- /* parsed either type check */
362
-
363
- type ExpectedParsed = x.ParseResult<ExpectedSubj>
364
-
365
- const parsed = x.parse(schema, undefined)
366
-
367
- type SchemaParsed = typeof parsed
368
-
369
- x.tCh<SchemaParsed, ExpectedParsed>()
370
- x.tCh<ExpectedParsed, SchemaParsed>()
371
-
372
- type ConstructParsed = ReturnType<typeof construct.parse>
373
-
374
- x.tCh<ConstructParsed, ExpectedParsed>()
375
- x.tCh<ExpectedParsed, ConstructParsed>()
376
-
377
- type StructParsed = ReturnType<typeof struct.parse>
378
-
379
- x.tCh<StructParsed, ExpectedParsed>()
380
- x.tCh<ExpectedParsed, StructParsed>()
381
-
382
- type StandardParsed = Extract<
383
- ReturnType<(typeof struct)['~standard']['validate']>,
384
- { value: unknown }
385
- >['value']
386
-
387
- x.tCh<StandardParsed, ExpectedSubj>()
388
- x.tCh<ExpectedSubj, StandardParsed>()
389
-
390
- /* runtime schema check */
391
-
392
- expect(struct.__schema).toStrictEqual(schema)
393
- expect(construct.__schema).toStrictEqual(schema)
394
- expect(construct.__schema === schema).toBe(false)
395
-
396
- /* parse result check */
397
-
398
- for (const subj of subjects) {
399
- const schemaParsed = x.parse(schema, subj)
400
-
401
- expect(schemaParsed.error).toBe(undefined)
402
- expect(schemaParsed.data).toStrictEqual(subj)
403
-
404
- const constructParsed = construct.parse(subj)
405
-
406
- expect(constructParsed.error).toBe(undefined)
407
- expect(constructParsed.data).toStrictEqual(subj)
408
-
409
- const structParsed = struct.parse(subj)
410
-
411
- expect(structParsed.error).toBe(undefined)
412
- expect(structParsed.data).toStrictEqual(subj)
413
-
414
- const standardParsed = struct['~standard'].validate(subj)
415
-
416
- if (standardParsed instanceof Promise) {
417
- throw Error('Not expected')
418
- }
419
-
420
- if (standardParsed.issues !== undefined) {
421
- throw Error('not expected')
422
- }
423
-
424
- expect(standardParsed.value).toStrictEqual(subj)
425
- }
426
- }
427
- })
428
- })
429
-
430
- describe('Struct parameter keys reduction and schema immutability (foldB)', () => {
431
- it('optional', () => {
432
- const schema = {
433
- type: 'boolean',
434
- optional: true,
435
- } as const satisfies x.Schema
436
-
437
- const prevStruct = x.boolean()
438
- const struct = prevStruct.optional()
439
-
440
- type ExpectedKeys = StructSharedKeys | 'brand' | 'nullable' | 'description'
441
-
442
- foldB: {
443
- const construct = x.makeStruct(schema)
444
-
445
- /* ensure that struct keys are reduced after application */
446
-
447
- type StructKeys = keyof typeof struct
448
-
449
- x.tCh<StructKeys, ExpectedKeys>()
450
- x.tCh<ExpectedKeys, StructKeys>()
451
-
452
- type ConstructKeys = keyof typeof construct
453
-
454
- x.tCh<ConstructKeys, ExpectedKeys>()
455
- x.tCh<ExpectedKeys, ConstructKeys>()
456
-
457
- /* ensure that construct/struct schema types are identical */
458
-
459
- type ExpectedSchema = typeof schema
460
- type StructSchema = typeof struct.__schema
461
-
462
- x.tCh<StructSchema, ExpectedSchema>()
463
- x.tCh<ExpectedSchema, StructSchema>()
464
-
465
- type ConstructSchema = typeof struct.__schema
466
-
467
- x.tCh<ConstructSchema, ExpectedSchema>()
468
- x.tCh<ExpectedSchema, ConstructSchema>()
469
-
470
- /* runtime schema check */
471
-
472
- expect(struct.__schema).toStrictEqual(schema)
473
- expect(construct.__schema).toStrictEqual(schema)
474
- expect(construct.__schema === schema).toBe(false)
475
-
476
- /* runtime schema parameter application immutability check */
477
-
478
- expect(prevStruct.__schema === struct.__schema).toBe(false)
479
- }
480
- })
481
-
482
- it('optional + nullable', () => {
483
- const schema = {
484
- type: 'boolean',
485
- optional: true,
486
- nullable: true,
487
- } as const satisfies x.Schema
488
-
489
- const prevStruct = x.boolean().optional()
490
- const struct = prevStruct.nullable()
491
-
492
- type ExpectedKeys = StructSharedKeys | 'brand' | 'description'
493
-
494
- foldB: {
495
- const construct = x.makeStruct(schema)
496
-
497
- /* ensure that struct keys are reduced after application */
498
-
499
- type StructKeys = keyof typeof struct
500
-
501
- x.tCh<StructKeys, ExpectedKeys>()
502
- x.tCh<ExpectedKeys, StructKeys>()
503
-
504
- type ConstructKeys = keyof typeof construct
505
-
506
- x.tCh<ConstructKeys, ExpectedKeys>()
507
- x.tCh<ExpectedKeys, ConstructKeys>()
508
-
509
- /* ensure that construct/struct schema types are identical */
510
-
511
- type ExpectedSchema = typeof schema
512
- type StructSchema = typeof struct.__schema
513
-
514
- x.tCh<StructSchema, ExpectedSchema>()
515
- x.tCh<ExpectedSchema, StructSchema>()
516
-
517
- type ConstructSchema = typeof struct.__schema
518
-
519
- x.tCh<ConstructSchema, ExpectedSchema>()
520
- x.tCh<ExpectedSchema, ConstructSchema>()
521
-
522
- /* runtime schema check */
523
-
524
- expect(struct.__schema).toStrictEqual(schema)
525
- expect(construct.__schema).toStrictEqual(schema)
526
- expect(construct.__schema === schema).toBe(false)
527
-
528
- /* runtime schema parameter application immutability check */
529
-
530
- expect(prevStruct.__schema === struct.__schema).toBe(false)
531
- }
532
- })
533
-
534
- it('optional + nullable + brand', () => {
535
- const schema = {
536
- type: 'boolean',
537
- optional: true,
538
- nullable: true,
539
- brand: ['x', 'y'],
540
- } as const satisfies x.Schema
541
-
542
- const prevStruct = x.boolean().optional().nullable()
543
- const struct = prevStruct.brand('x', 'y')
544
-
545
- type ExpectedKeys = StructSharedKeys | 'description'
546
-
547
- foldB: {
548
- const construct = x.makeStruct(schema)
549
-
550
- /* ensure that struct keys are reduced after application */
551
-
552
- type StructKeys = keyof typeof struct
553
-
554
- x.tCh<StructKeys, ExpectedKeys>()
555
- x.tCh<ExpectedKeys, StructKeys>()
556
-
557
- type ConstructKeys = keyof typeof construct
558
-
559
- x.tCh<ConstructKeys, ExpectedKeys>()
560
- x.tCh<ExpectedKeys, ConstructKeys>()
561
-
562
- /* ensure that construct/struct schema types are identical */
563
-
564
- type ExpectedSchema = typeof schema
565
- type StructSchema = typeof struct.__schema
566
-
567
- x.tCh<StructSchema, ExpectedSchema>()
568
- x.tCh<ExpectedSchema, StructSchema>()
569
-
570
- type ConstructSchema = typeof struct.__schema
571
-
572
- x.tCh<ConstructSchema, ExpectedSchema>()
573
- x.tCh<ExpectedSchema, ConstructSchema>()
574
-
575
- /* runtime schema check */
576
-
577
- expect(struct.__schema).toStrictEqual(schema)
578
- expect(construct.__schema).toStrictEqual(schema)
579
- expect(construct.__schema === schema).toBe(false)
580
-
581
- /* runtime schema parameter application immutability check */
582
-
583
- expect(prevStruct.__schema === struct.__schema).toBe(false)
584
- }
585
- })
586
-
587
- it('optional + nullable + brand + description', () => {
588
- const schema = {
589
- type: 'boolean',
590
- optional: true,
591
- nullable: true,
592
- brand: ['x', 'y'],
593
- description: 'x',
594
- } as const satisfies x.Schema
595
-
596
- const prevStruct = x.boolean().optional().nullable().brand('x', 'y')
597
- const struct = prevStruct.description('x')
598
-
599
- type ExpectedKeys = StructSharedKeys
600
-
601
- foldB: {
602
- const construct = x.makeStruct(schema)
603
-
604
- /* ensure that struct keys are reduced after application */
605
-
606
- type StructKeys = keyof typeof struct
607
-
608
- x.tCh<StructKeys, ExpectedKeys>()
609
- x.tCh<ExpectedKeys, StructKeys>()
610
-
611
- type ConstructKeys = keyof typeof construct
612
-
613
- x.tCh<ConstructKeys, ExpectedKeys>()
614
- x.tCh<ExpectedKeys, ConstructKeys>()
615
-
616
- /* ensure that construct/struct schema types are identical */
617
-
618
- type ExpectedSchema = typeof schema
619
- type StructSchema = typeof struct.__schema
620
-
621
- x.tCh<StructSchema, ExpectedSchema>()
622
- x.tCh<ExpectedSchema, StructSchema>()
623
-
624
- type ConstructSchema = typeof struct.__schema
625
-
626
- x.tCh<ConstructSchema, ExpectedSchema>()
627
- x.tCh<ExpectedSchema, ConstructSchema>()
628
-
629
- /* runtime schema check */
630
-
631
- expect(struct.__schema).toStrictEqual(schema)
632
- expect(construct.__schema).toStrictEqual(schema)
633
- expect(construct.__schema === schema).toBe(false)
634
-
635
- /* runtime schema parameter application immutability check */
636
-
637
- expect(prevStruct.__schema === struct.__schema).toBe(false)
638
- }
639
- })
640
-
641
- it('description + brand + nullable + optional', () => {
642
- const schema = {
643
- type: 'boolean',
644
- optional: true,
645
- nullable: true,
646
- brand: ['x', 'y'],
647
- description: 'x',
648
- } as const satisfies x.Schema
649
-
650
- const prevStruct = x.boolean().description('x').brand('x', 'y').nullable()
651
- const struct = prevStruct.optional()
652
-
653
- type ExpectedKeys = StructSharedKeys
654
-
655
- foldB: {
656
- const construct = x.makeStruct(schema)
657
-
658
- /* ensure that struct keys are reduced after application */
659
-
660
- type StructKeys = keyof typeof struct
661
-
662
- x.tCh<StructKeys, ExpectedKeys>()
663
- x.tCh<ExpectedKeys, StructKeys>()
664
-
665
- type ConstructKeys = keyof typeof construct
666
-
667
- x.tCh<ConstructKeys, ExpectedKeys>()
668
- x.tCh<ExpectedKeys, ConstructKeys>()
669
-
670
- /* ensure that construct/struct schema types are identical */
671
-
672
- type ExpectedSchema = typeof schema
673
- type StructSchema = typeof struct.__schema
674
-
675
- x.tCh<StructSchema, ExpectedSchema>()
676
- x.tCh<ExpectedSchema, StructSchema>()
677
-
678
- type ConstructSchema = typeof struct.__schema
679
-
680
- x.tCh<ConstructSchema, ExpectedSchema>()
681
- x.tCh<ExpectedSchema, ConstructSchema>()
682
-
683
- /* runtime schema check */
684
-
685
- expect(struct.__schema).toStrictEqual(schema)
686
- expect(construct.__schema).toStrictEqual(schema)
687
- expect(construct.__schema === schema).toBe(false)
688
-
689
- /* runtime schema parameter application immutability check */
690
-
691
- expect(prevStruct.__schema === struct.__schema).toBe(false)
692
- }
693
- })
694
- })
695
-
696
- describe('ERROR_CODE.invalidType (foldC)', () => {
697
- it('iterate over fixture.DATA_TYPE', () => {
698
- const schema = { type: 'boolean' } satisfies x.Schema
699
- const struct = x.boolean()
700
- const source = fixture.DATA_TYPE
701
-
702
- foldC: {
703
- const construct = x.makeStruct(schema)
704
-
705
- for (const [kind, types] of source) {
706
- if (kind === schema.type) {
707
- continue
708
- }
709
-
710
- for (const subject of types) {
711
- const expectedError = [
712
- {
713
- code: x.ERROR_CODE.invalidType,
714
- schema: schema,
715
- subject: subject,
716
- path: [],
717
- },
718
- ]
719
-
720
- const parsedSchema = x.parse(schema, subject)
721
- const parsedConstruct = construct.parse(subject)
722
- const parsedStruct = struct.parse(subject)
723
-
724
- expect(parsedSchema.error).toStrictEqual(expectedError)
725
- expect(parsedConstruct.error).toStrictEqual(expectedError)
726
- expect(parsedStruct.error).toStrictEqual(expectedError)
727
-
728
- const parsedStandard = struct['~standard'].validate(subject)
729
-
730
- if (parsedStandard instanceof Promise) {
731
- throw Error('Not expected')
732
- }
733
-
734
- expect(parsedStandard.issues).toStrictEqual([
735
- { message: x.ERROR_CODE.invalidType, path: [] },
736
- ])
737
- }
738
- }
739
- }
740
- })
741
- })