@@ -2,8 +2,8 @@ import * as S from 'rescript-schema';
2
2
3
3
import { createCase } from '../benchmarks' ;
4
4
5
- createCase ( 'rescript-schema' , 'parseSafe' , ( ) => {
6
- const schema = S . object ( {
5
+ const makeSchema = ( ) =>
6
+ S . object ( {
7
7
number : S . number ,
8
8
negNumber : S . number ,
9
9
maxNumber : S . number ,
@@ -17,79 +17,50 @@ createCase('rescript-schema', 'parseSafe', () => {
17
17
} ) ,
18
18
} ) ;
19
19
20
+ createCase ( 'rescript-schema' , 'parseSafe' , ( ) => {
21
+ S . setGlobalConfig ( {
22
+ disableNanNumberCheck : true ,
23
+ } ) ;
24
+ const schema = makeSchema ( ) ;
25
+
20
26
return data => {
21
- return S . parseOrThrow ( schema , data ) ;
27
+ return schema . parseOrThrow ( data ) ;
22
28
} ;
23
29
} ) ;
24
30
25
31
createCase ( 'rescript-schema' , 'parseStrict' , ( ) => {
26
- const schema = S . Object . strict (
27
- S . object ( {
28
- number : S . number ,
29
- negNumber : S . number ,
30
- maxNumber : S . number ,
31
- string : S . string ,
32
- longString : S . string ,
33
- boolean : S . boolean ,
34
- deeplyNested : S . Object . strict (
35
- S . object ( {
36
- foo : S . string ,
37
- num : S . number ,
38
- bool : S . boolean ,
39
- } )
40
- ) ,
41
- } )
42
- ) ;
32
+ S . setGlobalConfig ( {
33
+ disableNanNumberCheck : true ,
34
+ defaultUnknownKeys : 'Strict' ,
35
+ } ) ;
36
+ const schema = makeSchema ( ) ;
43
37
44
38
return data => {
45
- return S . parseOrThrow ( schema , data ) ;
39
+ return schema . parseOrThrow ( data ) ;
46
40
} ;
47
41
} ) ;
48
42
49
43
createCase ( 'rescript-schema' , 'assertLoose' , ( ) => {
50
- const schema = S . object ( {
51
- number : S . number ,
52
- negNumber : S . number ,
53
- maxNumber : S . number ,
54
- string : S . string ,
55
- longString : S . string ,
56
- boolean : S . boolean ,
57
- deeplyNested : S . object ( {
58
- foo : S . string ,
59
- num : S . number ,
60
- bool : S . boolean ,
61
- } ) ,
44
+ S . setGlobalConfig ( {
45
+ disableNanNumberCheck : true ,
62
46
} ) ;
47
+ const schema = makeSchema ( ) ;
63
48
64
49
return data => {
65
- S . parseOrThrow ( schema , data ) ;
66
-
50
+ schema . assert ( data ) ! ;
67
51
return true ;
68
52
} ;
69
53
} ) ;
70
54
71
55
createCase ( 'rescript-schema' , 'assertStrict' , ( ) => {
72
- const schema = S . Object . strict (
73
- S . object ( {
74
- number : S . number ,
75
- negNumber : S . number ,
76
- maxNumber : S . number ,
77
- string : S . string ,
78
- longString : S . string ,
79
- boolean : S . boolean ,
80
- deeplyNested : S . Object . strict (
81
- S . object ( {
82
- foo : S . string ,
83
- num : S . number ,
84
- bool : S . boolean ,
85
- } )
86
- ) ,
87
- } )
88
- ) ;
56
+ S . setGlobalConfig ( {
57
+ disableNanNumberCheck : true ,
58
+ defaultUnknownKeys : 'Strict' ,
59
+ } ) ;
60
+ const schema = makeSchema ( ) ;
89
61
90
62
return data => {
91
- S . parseOrThrow ( schema , data ) ;
92
-
63
+ schema . assert ( data ) ! ;
93
64
return true ;
94
65
} ;
95
66
} ) ;
0 commit comments