@litert/typeguard 1.1.0 → 1.3.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.
Files changed (63) hide show
  1. package/CHANGES.md +10 -0
  2. package/lib/BuiltInTypeCompiler.d.ts +2 -2
  3. package/lib/BuiltInTypeCompiler.d.ts.map +1 -1
  4. package/lib/BuiltInTypeCompiler.js +1 -1
  5. package/lib/BuiltInTypeCompiler.js.map +1 -1
  6. package/lib/BuiltInTypes.d.ts +1 -1
  7. package/lib/BuiltInTypes.js +1 -1
  8. package/lib/Common.d.ts +19 -2
  9. package/lib/Common.d.ts.map +1 -1
  10. package/lib/Common.js +1 -1
  11. package/lib/Compiler.d.ts +1 -1
  12. package/lib/Compiler.d.ts.map +1 -1
  13. package/lib/Compiler.js +93 -39
  14. package/lib/Compiler.js.map +1 -1
  15. package/lib/Context.d.ts +5 -4
  16. package/lib/Context.d.ts.map +1 -1
  17. package/lib/Context.js +9 -6
  18. package/lib/Context.js.map +1 -1
  19. package/lib/FilterCompiler.d.ts +3 -3
  20. package/lib/FilterCompiler.d.ts.map +1 -1
  21. package/lib/FilterCompiler.js +2 -2
  22. package/lib/FilterCompiler.js.map +1 -1
  23. package/lib/InlineCompiler.d.ts +10 -3
  24. package/lib/InlineCompiler.d.ts.map +1 -1
  25. package/lib/InlineCompiler.js +16 -5
  26. package/lib/InlineCompiler.js.map +1 -1
  27. package/lib/Internal.d.ts +6 -4
  28. package/lib/Internal.d.ts.map +1 -1
  29. package/lib/Internal.js +3 -2
  30. package/lib/Internal.js.map +1 -1
  31. package/lib/Modifiers.d.ts +1 -1
  32. package/lib/Modifiers.js +1 -1
  33. package/lib/index.d.ts +1 -1
  34. package/lib/index.js +6 -2
  35. package/lib/index.js.map +1 -1
  36. package/lib/langs/JavaScript.d.ts +1 -1
  37. package/lib/langs/JavaScript.d.ts.map +1 -1
  38. package/lib/langs/JavaScript.js +29 -4
  39. package/lib/langs/JavaScript.js.map +1 -1
  40. package/package.json +12 -12
  41. package/src/examples/quick-start.ts +118 -2
  42. package/src/lib/BuiltInTypeCompiler.ts +2 -2
  43. package/src/lib/BuiltInTypes.ts +1 -1
  44. package/src/lib/Common.ts +41 -2
  45. package/src/lib/Compiler.ts +155 -50
  46. package/src/lib/Context.ts +9 -11
  47. package/src/lib/FilterCompiler.ts +4 -4
  48. package/src/lib/InlineCompiler.ts +36 -10
  49. package/src/lib/Internal.ts +8 -4
  50. package/src/lib/Modifiers.ts +1 -1
  51. package/src/lib/index.ts +1 -1
  52. package/src/lib/langs/JavaScript.ts +58 -5
  53. package/src/test/00-all.ts +1 -1
  54. package/src/test/01-elemental-types.ts +2 -1
  55. package/src/test/02-array-and-list.ts +18 -18
  56. package/src/test/03-tuple.ts +1 -1
  57. package/src/test/04-from-string.ts +2 -1
  58. package/src/test/05-string-asserts.ts +1 -1
  59. package/src/test/06-structure.ts +26 -26
  60. package/src/test/07-modifiers.ts +71 -10
  61. package/src/test/08-map-and-dict.ts +20 -20
  62. package/src/test/09-exceptions.ts +4 -4
  63. package/src/test/abstracts.ts +45 -7
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
package/src/lib/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -192,7 +192,7 @@ implements C.ILanguageBuilder {
192
192
  regExp: string
193
193
  ): string {
194
194
 
195
- let m = /^\/(.+)\/([a-z]*)$/i.exec(regExp);
195
+ const m = /^\/(.+)\/([a-z]*)$/i.exec(regExp);
196
196
 
197
197
  if (m) {
198
198
 
@@ -289,12 +289,14 @@ implements C.ILanguageBuilder {
289
289
  }
290
290
 
291
291
  public forEach(
292
- an: string,
293
- it: string,
292
+ arrVar: string,
293
+ elVar: string,
294
+ iterVar: string,
294
295
  body: string
295
296
  ): string {
296
297
 
297
- return `for (const ${it} of ${an}) {
298
+ return `for (let ${elVar} = 0; ${elVar} < ${arrVar}.length; ${elVar}++) {
299
+ const ${iterVar} = ${arrVar}[${elVar}];
298
300
  ${body}
299
301
  }`;
300
302
  }
@@ -424,6 +426,57 @@ implements C.ILanguageBuilder {
424
426
  args.join(', ')
425
427
  })`;
426
428
  }
429
+
430
+ public escape(str: string): string {
431
+
432
+ return str.replace(/(['"])/g, '\\$1').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
433
+ }
434
+
435
+ public stringTemplateVar(varExpr: string): string {
436
+
437
+ return `"\${${varExpr}.replace(/(['"])/g, '\\\\$1').replace(/\\n/g, '\\\\n').replace(/\\r/g, '\\\\r')}"`;
438
+ }
439
+
440
+ public numberTemplateVar(varExpr: string): string {
441
+
442
+ return `\${${varExpr}}`;
443
+ }
444
+
445
+ public addTrace(
446
+ vTrace: string,
447
+ vTraceStack: string,
448
+ path: string,
449
+ negative: boolean = false
450
+ ): string {
451
+
452
+ if (negative) {
453
+
454
+ return `(${vTrace}.push(\`\${${vTraceStack}}${path}\`), true)`;
455
+ }
456
+
457
+ return `(${vTrace}.push(\`\${${vTraceStack}}${path}\`), false)`;
458
+ }
459
+
460
+ public add(a: string | number, b: string | number): string {
461
+
462
+ return `${a} + ${b}`;
463
+ }
464
+
465
+ public orAddTrace(
466
+ expr: string,
467
+ vTrace: string,
468
+ vTraceStack: string,
469
+ path: string,
470
+ negative: boolean = false
471
+ ): string {
472
+
473
+ if (negative) {
474
+
475
+ return `((${expr}) && (${vTrace}.push(\`\${${vTraceStack}}${path}\`), true))`;
476
+ }
477
+
478
+ return `((${expr}) || (${vTrace}.push(\`\${${vTraceStack}}${path}\`), false))`;
479
+ }
427
480
  }
428
481
 
429
482
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -1,5 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/no-loss-of-precision */
1
2
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
3
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
4
  *
4
5
  * Licensed under the Apache License, Version 2.0 (the "License");
5
6
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -158,38 +158,38 @@ const testItems: ITestSuite = {
158
158
  'a->[]': 'string'
159
159
  }, [
160
160
  assertItem([], false),
161
- assertItem({'a': []}, true),
162
- assertItem({'a': [1]}, false),
163
- assertItem({'a': ['1']}, true)
161
+ assertItem({ 'a': [] }, true),
162
+ assertItem({ 'a': [1] }, false),
163
+ assertItem({ 'a': ['1'] }, true)
164
164
  ]),
165
165
  addRule({
166
166
  'a->[3]': 'string'
167
167
  }, [
168
168
  assertItem([], false),
169
- assertItem({'a': []}, false),
170
- assertItem({'a': [1, 1, 2]}, false),
171
- assertItem({'a': ['1', 'f', 'c']}, true),
172
- assertItem({'a': ['1', 'f', 'c', 'c']}, false)
169
+ assertItem({ 'a': [] }, false),
170
+ assertItem({ 'a': [1, 1, 2] }, false),
171
+ assertItem({ 'a': ['1', 'f', 'c'] }, true),
172
+ assertItem({ 'a': ['1', 'f', 'c', 'c'] }, false)
173
173
  ]),
174
174
  addRule({
175
175
  'a->[3,]': 'string'
176
176
  }, [
177
177
  assertItem([], false),
178
- assertItem({'a': []}, false),
179
- assertItem({'a': [1, 1, 2]}, false),
180
- assertItem({'a': ['1', 'f', 'c']}, true),
181
- assertItem({'a': ['1', 'f', 'c', 'c']}, true)
178
+ assertItem({ 'a': [] }, false),
179
+ assertItem({ 'a': [1, 1, 2] }, false),
180
+ assertItem({ 'a': ['1', 'f', 'c'] }, true),
181
+ assertItem({ 'a': ['1', 'f', 'c', 'c'] }, true)
182
182
  ]),
183
183
  addRule({
184
184
  'a->[3,5]': 'string'
185
185
  }, [
186
186
  assertItem([], false),
187
- assertItem({'a': []}, false),
188
- assertItem({'a': [1, 1, 2]}, false),
189
- assertItem({'a': ['1', 'f', 'c']}, true),
190
- assertItem({'a': ['1', 'f', 'c', 'c']}, true),
191
- assertItem({'a': ['1', 'f', 'c', 'c', '5']}, true),
192
- assertItem({'a': ['1', 'f', 'c', 'c', '5', 'c']}, false)
187
+ assertItem({ 'a': [] }, false),
188
+ assertItem({ 'a': [1, 1, 2] }, false),
189
+ assertItem({ 'a': ['1', 'f', 'c'] }, true),
190
+ assertItem({ 'a': ['1', 'f', 'c', 'c'] }, true),
191
+ assertItem({ 'a': ['1', 'f', 'c', 'c', '5'] }, true),
192
+ assertItem({ 'a': ['1', 'f', 'c', 'c', '5', 'c'] }, false)
193
193
  ])
194
194
  ],
195
195
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -1,5 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/no-loss-of-precision */
1
2
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
3
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
4
  *
4
5
  * Licensed under the Apache License, Version 2.0 (the "License");
5
6
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -32,7 +32,7 @@ const testItems: ITestSuite = {
32
32
  },
33
33
  {
34
34
  inputName: 'Object with one property',
35
- inputValue: {'a': 123},
35
+ inputValue: { 'a': 123 },
36
36
  expect: true
37
37
  },
38
38
  {
@@ -56,7 +56,7 @@ const testItems: ITestSuite = {
56
56
  },
57
57
  {
58
58
  inputName: 'Object with one property',
59
- inputValue: {'a': 123},
59
+ inputValue: { 'a': 123 },
60
60
  expect: true
61
61
  },
62
62
  {
@@ -80,12 +80,12 @@ const testItems: ITestSuite = {
80
80
  },
81
81
  {
82
82
  inputName: 'Object with one property',
83
- inputValue: {'a': 123},
83
+ inputValue: { 'a': 123 },
84
84
  expect: true
85
85
  },
86
86
  {
87
87
  inputName: 'Object with one mismatch-type property',
88
- inputValue: {'a': '123'},
88
+ inputValue: { 'a': '123' },
89
89
  expect: false
90
90
  },
91
91
  {
@@ -109,22 +109,22 @@ const testItems: ITestSuite = {
109
109
  },
110
110
  {
111
111
  inputName: 'Object with one property',
112
- inputValue: {'a': 123},
112
+ inputValue: { 'a': 123 },
113
113
  expect: false
114
114
  },
115
115
  {
116
116
  inputName: 'Object with mismatch-typed nest property',
117
- inputValue: {'a': 123, 'b': { 'c': 1232131 }},
117
+ inputValue: { 'a': 123, 'b': { 'c': 1232131 } },
118
118
  expect: false
119
119
  },
120
120
  {
121
121
  inputName: 'Object with one mismatch-typed property',
122
- inputValue: {'a': '123', 'b': { 'c': 'ffff'} },
122
+ inputValue: { 'a': '123', 'b': { 'c': 'ffff' } },
123
123
  expect: false
124
124
  },
125
125
  {
126
126
  inputName: 'Object with all corrected',
127
- inputValue: {'a': 123, 'b': { 'c': 'ffff'} },
127
+ inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
128
128
  expect: true
129
129
  }
130
130
  ]
@@ -142,17 +142,17 @@ const testItems: ITestSuite = {
142
142
  },
143
143
  {
144
144
  inputName: 'Object with one property',
145
- inputValue: {'a': 123},
145
+ inputValue: { 'a': 123 },
146
146
  expect: true
147
147
  },
148
148
  {
149
149
  inputName: 'Object with one mismatch-typed property',
150
- inputValue: {'a': '123' },
150
+ inputValue: { 'a': '123' },
151
151
  expect: false
152
152
  },
153
153
  {
154
154
  inputName: 'Object with 2 properties',
155
- inputValue: {'a': 123, 'b': { 'c': 'ffff'} },
155
+ inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
156
156
  expect: false
157
157
  }
158
158
  ]
@@ -168,22 +168,22 @@ const testItems: ITestSuite = {
168
168
  'items': [
169
169
  {
170
170
  inputName: 'Object with one property',
171
- inputValue: {'a': 123},
171
+ inputValue: { 'a': 123 },
172
172
  expect: false
173
173
  },
174
174
  {
175
175
  inputName: 'Object with wrong type in nest',
176
- inputValue: {'a': 123, 'b': { 'c': 'ffff'} },
176
+ inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
177
177
  expect: false
178
178
  },
179
179
  {
180
180
  inputName: 'Object with all correct',
181
- inputValue: {'a': 123, 'b': { 'c': 123 } },
181
+ inputValue: { 'a': 123, 'b': { 'c': 123 } },
182
182
  expect: true
183
183
  },
184
184
  {
185
185
  inputName: 'Object with one more in nested',
186
- inputValue: {'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
186
+ inputValue: { 'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
187
187
  expect: true
188
188
  }
189
189
  ]
@@ -199,22 +199,22 @@ const testItems: ITestSuite = {
199
199
  'items': [
200
200
  {
201
201
  inputName: 'Object with one property',
202
- inputValue: {'a': 123},
202
+ inputValue: { 'a': 123 },
203
203
  expect: false
204
204
  },
205
205
  {
206
206
  inputName: 'Object with wrong type in nest',
207
- inputValue: {'a': 123, 'b': { 'c': 'ffff'} },
207
+ inputValue: { 'a': 123, 'b': { 'c': 'ffff' } },
208
208
  expect: false
209
209
  },
210
210
  {
211
211
  inputName: 'Object with all correct',
212
- inputValue: {'a': 123, 'b': { 'c': 123 } },
212
+ inputValue: { 'a': 123, 'b': { 'c': 123 } },
213
213
  expect: true
214
214
  },
215
215
  {
216
216
  inputName: 'Object with one more in nested',
217
- inputValue: {'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
217
+ inputValue: { 'a': 123, 'b': { 'c': 123, 'd': '1213131' } },
218
218
  expect: false
219
219
  }
220
220
  ]
@@ -230,17 +230,17 @@ const testItems: ITestSuite = {
230
230
  'items': [
231
231
  {
232
232
  inputName: 'Object with all correct',
233
- inputValue: {'a': 123, 'b': { 'c': 123 } },
233
+ inputValue: { 'a': 123, 'b': { 'c': 123 } },
234
234
  expect: true
235
235
  },
236
236
  {
237
237
  inputName: 'Object with string incorrect-value',
238
- inputValue: {'a': 123, 'b': { 'c': '123d' } },
238
+ inputValue: { 'a': 123, 'b': { 'c': '123d' } },
239
239
  expect: false
240
240
  },
241
241
  {
242
242
  inputName: 'Object with string value',
243
- inputValue: {'a': '123312312', 'b': { 'c': '123' } },
243
+ inputValue: { 'a': '123312312', 'b': { 'c': '123' } },
244
244
  expect: true
245
245
  }
246
246
  ]
@@ -256,17 +256,17 @@ const testItems: ITestSuite = {
256
256
  'items': [
257
257
  {
258
258
  inputName: 'Object with all correct',
259
- inputValue: {'a': 123, 'b': { 'c': 123 } },
259
+ inputValue: { 'a': 123, 'b': { 'c': 123 } },
260
260
  expect: true
261
261
  },
262
262
  {
263
263
  inputName: 'Object with string incorrect-value',
264
- inputValue: {'a': 123, 'b': { 'c': '123d' } },
264
+ inputValue: { 'a': 123, 'b': { 'c': '123d' } },
265
265
  expect: false
266
266
  },
267
267
  {
268
268
  inputName: 'Object with string value',
269
- inputValue: {'a': '123312312', 'b': { 'c': '123' } },
269
+ inputValue: { 'a': '123312312', 'b': { 'c': '123' } },
270
270
  expect: true
271
271
  }
272
272
  ]
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -23,7 +23,7 @@ const testItems: ITestSuite = {
23
23
 
24
24
  {
25
25
  'name': '$.string',
26
- 'rule': ['$.string', 'uint32', {'a': 'uint32'}],
26
+ 'rule': ['$.string', 'uint32', { 'a': 'uint32' }],
27
27
  'items': [
28
28
  {
29
29
  inputName: JSON.stringify('123'),
@@ -31,13 +31,13 @@ const testItems: ITestSuite = {
31
31
  expect: true
32
32
  },
33
33
  {
34
- inputName: JSON.stringify({'a': 123}),
35
- inputValue: {'a': 123},
34
+ inputName: JSON.stringify({ 'a': 123 }),
35
+ inputValue: { 'a': 123 },
36
36
  expect: true
37
37
  },
38
38
  {
39
- inputName: JSON.stringify({'a': 123}),
40
- inputValue: {'a': 123},
39
+ inputName: JSON.stringify({ 'a': 123 }),
40
+ inputValue: { 'a': 123 },
41
41
  expect: true
42
42
  },
43
43
  ...defaultItemss({
@@ -66,8 +66,8 @@ const testItems: ITestSuite = {
66
66
  }],
67
67
  'items': [
68
68
  {
69
- inputName: JSON.stringify([{'a': 'x'}, {'a': 'c', 'b': 'x'}]),
70
- inputValue: [{'a': 'x'}, {'a': 'c', 'b': 'x'}],
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
  ]
@@ -83,8 +83,8 @@ const testItems: ITestSuite = {
83
83
  }],
84
84
  'items': [
85
85
  {
86
- inputName: JSON.stringify({'a': {'b': 'c', 'd': 'ccc'}}),
87
- inputValue: {'a': {'b': 'c', 'd': 'ccc'}},
86
+ inputName: JSON.stringify({ 'a': { 'b': 'c', 'd': 'ccc' } }),
87
+ inputValue: { 'a': { 'b': 'c', 'd': 'ccc' } },
88
88
  expect: true
89
89
  }
90
90
  ]
@@ -139,6 +139,67 @@ const testItems: ITestSuite = {
139
139
  ...defaultItemss({}, false)
140
140
  ]
141
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
+ },
142
203
  {
143
204
  'name': '$.type with unsupported characters in type name',
144
205
  'rule': {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 Angus.Fenying <fenying@litert.org>
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.
@@ -33,22 +33,22 @@ const testItems: ITestSuite = {
33
33
  'items': [
34
34
  {
35
35
  inputName: 'all string object',
36
- inputValue: {'a': '123312312', 'b': 'ccc' },
36
+ inputValue: { 'a': '123312312', 'b': 'ccc' },
37
37
  expect: true
38
38
  },
39
39
  {
40
40
  inputName: 'all uint32 object',
41
- inputValue: {'a': 123312312, 'b': 0xCCC },
41
+ inputValue: { 'a': 123312312, 'b': 0xCCC },
42
42
  expect: true
43
43
  },
44
44
  {
45
45
  inputName: 'all uint32 & string object',
46
- inputValue: {'a': 123312312, 'b': 0xCCC },
46
+ inputValue: { 'a': 123312312, 'b': 0xCCC },
47
47
  expect: true
48
48
  },
49
49
  {
50
50
  inputName: 'all uint32 & boolean object',
51
- inputValue: {'a': 123312312, 'b': false },
51
+ inputValue: { 'a': 123312312, 'b': false },
52
52
  expect: false
53
53
  },
54
54
  ...defaultItemss({
@@ -67,15 +67,15 @@ const testItems: ITestSuite = {
67
67
  },
68
68
  'items': [
69
69
  assertItem(
70
- {'a': '123312312', 'b': 123.3, c: 1232 },
70
+ { 'a': '123312312', 'b': 123.3, c: 1232 },
71
71
  true
72
72
  ),
73
73
  assertItem(
74
- {'a': '123312312', 'b': 'ccc' },
74
+ { 'a': '123312312', 'b': 'ccc' },
75
75
  false
76
76
  ),
77
77
  assertItem(
78
- {'a': 123312312, 'b': 123.3 },
78
+ { 'a': 123312312, 'b': 123.3 },
79
79
  false
80
80
  ),
81
81
  ]
@@ -91,56 +91,56 @@ const testItems: ITestSuite = {
91
91
  },
92
92
  'items': [
93
93
  assertItem(
94
- {'a': '123312312', 'b': 'ccc' },
94
+ { 'a': '123312312', 'b': 'ccc' },
95
95
  false
96
96
  ),
97
97
  assertItem(
98
- {'a': 123312312, 'b': 123.3 },
98
+ { 'a': 123312312, 'b': 123.3 },
99
99
  false
100
100
  ),
101
101
  assertItem(
102
- {'a': '123312312', 'b': {d: 123.3, c: 1232} },
102
+ { 'a': '123312312', 'b': { d: 123.3, c: 1232 } },
103
103
  true
104
104
  ),
105
105
  assertItem(
106
- {'a': '123312312', 'b': { d: 123.3, c: '1232' } },
106
+ { 'a': '123312312', 'b': { d: 123.3, c: '1232' } },
107
107
  false
108
108
  ),
109
109
  ]
110
110
  },
111
111
  addRule(['$.dict', ['a', 'b'], 'string'], [
112
112
  assertItem(
113
- {'a': '123312312', 'b': 'ccc' },
113
+ { 'a': '123312312', 'b': 'ccc' },
114
114
  true
115
115
  ),
116
116
  assertItem(
117
- {'a': '123312312', 'b': 'ccc', 'c': 123 },
117
+ { 'a': '123312312', 'b': 'ccc', 'c': 123 },
118
118
  true
119
119
  ),
120
120
  assertItem(
121
- {'a': '123312312' },
121
+ { 'a': '123312312' },
122
122
  false
123
123
  ),
124
124
  assertItem(
125
- {'a': '123312312', 'c': 'ddd' },
125
+ { 'a': '123312312', 'c': 'ddd' },
126
126
  false
127
127
  ),
128
128
  assertItem(
129
- {'a': '123312312', 'b': 123.3 },
129
+ { 'a': '123312312', 'b': 123.3 },
130
130
  false
131
131
  )
132
132
  ]),
133
133
  addRule(['$.strict', '$.dict', ['a', 'b'], 'string'], [
134
134
  assertItem(
135
- {'a': '123312312', 'b': 'ccc' },
135
+ { 'a': '123312312', 'b': 'ccc' },
136
136
  true
137
137
  ),
138
138
  assertItem(
139
- {'a': '123312312', 'b': 'ccc', 'c': 123 },
139
+ { 'a': '123312312', 'b': 'ccc', 'c': 123 },
140
140
  false
141
141
  ),
142
142
  assertItem(
143
- {'a': '123312312' },
143
+ { 'a': '123312312' },
144
144
  false
145
145
  ),
146
146
  ])