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

Commit 34109f9

Browse files
committed
docs: add runnable quick start example
1 parent a52f4c3 commit 34109f9

File tree

5 files changed

+121
-6
lines changed

5 files changed

+121
-6
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ const fuzzer = fuzz.exampleGenerator(r, target);
3131

3232
// Make examples. The input integer and context
3333
// fully determines the output example.
34-
console.log(fuzzer.encode([0, fuzz.fuzzContext()]));
35-
console.log(fuzzer.encode([1, fuzz.fuzzContext()]));
36-
console.log(fuzzer.encode([2, fuzz.fuzzContext()]));
37-
console.log(fuzzer.encode([493, fuzz.fuzzContext()]));
34+
for (const n of new Array(10).keys()) {
35+
console.log(JSON.stringify(fuzzer.encode([n, fuzz.fuzzContext()])));
36+
}
3837
```
3938

39+
See [examples/quickstart/index.ts](examples/quickstart/index.ts).
40+
4041
## Types Supported
4142

4243
Currently supports (along with their closure under composition):

examples/quickstart/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as t from 'io-ts';
2+
import * as fuzz from 'io-ts-fuzzer';
3+
4+
// Fuzzers for common types
5+
const r = fuzz.createCoreRegistry();
6+
7+
// Type to fuzz
8+
const target = t.union([t.string, t.type({ n: t.number, b: t.boolean })]);
9+
10+
// Builds a particular fuzzer from the registry.
11+
const fuzzer = fuzz.exampleGenerator(r, target);
12+
13+
// Make examples. The input integer and context
14+
// fully determines the output example.
15+
for (const n of new Array(10).keys()) {
16+
console.log(JSON.stringify(fuzzer.encode([n, fuzz.fuzzContext()])));
17+
}

examples/quickstart/package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "quickstart",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "Apache-2.0",
6+
"private": true,
7+
"scripts": {
8+
"start": "ts-node index.ts"
9+
},
10+
"dependencies": {
11+
"fp-ts": "^2.0.4",
12+
"io-ts": "^2.0.1",
13+
"io-ts-fuzzer": "../../"
14+
},
15+
"devDependencies": {
16+
"ts-node": "^8.3.0",
17+
"typescript": "^3.5.3"
18+
}
19+
}

examples/quickstart/yarn.lock

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
arg@^4.1.0:
6+
version "4.1.1"
7+
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.1.tgz#485f8e7c390ce4c5f78257dbea80d4be11feda4c"
8+
integrity sha512-SlmP3fEA88MBv0PypnXZ8ZfJhwmDeIE3SP71j37AiXQBXYosPV0x6uISAaHYSlSVhmHOVkomen0tbGk6Anlebw==
9+
10+
buffer-from@^1.0.0:
11+
version "1.1.1"
12+
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
13+
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
14+
15+
diff@^4.0.1:
16+
version "4.0.1"
17+
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
18+
integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==
19+
20+
fp-ts@^2.0.4:
21+
version "2.0.4"
22+
resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.0.4.tgz#a07ceef59c2460616fcf70367708ebe4d1c2212f"
23+
integrity sha512-oRQbFqqGcvorkEj92dAcM4/RH1TARJCt8wVgynRIp8v4uOzVCe4kCs7vKSYpIXQsvtpyCt9nVVFqufSX8VYghg==
24+
25+
io-ts-fuzzer@../../:
26+
version "3.0.0"
27+
dependencies:
28+
seedrandom "^3.0.1"
29+
30+
io-ts@^2.0.1:
31+
version "2.0.1"
32+
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.1.tgz#1261c12f915c2f48d16393a36966636b48a45aa1"
33+
integrity sha512-RezD+WcCfW4VkMkEcQWL/Nmy/nqsWTvTYg7oUmTGzglvSSV2P9h2z1PVeREPFf0GWNzruYleAt1XCMQZSg1xxQ==
34+
35+
make-error@^1.1.1:
36+
version "1.3.5"
37+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
38+
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
39+
40+
seedrandom@^3.0.1:
41+
version "3.0.1"
42+
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.1.tgz#eb3dde015bcf55df05a233514e5df44ef9dce083"
43+
integrity sha512-1/02Y/rUeU1CJBAGLebiC5Lbo5FnB22gQbIFFYTLkwvp1xdABZJH1sn4ZT1MzXmPpzv+Rf/Lu2NcsLJiK4rcDg==
44+
45+
source-map-support@^0.5.6:
46+
version "0.5.13"
47+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
48+
integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==
49+
dependencies:
50+
buffer-from "^1.0.0"
51+
source-map "^0.6.0"
52+
53+
source-map@^0.6.0:
54+
version "0.6.1"
55+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
56+
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
57+
58+
ts-node@^8.3.0:
59+
version "8.3.0"
60+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.3.0.tgz#e4059618411371924a1fb5f3b125915f324efb57"
61+
integrity sha512-dyNS/RqyVTDcmNM4NIBAeDMpsAdaQ+ojdf0GOLqE6nwJOgzEkdRNzJywhDfwnuvB10oa6NLVG1rUJQCpRN7qoQ==
62+
dependencies:
63+
arg "^4.1.0"
64+
diff "^4.0.1"
65+
make-error "^1.1.1"
66+
source-map-support "^0.5.6"
67+
yn "^3.0.0"
68+
69+
typescript@^3.5.3:
70+
version "3.5.3"
71+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
72+
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==
73+
74+
yn@^3.0.0:
75+
version "3.1.1"
76+
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
77+
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"lint": "yarn fix && yarn run check",
5656
"check": "yarn run pretty.check && gts check",
5757
"fix": "yarn run pretty.fix && gts fix",
58-
"preversion": "yarn test",
58+
"test.examples": "pushd examples/quickstart && rm yarn.lock && yarn && yarn start",
59+
"preversion": "yarn test && yarn test.examples",
5960
"docs": "yarn clean && yarn build && rm -rf docs && mkdir -p docs && ( mocha --grep='#private' --invert -R markdown >docs/index.md )",
6061
"test-unit": "yarn test --grep='#e2e|#int' --invert",
6162
"test-e2e": "yarn test --grep='#e2e'",
@@ -70,7 +71,7 @@
7071
"sideEffects": false,
7172
"husky": {
7273
"hooks": {
73-
"pre-commit": "yarn clean && yarn run check && yarn test:postinstall"
74+
"pre-commit": "yarn clean && yarn run check && yarn test:postinstall && yarn test.examples"
7475
}
7576
},
7677
"release": {

0 commit comments

Comments
 (0)