@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
|
@@ -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.
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
18
|
createTestDefinition,
|
|
19
|
-
|
|
19
|
+
defaultItems,
|
|
20
20
|
ITestSuite,
|
|
21
21
|
assertItem,
|
|
22
22
|
addRule
|
|
@@ -32,21 +32,21 @@ const testItems: ITestSuite = {
|
|
|
32
32
|
'rule': ['$.list', 'string'],
|
|
33
33
|
'items': [
|
|
34
34
|
{
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
title: '[string]',
|
|
36
|
+
value: ['fff'],
|
|
37
37
|
expect: true
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
title: '[string,string]',
|
|
41
|
+
value: ['fff', 'ggg'],
|
|
42
42
|
expect: true
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
title: '[string,int]',
|
|
46
|
+
value: ['fff', 123],
|
|
47
47
|
expect: false
|
|
48
48
|
},
|
|
49
|
-
...
|
|
49
|
+
...defaultItems({
|
|
50
50
|
'empty array': true
|
|
51
51
|
})
|
|
52
52
|
]
|
|
@@ -56,16 +56,16 @@ const testItems: ITestSuite = {
|
|
|
56
56
|
'rule': ['$.array', 1, 'string'],
|
|
57
57
|
'items': [
|
|
58
58
|
{
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
title: '[string]',
|
|
60
|
+
value: ['fff'],
|
|
61
61
|
expect: true
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
title: '[string,string]',
|
|
65
|
+
value: ['fff', 'ggg'],
|
|
66
66
|
expect: false
|
|
67
67
|
},
|
|
68
|
-
...
|
|
68
|
+
...defaultItems({})
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
71
|
{
|
|
@@ -73,31 +73,31 @@ const testItems: ITestSuite = {
|
|
|
73
73
|
'rule': ['$.array', 2, 'string', 'int'],
|
|
74
74
|
'items': [
|
|
75
75
|
{
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
title: '[string]',
|
|
77
|
+
value: ['fff'],
|
|
78
78
|
expect: false
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
title: '[string,string]',
|
|
82
|
+
value: ['fff', 'ggg'],
|
|
83
83
|
expect: true
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
title: '[string,int]',
|
|
87
|
+
value: ['fff', 312],
|
|
88
88
|
expect: true
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
title: '[int,int]',
|
|
92
|
+
value: [333, 312],
|
|
93
93
|
expect: true
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
title: '[int,string]',
|
|
97
|
+
value: [333, 'ddsadsa'],
|
|
98
98
|
expect: true
|
|
99
99
|
},
|
|
100
|
-
...
|
|
100
|
+
...defaultItems({})
|
|
101
101
|
]
|
|
102
102
|
},
|
|
103
103
|
{
|
|
@@ -105,21 +105,21 @@ const testItems: ITestSuite = {
|
|
|
105
105
|
'rule': ['$.array', [1], 'string'],
|
|
106
106
|
'items': [
|
|
107
107
|
{
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
title: '[string]',
|
|
109
|
+
value: ['fff'],
|
|
110
110
|
expect: true
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
title: '[string,string]',
|
|
114
|
+
value: ['fff', 'ggg'],
|
|
115
115
|
expect: true
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
title: '[string,int]',
|
|
119
|
+
value: ['fff', 123],
|
|
120
120
|
expect: false
|
|
121
121
|
},
|
|
122
|
-
...
|
|
122
|
+
...defaultItems({})
|
|
123
123
|
]
|
|
124
124
|
},
|
|
125
125
|
{
|
|
@@ -127,31 +127,31 @@ const testItems: ITestSuite = {
|
|
|
127
127
|
'rule': ['$.array', [1, 3], 'string'],
|
|
128
128
|
'items': [
|
|
129
129
|
{
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
title: '[string]',
|
|
131
|
+
value: ['fff'],
|
|
132
132
|
expect: true
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
title: '[string,string]',
|
|
136
|
+
value: ['fff', 'ggg'],
|
|
137
137
|
expect: true
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
title: '[string,string,string]',
|
|
141
|
+
value: ['fff', 'ggg', 'ggg'],
|
|
142
142
|
expect: true
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
title: '[string,string,string,string]',
|
|
146
|
+
value: ['fff', 'ggg', 'ggg', 'fffa'],
|
|
147
147
|
expect: false
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
title: '[string,int]',
|
|
151
|
+
value: ['fff', 123],
|
|
152
152
|
expect: false
|
|
153
153
|
},
|
|
154
|
-
...
|
|
154
|
+
...defaultItems({})
|
|
155
155
|
]
|
|
156
156
|
},
|
|
157
157
|
addRule({
|
package/src/test/03-tuple.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': ['$.tuple', 'string', 'int'],
|
|
27
27
|
'items': [
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
title: '[string]',
|
|
30
|
+
value: ['fff'],
|
|
31
31
|
expect: false
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
title: '[string,int]',
|
|
35
|
+
value: ['fff', 1213],
|
|
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
|
'empty array': false
|
|
45
45
|
})
|
|
46
46
|
]
|
|
@@ -50,84 +50,84 @@ const testItems: ITestSuite = {
|
|
|
50
50
|
'rule': ['$.tuple'],
|
|
51
51
|
'items': [
|
|
52
52
|
{
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
title: '[string]',
|
|
54
|
+
value: ['fff'],
|
|
55
55
|
expect: false
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
title: '[string,int]',
|
|
59
|
+
value: ['fff', 1213],
|
|
60
60
|
expect: false
|
|
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
|
'empty array': true
|
|
69
69
|
})
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
|
-
'name': '
|
|
73
|
+
'name': 'Unlimited optional tuple',
|
|
74
74
|
'rule': ['$.tuple', 'string', 'int', '...'],
|
|
75
75
|
'items': [
|
|
76
76
|
{
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
title: '[string]',
|
|
78
|
+
value: ['fff'],
|
|
79
79
|
expect: true
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
title: '[string,int]',
|
|
83
|
+
value: ['fff', 1213],
|
|
84
84
|
expect: true
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
title: '[string,int,int]',
|
|
88
|
+
value: ['fff', 1213, 233],
|
|
89
89
|
expect: true
|
|
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
|
'empty array': false
|
|
98
98
|
})
|
|
99
99
|
]
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
|
-
'name': 'Limited
|
|
102
|
+
'name': 'Limited optional tuple',
|
|
103
103
|
'rule': ['$.tuple', 'string', 'int', '...3', 'string'],
|
|
104
104
|
'items': [
|
|
105
105
|
{
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
title: '[string,int,int,int,string]',
|
|
107
|
+
value: ['fff', 1, 3, 5, 'ccc'],
|
|
108
108
|
expect: true
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
title: '[string,int]',
|
|
112
|
+
value: ['fff', 1213],
|
|
113
113
|
expect: false
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
title: '[string,int,string]',
|
|
117
|
+
value: ['fff', 1213, 'ccc'],
|
|
118
118
|
expect: false
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
title: '[string,int,int]',
|
|
122
|
+
value: ['fff', 1213, 233],
|
|
123
123
|
expect: false
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
title: '[int, string]',
|
|
127
|
+
value: [123, 'fff'],
|
|
128
128
|
expect: false
|
|
129
129
|
},
|
|
130
|
-
...
|
|
130
|
+
...defaultItems({
|
|
131
131
|
'empty array': false
|
|
132
132
|
})
|
|
133
133
|
]
|
|
@@ -137,46 +137,46 @@ const testItems: ITestSuite = {
|
|
|
137
137
|
'rule': ['$.tuple', 'string', 'int', '...4', 'string', '...'],
|
|
138
138
|
'items': [
|
|
139
139
|
{
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
title: '[string,int,int,int,int,string]',
|
|
141
|
+
value: ['fff', 1, 3, 5, 2, 'ccc'],
|
|
142
142
|
expect: true
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
title: '[string,int,int,int,int,string,string]',
|
|
146
|
+
value: ['fff', 1, 3, 5, 2, 'ccc', 'aaa'],
|
|
147
147
|
expect: true
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
title: '[string,int,int,int,int]',
|
|
151
|
+
value: ['fff', 1, 3, 5, 2],
|
|
152
152
|
expect: true
|
|
153
153
|
},
|
|
154
154
|
{
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
title: '[string,int,int,int]',
|
|
156
|
+
value: ['fff', 1, 3, 5],
|
|
157
157
|
expect: false
|
|
158
158
|
},
|
|
159
159
|
{
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
title: '[string,int]',
|
|
161
|
+
value: ['fff', 1213],
|
|
162
162
|
expect: false
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
title: '[string,int,string]',
|
|
166
|
+
value: ['fff', 1213, 'ccc'],
|
|
167
167
|
expect: false
|
|
168
168
|
},
|
|
169
169
|
{
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
title: '[string,int,int]',
|
|
171
|
+
value: ['fff', 1213, 233],
|
|
172
172
|
expect: false
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
title: '[int, string]',
|
|
176
|
+
value: [123, 'fff'],
|
|
177
177
|
expect: false
|
|
178
178
|
},
|
|
179
|
-
...
|
|
179
|
+
...defaultItems({
|
|
180
180
|
'empty array': false
|
|
181
181
|
})
|
|
182
182
|
]
|
|
@@ -186,8 +186,8 @@ const testItems: ITestSuite = {
|
|
|
186
186
|
'rule': ['$.tuple', '...'],
|
|
187
187
|
'items': [
|
|
188
188
|
{
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
title: 'any',
|
|
190
|
+
value: 'any',
|
|
191
191
|
expect: 'throw'
|
|
192
192
|
}
|
|
193
193
|
]
|
|
@@ -197,8 +197,8 @@ const testItems: ITestSuite = {
|
|
|
197
197
|
'rule': ['$.tuple', 'string', '...', '...'],
|
|
198
198
|
'items': [
|
|
199
199
|
{
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
title: 'any',
|
|
201
|
+
value: 'any',
|
|
202
202
|
expect: 'throw'
|
|
203
203
|
}
|
|
204
204
|
]
|
|
@@ -208,8 +208,8 @@ const testItems: ITestSuite = {
|
|
|
208
208
|
'rule': ['$.tuple', 'string', '...d'],
|
|
209
209
|
'items': [
|
|
210
210
|
{
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
title: 'any',
|
|
212
|
+
value: 'any',
|
|
213
213
|
expect: 'throw'
|
|
214
214
|
}
|
|
215
215
|
]
|