@litert/typeguard 1.0.0 → 1.2.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 +15 -0
- package/lib/BuiltInTypeCompiler.d.ts +4 -4
- package/lib/BuiltInTypeCompiler.d.ts.map +1 -1
- package/lib/BuiltInTypeCompiler.js +167 -166
- package/lib/BuiltInTypeCompiler.js.map +1 -1
- package/lib/BuiltInTypes.d.ts +1 -1
- package/lib/BuiltInTypes.js +37 -36
- package/lib/BuiltInTypes.js.map +1 -1
- package/lib/Common.d.ts +13 -9
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +1 -1
- package/lib/Compiler.d.ts +2 -2
- package/lib/Compiler.d.ts.map +1 -1
- package/lib/Compiler.js +77 -72
- package/lib/Compiler.js.map +1 -1
- package/lib/Context.d.ts +2 -2
- package/lib/Context.js +3 -2
- package/lib/Context.js.map +1 -1
- package/lib/FilterCompiler.d.ts +5 -5
- package/lib/FilterCompiler.d.ts.map +1 -1
- package/lib/FilterCompiler.js +25 -24
- package/lib/FilterCompiler.js.map +1 -1
- package/lib/InlineCompiler.d.ts +12 -5
- package/lib/InlineCompiler.d.ts.map +1 -1
- package/lib/InlineCompiler.js +14 -5
- package/lib/InlineCompiler.js.map +1 -1
- package/lib/Internal.d.ts +2 -1
- package/lib/Internal.d.ts.map +1 -1
- package/lib/Internal.js +12 -10
- package/lib/Internal.js.map +1 -1
- package/lib/Modifiers.d.ts +1 -1
- package/lib/Modifiers.js +2 -1
- package/lib/Modifiers.js.map +1 -1
- package/lib/index.d.ts +5 -5
- package/lib/index.js +19 -7
- package/lib/index.js.map +1 -1
- package/lib/langs/JavaScript.d.ts +2 -2
- package/lib/langs/JavaScript.d.ts.map +1 -1
- package/lib/langs/JavaScript.js +30 -23
- package/lib/langs/JavaScript.js.map +1 -1
- package/package.json +18 -13
- package/src/{samples → examples}/quick-start.ts +22 -12
- package/src/lib/BuiltInTypeCompiler.ts +171 -171
- package/src/lib/BuiltInTypes.ts +36 -36
- package/src/lib/Common.ts +15 -10
- package/src/lib/Compiler.ts +213 -208
- package/src/lib/Context.ts +3 -3
- package/src/lib/FilterCompiler.ts +84 -84
- package/src/lib/InlineCompiler.ts +35 -14
- package/src/lib/Internal.ts +12 -10
- package/src/lib/Modifiers.ts +2 -2
- package/src/lib/index.ts +5 -5
- package/src/lib/langs/JavaScript.ts +34 -24
- package/src/test/00-all.ts +11 -9
- package/src/test/01-elemental-types.ts +1111 -1110
- package/src/test/02-array-and-list.ts +75 -75
- package/src/test/03-tuple.ts +87 -87
- package/src/test/04-from-string.ts +849 -848
- package/src/test/05-string-asserts.ts +422 -422
- package/src/test/06-structure.ts +107 -107
- package/src/test/07-modifiers.ts +151 -42
- package/src/test/08-map-and-dict.ts +46 -46
- package/src/test/09-exceptions.ts +67 -0
- package/src/test/abstracts.ts +52 -43
- package/dist/typeguard.amd.d.ts +0 -588
- package/dist/typeguard.amd.d.ts.map +0 -1
- package/dist/typeguard.amd.js +0 -2063
- package/dist/typeguard.amd.js.map +0 -1
- package/dist/typeguard.system.d.ts +0 -588
- package/dist/typeguard.system.d.ts.map +0 -1
- package/dist/typeguard.system.js +0 -2179
- package/dist/typeguard.system.js.map +0 -1
- package/tsconfig-amd.json +0 -72
- package/tsconfig-systemjs.json +0 -72
package/src/test/06-structure.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2022 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,259 +14,259 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { createTestDefinition, defaultItemss, ITestSuite } from
|
|
17
|
+
import { createTestDefinition, defaultItemss, ITestSuite } from './abstracts';
|
|
18
18
|
|
|
19
19
|
const testItems: ITestSuite = {
|
|
20
20
|
|
|
21
|
-
name:
|
|
21
|
+
name: 'Structure',
|
|
22
22
|
sections: [
|
|
23
23
|
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
'name': 'Empty object',
|
|
26
|
+
'rule': {},
|
|
27
|
+
'items': [
|
|
28
28
|
{
|
|
29
|
-
inputName:
|
|
29
|
+
inputName: 'Empty object',
|
|
30
30
|
inputValue: {},
|
|
31
31
|
expect: true
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
inputName:
|
|
35
|
-
inputValue: {
|
|
34
|
+
inputName: 'Object with one property',
|
|
35
|
+
inputValue: { 'a': 123 },
|
|
36
36
|
expect: true
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
|
-
inputName:
|
|
40
|
-
inputValue: [123,
|
|
39
|
+
inputName: '[int, string]',
|
|
40
|
+
inputValue: [123, 'fff'],
|
|
41
41
|
expect: false
|
|
42
42
|
},
|
|
43
43
|
...defaultItemss({
|
|
44
|
-
|
|
44
|
+
'object': true
|
|
45
45
|
})
|
|
46
46
|
]
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
'name': '1 property object',
|
|
50
|
+
'rule': { 'a': 'uint32' },
|
|
51
|
+
'items': [
|
|
52
52
|
{
|
|
53
|
-
inputName:
|
|
53
|
+
inputName: 'Empty object',
|
|
54
54
|
inputValue: {},
|
|
55
55
|
expect: false
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
inputName:
|
|
59
|
-
inputValue: {
|
|
58
|
+
inputName: 'Object with one property',
|
|
59
|
+
inputValue: { 'a': 123 },
|
|
60
60
|
expect: true
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
inputName:
|
|
64
|
-
inputValue: [123,
|
|
63
|
+
inputName: '[int, string]',
|
|
64
|
+
inputValue: [123, 'fff'],
|
|
65
65
|
expect: false
|
|
66
66
|
},
|
|
67
67
|
...defaultItemss({
|
|
68
|
-
|
|
68
|
+
'object': false
|
|
69
69
|
})
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
'name': '1 optional property object',
|
|
74
|
+
'rule': { 'a?': 'uint32' },
|
|
75
|
+
'items': [
|
|
76
76
|
{
|
|
77
|
-
inputName:
|
|
77
|
+
inputName: 'Empty object',
|
|
78
78
|
inputValue: {},
|
|
79
79
|
expect: true
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
inputName:
|
|
83
|
-
inputValue: {
|
|
82
|
+
inputName: 'Object with one property',
|
|
83
|
+
inputValue: { 'a': 123 },
|
|
84
84
|
expect: true
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
inputName:
|
|
88
|
-
inputValue: {
|
|
87
|
+
inputName: 'Object with one mismatch-type property',
|
|
88
|
+
inputValue: { 'a': '123' },
|
|
89
89
|
expect: false
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
|
-
inputName:
|
|
93
|
-
inputValue: [123,
|
|
92
|
+
inputName: '[int, string]',
|
|
93
|
+
inputValue: [123, 'fff'],
|
|
94
94
|
expect: false
|
|
95
95
|
},
|
|
96
96
|
...defaultItemss({
|
|
97
|
-
|
|
97
|
+
'object': true
|
|
98
98
|
})
|
|
99
99
|
]
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
'name': 'Nested object',
|
|
103
|
+
'rule': { 'a?': 'uint32', 'b': { 'c': 'string' } },
|
|
104
|
+
'items': [
|
|
105
105
|
{
|
|
106
|
-
inputName:
|
|
106
|
+
inputName: 'Empty object',
|
|
107
107
|
inputValue: {},
|
|
108
108
|
expect: false
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
|
-
inputName:
|
|
112
|
-
inputValue: {
|
|
111
|
+
inputName: 'Object with one property',
|
|
112
|
+
inputValue: { 'a': 123 },
|
|
113
113
|
expect: false
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
inputName:
|
|
117
|
-
inputValue: {
|
|
116
|
+
inputName: 'Object with mismatch-typed nest property',
|
|
117
|
+
inputValue: { 'a': 123, 'b': { 'c': 1232131 } },
|
|
118
118
|
expect: false
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
|
-
inputName:
|
|
122
|
-
inputValue: {
|
|
121
|
+
inputName: 'Object with one mismatch-typed property',
|
|
122
|
+
inputValue: { 'a': '123', 'b': { 'c': 'ffff' } },
|
|
123
123
|
expect: false
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
|
-
inputName:
|
|
127
|
-
inputValue: {
|
|
126
|
+
inputName: 'Object with all corrected',
|
|
127
|
+
inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
128
128
|
expect: true
|
|
129
129
|
}
|
|
130
130
|
]
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
'name': 'Strict object',
|
|
134
|
+
'rule': ['$.strict', {
|
|
135
|
+
'a': 'uint'
|
|
136
136
|
}],
|
|
137
|
-
|
|
137
|
+
'items': [
|
|
138
138
|
{
|
|
139
|
-
inputName:
|
|
139
|
+
inputName: 'Empty object',
|
|
140
140
|
inputValue: {},
|
|
141
141
|
expect: false
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
|
-
inputName:
|
|
145
|
-
inputValue: {
|
|
144
|
+
inputName: 'Object with one property',
|
|
145
|
+
inputValue: { 'a': 123 },
|
|
146
146
|
expect: true
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
|
-
inputName:
|
|
150
|
-
inputValue: {
|
|
149
|
+
inputName: 'Object with one mismatch-typed property',
|
|
150
|
+
inputValue: { 'a': '123' },
|
|
151
151
|
expect: false
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
|
-
inputName:
|
|
155
|
-
inputValue: {
|
|
154
|
+
inputName: 'Object with 2 properties',
|
|
155
|
+
inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
156
156
|
expect: false
|
|
157
157
|
}
|
|
158
158
|
]
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
'name': 'Strict object with nested properties',
|
|
162
|
+
'rule': ['$.strict', {
|
|
163
|
+
'a': 'uint',
|
|
164
|
+
'b': {
|
|
165
|
+
'c': 'uint'
|
|
166
166
|
}
|
|
167
167
|
}],
|
|
168
|
-
|
|
168
|
+
'items': [
|
|
169
169
|
{
|
|
170
|
-
inputName:
|
|
171
|
-
inputValue: {
|
|
170
|
+
inputName: 'Object with one property',
|
|
171
|
+
inputValue: { 'a': 123 },
|
|
172
172
|
expect: false
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
|
-
inputName:
|
|
176
|
-
inputValue: {
|
|
175
|
+
inputName: 'Object with wrong type in nest',
|
|
176
|
+
inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
177
177
|
expect: false
|
|
178
178
|
},
|
|
179
179
|
{
|
|
180
|
-
inputName:
|
|
181
|
-
inputValue: {
|
|
180
|
+
inputName: 'Object with all correct',
|
|
181
|
+
inputValue: { 'a': 123, 'b': { 'c': 123 } },
|
|
182
182
|
expect: true
|
|
183
183
|
},
|
|
184
184
|
{
|
|
185
|
-
inputName:
|
|
186
|
-
inputValue: {
|
|
185
|
+
inputName: 'Object with one more in nested',
|
|
186
|
+
inputValue: { 'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
|
|
187
187
|
expect: true
|
|
188
188
|
}
|
|
189
189
|
]
|
|
190
190
|
},
|
|
191
191
|
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
'name': 'Recursively-Strict object with nested properties',
|
|
193
|
+
'rule': ['$.equal', {
|
|
194
|
+
'a': 'uint',
|
|
195
|
+
'b': {
|
|
196
|
+
'c': 'uint'
|
|
197
197
|
}
|
|
198
198
|
}],
|
|
199
|
-
|
|
199
|
+
'items': [
|
|
200
200
|
{
|
|
201
|
-
inputName:
|
|
202
|
-
inputValue: {
|
|
201
|
+
inputName: 'Object with one property',
|
|
202
|
+
inputValue: { 'a': 123 },
|
|
203
203
|
expect: false
|
|
204
204
|
},
|
|
205
205
|
{
|
|
206
|
-
inputName:
|
|
207
|
-
inputValue: {
|
|
206
|
+
inputName: 'Object with wrong type in nest',
|
|
207
|
+
inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
|
|
208
208
|
expect: false
|
|
209
209
|
},
|
|
210
210
|
{
|
|
211
|
-
inputName:
|
|
212
|
-
inputValue: {
|
|
211
|
+
inputName: 'Object with all correct',
|
|
212
|
+
inputValue: { 'a': 123, 'b': { 'c': 123 } },
|
|
213
213
|
expect: true
|
|
214
214
|
},
|
|
215
215
|
{
|
|
216
|
-
inputName:
|
|
217
|
-
inputValue: {
|
|
216
|
+
inputName: 'Object with one more in nested',
|
|
217
|
+
inputValue: { 'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
|
|
218
218
|
expect: false
|
|
219
219
|
}
|
|
220
220
|
]
|
|
221
221
|
},
|
|
222
222
|
{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
'name': 'Object with from-string modifier',
|
|
224
|
+
'rule': ['$.string', {
|
|
225
|
+
'a': 'uint',
|
|
226
|
+
'b': {
|
|
227
|
+
'c': 'uint'
|
|
228
228
|
}
|
|
229
229
|
}],
|
|
230
|
-
|
|
230
|
+
'items': [
|
|
231
231
|
{
|
|
232
|
-
inputName:
|
|
233
|
-
inputValue: {
|
|
232
|
+
inputName: 'Object with all correct',
|
|
233
|
+
inputValue: { 'a': 123, 'b': { 'c': 123 } },
|
|
234
234
|
expect: true
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
|
-
inputName:
|
|
238
|
-
inputValue: {
|
|
237
|
+
inputName: 'Object with string incorrect-value',
|
|
238
|
+
inputValue: { 'a': 123, 'b': { 'c': '123d' } },
|
|
239
239
|
expect: false
|
|
240
240
|
},
|
|
241
241
|
{
|
|
242
|
-
inputName:
|
|
243
|
-
inputValue: {
|
|
242
|
+
inputName: 'Object with string value',
|
|
243
|
+
inputValue: { 'a': '123312312', 'b': { 'c': '123' } },
|
|
244
244
|
expect: true
|
|
245
245
|
}
|
|
246
246
|
]
|
|
247
247
|
},
|
|
248
248
|
{
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
'name': 'Object with from-string modifier',
|
|
250
|
+
'rule': ['$.string', {
|
|
251
|
+
'a': 'uint',
|
|
252
|
+
'b': {
|
|
253
|
+
'c': 'uint'
|
|
254
254
|
}
|
|
255
255
|
}],
|
|
256
|
-
|
|
256
|
+
'items': [
|
|
257
257
|
{
|
|
258
|
-
inputName:
|
|
259
|
-
inputValue: {
|
|
258
|
+
inputName: 'Object with all correct',
|
|
259
|
+
inputValue: { 'a': 123, 'b': { 'c': 123 } },
|
|
260
260
|
expect: true
|
|
261
261
|
},
|
|
262
262
|
{
|
|
263
|
-
inputName:
|
|
264
|
-
inputValue: {
|
|
263
|
+
inputName: 'Object with string incorrect-value',
|
|
264
|
+
inputValue: { 'a': 123, 'b': { 'c': '123d' } },
|
|
265
265
|
expect: false
|
|
266
266
|
},
|
|
267
267
|
{
|
|
268
|
-
inputName:
|
|
269
|
-
inputValue: {
|
|
268
|
+
inputName: 'Object with string value',
|
|
269
|
+
inputValue: { 'a': '123312312', 'b': { 'c': '123' } },
|
|
270
270
|
expect: true
|
|
271
271
|
}
|
|
272
272
|
]
|
package/src/test/07-modifiers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2022 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,97 +14,206 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { createTestDefinition, defaultItemss, ITestSuite } from
|
|
17
|
+
import { createTestDefinition, defaultItemss, ITestSuite } from './abstracts';
|
|
18
18
|
|
|
19
19
|
const testItems: ITestSuite = {
|
|
20
20
|
|
|
21
|
-
name:
|
|
21
|
+
name: 'Modifiers',
|
|
22
22
|
sections: [
|
|
23
23
|
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
'name': '$.string',
|
|
26
|
+
'rule': ['$.string', 'uint32', { 'a': 'uint32' }],
|
|
27
|
+
'items': [
|
|
28
28
|
{
|
|
29
|
-
inputName: JSON.stringify(
|
|
30
|
-
inputValue:
|
|
29
|
+
inputName: JSON.stringify('123'),
|
|
30
|
+
inputValue: '123',
|
|
31
31
|
expect: true
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
inputName: JSON.stringify({
|
|
35
|
-
inputValue: {
|
|
34
|
+
inputName: JSON.stringify({ 'a': 123 }),
|
|
35
|
+
inputValue: { 'a': 123 },
|
|
36
36
|
expect: true
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
|
-
inputName: JSON.stringify({
|
|
40
|
-
inputValue: {
|
|
39
|
+
inputName: JSON.stringify({ 'a': 123 }),
|
|
40
|
+
inputValue: { 'a': 123 },
|
|
41
41
|
expect: true
|
|
42
42
|
},
|
|
43
43
|
...defaultItemss({
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
'number 1': true,
|
|
45
|
+
'number 0': true
|
|
46
46
|
})
|
|
47
47
|
]
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
'name': '$.string standalone',
|
|
51
|
+
'rule': ['$.and', ['$.string', 'uint32'], 'uint32'],
|
|
52
|
+
'items': [
|
|
53
53
|
{
|
|
54
|
-
inputName: JSON.stringify(
|
|
55
|
-
inputValue:
|
|
54
|
+
inputName: JSON.stringify('123'),
|
|
55
|
+
inputValue: '123',
|
|
56
56
|
expect: false
|
|
57
57
|
}
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
'name': '$.strict standalone',
|
|
62
|
+
'rule': ['$.tuple', ['$.strict', {
|
|
63
|
+
'a': 'string'
|
|
64
64
|
}], {
|
|
65
|
-
|
|
65
|
+
'a': 'string'
|
|
66
66
|
}],
|
|
67
|
-
|
|
67
|
+
'items': [
|
|
68
68
|
{
|
|
69
|
-
inputName: JSON.stringify([{
|
|
70
|
-
inputValue: [{
|
|
69
|
+
inputName: JSON.stringify([{ 'a': 'x' }, { 'a': 'c', 'b': 'x' }]),
|
|
70
|
+
inputValue: [{ 'a': 'x' }, { 'a': 'c', 'b': 'x' }],
|
|
71
71
|
expect: true
|
|
72
72
|
}
|
|
73
73
|
]
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
'name': '$.equal standalone',
|
|
77
|
+
'rule': ['$.and', ['$.equal', {
|
|
78
|
+
'a': 'any'
|
|
79
79
|
}], {
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
'a': {
|
|
81
|
+
'b': 'string'
|
|
82
82
|
}
|
|
83
83
|
}],
|
|
84
|
-
|
|
84
|
+
'items': [
|
|
85
85
|
{
|
|
86
|
-
inputName: JSON.stringify({
|
|
87
|
-
inputValue: {
|
|
86
|
+
inputName: JSON.stringify({ 'a': { 'b': 'c', 'd': 'ccc' } }),
|
|
87
|
+
inputValue: { 'a': { 'b': 'c', 'd': 'ccc' } },
|
|
88
88
|
expect: true
|
|
89
89
|
}
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
'name': '$.not with string and literal 0',
|
|
94
|
+
'rule': ['$.not', 'string', 0],
|
|
95
|
+
'items': [
|
|
96
96
|
{
|
|
97
|
-
inputName:
|
|
98
|
-
inputValue:
|
|
97
|
+
inputName: 'string \'abc\'',
|
|
98
|
+
inputValue: 'abc',
|
|
99
99
|
expect: false
|
|
100
100
|
},
|
|
101
101
|
...defaultItemss({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
'string \'hello\'': false,
|
|
103
|
+
'empty string': false,
|
|
104
|
+
'number 0': false
|
|
105
105
|
}, true)
|
|
106
106
|
]
|
|
107
107
|
},
|
|
108
|
+
{
|
|
109
|
+
'name': '$.type ',
|
|
110
|
+
'rule': {
|
|
111
|
+
'a': ['$.type', 'test:a.b-c', 'int'],
|
|
112
|
+
'b': '@test:a.b-c',
|
|
113
|
+
},
|
|
114
|
+
'items': [
|
|
115
|
+
{
|
|
116
|
+
inputName: 'object {a: 213, b: 321}',
|
|
117
|
+
inputValue: {
|
|
118
|
+
'a': 213,
|
|
119
|
+
'b': 321
|
|
120
|
+
},
|
|
121
|
+
expect: true
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
inputName: 'object {a: 213, b: "321"}',
|
|
125
|
+
inputValue: {
|
|
126
|
+
'a': 213,
|
|
127
|
+
'b': '321'
|
|
128
|
+
},
|
|
129
|
+
expect: false
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
inputName: 'object {a: 213, b: "321"}',
|
|
133
|
+
inputValue: {
|
|
134
|
+
'a': 213,
|
|
135
|
+
'b': 777
|
|
136
|
+
},
|
|
137
|
+
expect: true
|
|
138
|
+
},
|
|
139
|
+
...defaultItemss({}, false)
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
'name': 'Pre-defined IPv4 Address Checker',
|
|
144
|
+
'rule': '@ipv4_address',
|
|
145
|
+
'items': [
|
|
146
|
+
{
|
|
147
|
+
inputName: 'String: 1.1.1.1',
|
|
148
|
+
inputValue: '1.1.1.1',
|
|
149
|
+
expect: true
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
inputName: 'String: 255.255.255.255',
|
|
153
|
+
inputValue: '255.255.255.255',
|
|
154
|
+
expect: true
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
inputName: 'String: 0.0.0.0',
|
|
158
|
+
inputValue: '0.0.0.0',
|
|
159
|
+
expect: true
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
inputName: 'String: 2552.1.1.1',
|
|
163
|
+
inputValue: '2552.1.1.1',
|
|
164
|
+
expect: false
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
inputName: 'String: 256.1.1.1',
|
|
168
|
+
inputValue: '256.1.1.1',
|
|
169
|
+
expect: false
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
inputName: 'String: .1.1.1',
|
|
173
|
+
inputValue: '.1.1.1',
|
|
174
|
+
expect: false
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
inputName: 'object {a: 213, b: 321}',
|
|
178
|
+
inputValue: {
|
|
179
|
+
'a': 213,
|
|
180
|
+
'b': 321
|
|
181
|
+
},
|
|
182
|
+
expect: false
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
inputName: 'object {a: 213, b: "321"}',
|
|
186
|
+
inputValue: {
|
|
187
|
+
'a': 213,
|
|
188
|
+
'b': '321'
|
|
189
|
+
},
|
|
190
|
+
expect: false
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
inputName: 'object {a: 213, b: "321"}',
|
|
194
|
+
inputValue: {
|
|
195
|
+
'a': 213,
|
|
196
|
+
'b': 777
|
|
197
|
+
},
|
|
198
|
+
expect: false
|
|
199
|
+
},
|
|
200
|
+
...defaultItemss({}, false)
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
'name': '$.type with unsupported characters in type name',
|
|
205
|
+
'rule': {
|
|
206
|
+
'a': ['$.type', 'test=123', 'int'],
|
|
207
|
+
'b': '@test:a',
|
|
208
|
+
},
|
|
209
|
+
'items': [
|
|
210
|
+
{
|
|
211
|
+
inputName: 'invalid format',
|
|
212
|
+
inputValue: '',
|
|
213
|
+
expect: 'throw'
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
},
|
|
108
217
|
]
|
|
109
218
|
};
|
|
110
219
|
|