Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit b7c6467

Browse files
committed
feat: support literals
1 parent 37d5840 commit b7c6467

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Currently supports:
4848
* `t.void`
4949
* `t.unknown`
5050
* `t.Int`
51+
* `t.literal`
5152

5253
## Use Cases
5354

src/core/core.ts

+11
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ export function fuzzUnknown(n: number): unknown {
115115
return n;
116116
}
117117

118+
export function fuzzLiteral(
119+
b: t.LiteralType<string | number | boolean>
120+
): ConcreteFuzzer<unknown> {
121+
return {
122+
func: n => {
123+
return b.value;
124+
},
125+
};
126+
}
127+
118128
export function fuzzUnion(b: t.UnionType<t.Mixed[]>): ConcreteFuzzer<unknown> {
119129
return {
120130
children: b.types,
@@ -206,4 +216,5 @@ export const coreFuzzers = [
206216
gen(fuzzPartial, 'PartialType'),
207217
gen(fuzzArray, 'ArrayType'),
208218
gen(fuzzIntersection, 'IntersectionType'),
219+
gen(fuzzLiteral, 'LiteralType'),
209220
];

test/helpers.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export const types = [
1515
t.unknown,
1616
t.array(t.string),
1717
t.Int,
18-
18+
t.literal('hello'),
19+
t.literal(34.4),
20+
t.literal(true),
21+
t.literal(''),
22+
t.literal(0),
23+
t.literal(false),
1924
// Complex types
2025
t.type({ s: t.string, m: t.type({ n: t.Int }) }),
2126
t.type({

0 commit comments

Comments
 (0)