@litert/typeguard 1.3.0 → 1.4.0
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.
- package/CHANGES.md +7 -1
- package/lib/BuiltInTypeCompiler.d.ts +1 -1
- package/lib/BuiltInTypeCompiler.js +4 -4
- package/lib/BuiltInTypeCompiler.js.map +1 -1
- package/lib/BuiltInTypes.d.ts +1 -1
- package/lib/BuiltInTypes.js +1 -1
- package/lib/Common.d.ts +6 -5
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +1 -1
- package/lib/Compiler.d.ts +1 -1
- package/lib/Compiler.d.ts.map +1 -1
- package/lib/Compiler.js +57 -35
- package/lib/Compiler.js.map +1 -1
- package/lib/Context.d.ts +2 -2
- package/lib/Context.d.ts.map +1 -1
- package/lib/Context.js +2 -2
- package/lib/Context.js.map +1 -1
- package/lib/FilterCompiler.d.ts +3 -3
- package/lib/FilterCompiler.d.ts.map +1 -1
- package/lib/FilterCompiler.js +4 -4
- package/lib/FilterCompiler.js.map +1 -1
- package/lib/InlineCompiler.d.ts +2 -2
- package/lib/InlineCompiler.d.ts.map +1 -1
- package/lib/InlineCompiler.js +5 -7
- package/lib/InlineCompiler.js.map +1 -1
- package/lib/Internal.d.ts +9 -4
- package/lib/Internal.d.ts.map +1 -1
- package/lib/Internal.js +45 -4
- package/lib/Internal.js.map +1 -1
- package/lib/Modifiers.d.ts +2 -1
- package/lib/Modifiers.d.ts.map +1 -1
- package/lib/Modifiers.js +3 -2
- package/lib/Modifiers.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/langs/JavaScript.d.ts +1 -1
- package/lib/langs/JavaScript.js +2 -2
- package/package.json +10 -12
- package/src/examples/quick-start.ts +5 -1
- package/src/lib/BuiltInTypeCompiler.ts +4 -4
- package/src/lib/BuiltInTypes.ts +1 -1
- package/src/lib/Common.ts +5 -4
- package/src/lib/Compiler.ts +66 -39
- package/src/lib/Context.ts +2 -2
- package/src/lib/FilterCompiler.ts +3 -3
- package/src/lib/InlineCompiler.ts +6 -9
- package/src/lib/Internal.ts +73 -4
- package/src/lib/Modifiers.ts +3 -1
- package/src/lib/index.ts +1 -1
- package/src/lib/langs/JavaScript.ts +2 -2
- package/src/test/00-all.ts +1 -1
- package/src/test/01-elemental-types.ts +580 -580
- package/src/test/02-array-and-list.ts +43 -43
- package/src/test/03-tuple.ts +61 -61
- package/src/test/04-from-string.ts +501 -501
- package/src/test/05-string-asserts.ts +203 -203
- package/src/test/06-structure.ts +71 -71
- package/src/test/07-modifiers.ts +297 -48
- package/src/test/08-map-and-dict.ts +11 -11
- package/src/test/09-exceptions.ts +11 -11
- package/src/test/abstracts.ts +57 -29
package/src/test/06-structure.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2023 Angus Fenying <fenying@litert.org>
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { createTestDefinition,
|
|
17
|
+
import { createTestDefinition, defaultItems, ITestSuite } from './abstracts';
|
|
18
18
|
|
|
19
19
|
const testItems: ITestSuite = {
|
|
20
20
|
|
|
@@ -26,21 +26,21 @@ const testItems: ITestSuite = {
|
|
|
26
26
|
'rule': {},
|
|
27
27
|
'items': [
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
title: 'Empty object',
|
|
30
|
+
value: {},
|
|
31
31
|
expect: true
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
title: 'Object with one property',
|
|
35
|
+
value: { 'a': 123 },
|
|
36
36
|
expect: true
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
title: '[int, string]',
|
|
40
|
+
value: [123, 'fff'],
|
|
41
41
|
expect: false
|
|
42
42
|
},
|
|
43
|
-
...
|
|
43
|
+
...defaultItems({
|
|
44
44
|
'object': true
|
|
45
45
|
})
|
|
46
46
|
]
|
|
@@ -50,21 +50,21 @@ const testItems: ITestSuite = {
|
|
|
50
50
|
'rule': { 'a': 'uint32' },
|
|
51
51
|
'items': [
|
|
52
52
|
{
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
title: 'Empty object',
|
|
54
|
+
value: {},
|
|
55
55
|
expect: false
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
title: 'Object with one property',
|
|
59
|
+
value: { 'a': 123 },
|
|
60
60
|
expect: true
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
title: '[int, string]',
|
|
64
|
+
value: [123, 'fff'],
|
|
65
65
|
expect: false
|
|
66
66
|
},
|
|
67
|
-
...
|
|
67
|
+
...defaultItems({
|
|
68
68
|
'object': false
|
|
69
69
|
})
|
|
70
70
|
]
|
|
@@ -74,26 +74,26 @@ const testItems: ITestSuite = {
|
|
|
74
74
|
'rule': { 'a?': 'uint32' },
|
|
75
75
|
'items': [
|
|
76
76
|
{
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
title: 'Empty object',
|
|
78
|
+
value: {},
|
|
79
79
|
expect: true
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
title: 'Object with one property',
|
|
83
|
+
value: { 'a': 123 },
|
|
84
84
|
expect: true
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
title: 'Object with one mismatch-type property',
|
|
88
|
+
value: { 'a': '123' },
|
|
89
89
|
expect: false
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
title: '[int, string]',
|
|
93
|
+
value: [123, 'fff'],
|
|
94
94
|
expect: false
|
|
95
95
|
},
|
|
96
|
-
...
|
|
96
|
+
...defaultItems({
|
|
97
97
|
'object': true
|
|
98
98
|
})
|
|
99
99
|
]
|
|
@@ -103,28 +103,28 @@ const testItems: ITestSuite = {
|
|
|
103
103
|
'rule': { 'a?': 'uint32', 'b': { 'c': 'string' } },
|
|
104
104
|
'items': [
|
|
105
105
|
{
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
title: 'Empty object',
|
|
107
|
+
value: {},
|
|
108
108
|
expect: false
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
title: 'Object with one property',
|
|
112
|
+
value: { 'a': 123 },
|
|
113
113
|
expect: false
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
title: 'Object with mismatch-typed nest property',
|
|
117
|
+
value: { 'a': 123, 'b': { 'c': 1232131 } },
|
|
118
118
|
expect: false
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
title: 'Object with one mismatch-typed property',
|
|
122
|
+
value: { 'a': '123', 'b': { 'c': 'ffff' } },
|
|
123
123
|
expect: false
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
title: 'Object with all corrected',
|
|
127
|
+
value: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
128
128
|
expect: true
|
|
129
129
|
}
|
|
130
130
|
]
|
|
@@ -136,23 +136,23 @@ const testItems: ITestSuite = {
|
|
|
136
136
|
}],
|
|
137
137
|
'items': [
|
|
138
138
|
{
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
title: 'Empty object',
|
|
140
|
+
value: {},
|
|
141
141
|
expect: false
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
title: 'Object with one property',
|
|
145
|
+
value: { 'a': 123 },
|
|
146
146
|
expect: true
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
title: 'Object with one mismatch-typed property',
|
|
150
|
+
value: { 'a': '123' },
|
|
151
151
|
expect: false
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
title: 'Object with 2 properties',
|
|
155
|
+
value: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
156
156
|
expect: false
|
|
157
157
|
}
|
|
158
158
|
]
|
|
@@ -167,23 +167,23 @@ const testItems: ITestSuite = {
|
|
|
167
167
|
}],
|
|
168
168
|
'items': [
|
|
169
169
|
{
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
title: 'Object with one property',
|
|
171
|
+
value: { 'a': 123 },
|
|
172
172
|
expect: false
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
title: 'Object with wrong type in nest',
|
|
176
|
+
value: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
177
177
|
expect: false
|
|
178
178
|
},
|
|
179
179
|
{
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
title: 'Object with all correct',
|
|
181
|
+
value: { 'a': 123, 'b': { 'c': 123 } },
|
|
182
182
|
expect: true
|
|
183
183
|
},
|
|
184
184
|
{
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
title: 'Object with one more in nested',
|
|
186
|
+
value: { 'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
|
|
187
187
|
expect: true
|
|
188
188
|
}
|
|
189
189
|
]
|
|
@@ -198,23 +198,23 @@ const testItems: ITestSuite = {
|
|
|
198
198
|
}],
|
|
199
199
|
'items': [
|
|
200
200
|
{
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
title: 'Object with one property',
|
|
202
|
+
value: { 'a': 123 },
|
|
203
203
|
expect: false
|
|
204
204
|
},
|
|
205
205
|
{
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
title: 'Object with wrong type in nest',
|
|
207
|
+
value: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
208
208
|
expect: false
|
|
209
209
|
},
|
|
210
210
|
{
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
title: 'Object with all correct',
|
|
212
|
+
value: { 'a': 123, 'b': { 'c': 123 } },
|
|
213
213
|
expect: true
|
|
214
214
|
},
|
|
215
215
|
{
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
title: 'Object with one more in nested',
|
|
217
|
+
value: { 'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
|
|
218
218
|
expect: false
|
|
219
219
|
}
|
|
220
220
|
]
|
|
@@ -229,18 +229,18 @@ const testItems: ITestSuite = {
|
|
|
229
229
|
}],
|
|
230
230
|
'items': [
|
|
231
231
|
{
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
title: 'Object with all correct',
|
|
233
|
+
value: { 'a': 123, 'b': { 'c': 123 } },
|
|
234
234
|
expect: true
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
title: 'Object with string incorrect-value',
|
|
238
|
+
value: { 'a': 123, 'b': { 'c': '123d' } },
|
|
239
239
|
expect: false
|
|
240
240
|
},
|
|
241
241
|
{
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
title: 'Object with string value',
|
|
243
|
+
value: { 'a': '123312312', 'b': { 'c': '123' } },
|
|
244
244
|
expect: true
|
|
245
245
|
}
|
|
246
246
|
]
|
|
@@ -255,18 +255,18 @@ const testItems: ITestSuite = {
|
|
|
255
255
|
}],
|
|
256
256
|
'items': [
|
|
257
257
|
{
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
title: 'Object with all correct',
|
|
259
|
+
value: { 'a': 123, 'b': { 'c': 123 } },
|
|
260
260
|
expect: true
|
|
261
261
|
},
|
|
262
262
|
{
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
title: 'Object with string incorrect-value',
|
|
264
|
+
value: { 'a': 123, 'b': { 'c': '123d' } },
|
|
265
265
|
expect: false
|
|
266
266
|
},
|
|
267
267
|
{
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
title: 'Object with string value',
|
|
269
|
+
value: { 'a': '123312312', 'b': { 'c': '123' } },
|
|
270
270
|
expect: true
|
|
271
271
|
}
|
|
272
272
|
]
|