1+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Test using this disabled, see https://github.com/fastify/fast-json-stringify/pull/683
12import Ajv from 'ajv'
23import build, { restore, Schema, validLargeArrayMechanisms } from '..'
34import { expectError, expectType } from 'tsd'
45
56// Number schemas
67build({
7- type: 'number'
8+ type: 'number'
89})(25)
910build({
10- type: 'integer'
11+ type: 'integer'
1112})(-5)
1213build({
13- type: 'integer'
14+ type: 'integer'
1415})(5n)
1516
1617build({
17- type: 'number'
18+ type: 'number'
1819}, { rounding: 'ceil' })
1920build({
20- type: 'number'
21+ type: 'number'
2122}, { rounding: 'floor' })
2223build({
23- type: 'number'
24+ type: 'number'
2425}, { rounding: 'round' })
2526build({
26- type: 'number'
27+ type: 'number'
2728}, { rounding: 'trunc' })
2829expectError(build({
29- type: 'number'
30+ type: 'number'
3031}, { rounding: 'invalid' }))
3132
3233// String schema
@@ -36,55 +37,55 @@ build({
3637
3738// Boolean schema
3839build({
39- type: 'boolean'
40+ type: 'boolean'
4041})(true)
4142
4243// Null schema
4344build({
44- type: 'null'
45+ type: 'null'
4546})(null)
4647
4748// Array schemas
4849build({
49- type: 'array',
50- items: { type: 'number' }
50+ type: 'array',
51+ items: { type: 'number' }
5152})([25])
5253build({
53- type: 'array',
54- items: [{ type: 'string'}, {type: 'integer'}]
54+ type: 'array',
55+ items: [{ type: 'string' }, { type: 'integer' }]
5556})(['hello', 42])
5657
5758// Object schemas
5859build({
59- type: 'object'
60+ type: 'object'
6061})({})
6162build({
62- type: 'object',
63- properties: {
64- foo: { type: 'string' },
65- bar: { type: 'integer' }
66- },
67- required: ['foo'],
68- patternProperties: {
69- 'baz*': { type: 'null' }
70- },
71- additionalProperties: {
72- type: 'boolean'
73- }
63+ type: 'object',
64+ properties: {
65+ foo: { type: 'string' },
66+ bar: { type: 'integer' }
67+ },
68+ required: ['foo'],
69+ patternProperties: {
70+ 'baz*': { type: 'null' }
71+ },
72+ additionalProperties: {
73+ type: 'boolean'
74+ }
7475})({ foo: 'bar' })
7576build({
76- type: 'object',
77- properties: {
78- foo: { type: 'string' },
79- bar: { type: 'integer' }
80- },
81- required: ['foo'],
82- patternProperties: {
83- 'baz*': { type: 'null' }
84- },
85- additionalProperties: {
86- type: 'boolean'
87- }
77+ type: 'object',
78+ properties: {
79+ foo: { type: 'string' },
80+ bar: { type: 'integer' }
81+ },
82+ required: ['foo'],
83+ patternProperties: {
84+ 'baz*': { type: 'null' }
85+ },
86+ additionalProperties: {
87+ type: 'boolean'
88+ }
8889}, { rounding: 'floor' })({ foo: 'bar' })
8990
9091// Reference schemas
@@ -113,7 +114,7 @@ build({
113114 }
114115 },
115116 patternProperties: {
116- ' num' : {
117+ num: {
117118 $ref: '#/definitions/num'
118119 }
119120 },
@@ -207,52 +208,52 @@ interface InferenceSchema {
207208}
208209
209210const stringify3 = build({
210- type: " object" ,
211- properties: { a: { type: " string" } },
212- });
213- stringify3<InferenceSchema>({ id: " 123" });
214- stringify3<InferenceSchema>({ a: 123, id: " 123" });
215- expectError(stringify3<InferenceSchema>({ anotherOne: " bar" }));
216- expectError(stringify3<Schema>({ a: " bar" }));
211+ type: ' object' ,
212+ properties: { a: { type: ' string' } },
213+ })
214+ stringify3<InferenceSchema>({ id: ' 123' })
215+ stringify3<InferenceSchema>({ a: 123, id: ' 123' })
216+ expectError(stringify3<InferenceSchema>({ anotherOne: ' bar' }))
217+ expectError(stringify3<Schema>({ a: ' bar' }))
217218
218219// Without inference
219220const stringify4 = build({
220- type: " object" ,
221- properties: { a: { type: " string" } },
222- });
223- stringify4({ id: " 123" });
224- stringify4({ a: 123, id: " 123" });
225- stringify4({ anotherOne: " bar" });
226- stringify4({ a: " bar" });
221+ type: ' object' ,
222+ properties: { a: { type: ' string' } },
223+ })
224+ stringify4({ id: ' 123' })
225+ stringify4({ a: 123, id: ' 123' })
226+ stringify4({ anotherOne: ' bar' })
227+ stringify4({ a: ' bar' })
227228
228229// Without inference - string type
229230const stringify5 = build({
230- type: " string" ,
231- });
232- stringify5(" foo");
233- expectError(stringify5({ id: " 123" }));
231+ type: ' string' ,
232+ })
233+ stringify5(' foo')
234+ expectError(stringify5({ id: ' 123' }))
234235
235236// Without inference - null type
236237const stringify6 = build({
237- type: " null" ,
238- });
239- stringify6(null);
240- expectError(stringify6(" a string"));
238+ type: ' null' ,
239+ })
240+ stringify6(null)
241+ expectError(stringify6(' a string'))
241242
242243// Without inference - boolean type
243244const stringify7 = build({
244- type: " boolean" ,
245- });
246- stringify7(true);
247- expectError(stringify7(" a string"));
245+ type: ' boolean' ,
246+ })
247+ stringify7(true)
248+ expectError(stringify7(' a string'))
248249
249250// largeArrayMechanism
250251
251- build({}, { largeArrayMechanism: 'json-stringify'} )
252- build({}, { largeArrayMechanism: 'default'} )
253- expectError(build({} as Schema, { largeArrayMechanism: 'invalid'} ))
252+ build({}, { largeArrayMechanism: 'json-stringify' } )
253+ build({}, { largeArrayMechanism: 'default' } )
254+ expectError(build({} as Schema, { largeArrayMechanism: 'invalid' } ))
254255
255- build({}, { largeArraySize: 2000 } )
256- build({}, { largeArraySize: '2e4' } )
257- build({}, { largeArraySize: 2n } )
258- expectError(build({} as Schema, { largeArraySize: ['asdf']} ))
256+ build({}, { largeArraySize: 2000 })
257+ build({}, { largeArraySize: '2e4' })
258+ build({}, { largeArraySize: 2n })
259+ expectError(build({} as Schema, { largeArraySize: ['asdf'] } ))
0 commit comments