@litert/typeguard 1.4.0 → 1.4.1

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.
@@ -1,197 +0,0 @@
1
- /**
2
- * Copyright 2023 Angus Fenying <fenying@litert.org>
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * https://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import {
18
- createTestDefinition,
19
- defaultItems,
20
- ITestSuite,
21
- assertItem,
22
- addRule
23
- } from './abstracts';
24
-
25
- const testItems: ITestSuite = {
26
-
27
- name: 'List & Array',
28
- sections: [
29
-
30
- {
31
- 'name': 'String list',
32
- 'rule': ['$.list', 'string'],
33
- 'items': [
34
- {
35
- title: '[string]',
36
- value: ['fff'],
37
- expect: true
38
- },
39
- {
40
- title: '[string,string]',
41
- value: ['fff', 'ggg'],
42
- expect: true
43
- },
44
- {
45
- title: '[string,int]',
46
- value: ['fff', 123],
47
- expect: false
48
- },
49
- ...defaultItems({
50
- 'empty array': true
51
- })
52
- ]
53
- },
54
- {
55
- 'name': 'Fixed-length array with 1 element.',
56
- 'rule': ['$.array', 1, 'string'],
57
- 'items': [
58
- {
59
- title: '[string]',
60
- value: ['fff'],
61
- expect: true
62
- },
63
- {
64
- title: '[string,string]',
65
- value: ['fff', 'ggg'],
66
- expect: false
67
- },
68
- ...defaultItems({})
69
- ]
70
- },
71
- {
72
- 'name': 'Fixed-length array with 2 different-type elements.',
73
- 'rule': ['$.array', 2, 'string', 'int'],
74
- 'items': [
75
- {
76
- title: '[string]',
77
- value: ['fff'],
78
- expect: false
79
- },
80
- {
81
- title: '[string,string]',
82
- value: ['fff', 'ggg'],
83
- expect: true
84
- },
85
- {
86
- title: '[string,int]',
87
- value: ['fff', 312],
88
- expect: true
89
- },
90
- {
91
- title: '[int,int]',
92
- value: [333, 312],
93
- expect: true
94
- },
95
- {
96
- title: '[int,string]',
97
- value: [333, 'ddsadsa'],
98
- expect: true
99
- },
100
- ...defaultItems({})
101
- ]
102
- },
103
- {
104
- 'name': 'Variable-length array with at least 1 element',
105
- 'rule': ['$.array', [1], 'string'],
106
- 'items': [
107
- {
108
- title: '[string]',
109
- value: ['fff'],
110
- expect: true
111
- },
112
- {
113
- title: '[string,string]',
114
- value: ['fff', 'ggg'],
115
- expect: true
116
- },
117
- {
118
- title: '[string,int]',
119
- value: ['fff', 123],
120
- expect: false
121
- },
122
- ...defaultItems({})
123
- ]
124
- },
125
- {
126
- 'name': 'Variable-length array with 1 ~ 3 elements',
127
- 'rule': ['$.array', [1, 3], 'string'],
128
- 'items': [
129
- {
130
- title: '[string]',
131
- value: ['fff'],
132
- expect: true
133
- },
134
- {
135
- title: '[string,string]',
136
- value: ['fff', 'ggg'],
137
- expect: true
138
- },
139
- {
140
- title: '[string,string,string]',
141
- value: ['fff', 'ggg', 'ggg'],
142
- expect: true
143
- },
144
- {
145
- title: '[string,string,string,string]',
146
- value: ['fff', 'ggg', 'ggg', 'fffa'],
147
- expect: false
148
- },
149
- {
150
- title: '[string,int]',
151
- value: ['fff', 123],
152
- expect: false
153
- },
154
- ...defaultItems({})
155
- ]
156
- },
157
- addRule({
158
- 'a->[]': 'string'
159
- }, [
160
- assertItem([], false),
161
- assertItem({ 'a': [] }, true),
162
- assertItem({ 'a': [1] }, false),
163
- assertItem({ 'a': ['1'] }, true)
164
- ]),
165
- addRule({
166
- 'a->[3]': 'string'
167
- }, [
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)
173
- ]),
174
- addRule({
175
- 'a->[3,]': 'string'
176
- }, [
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)
182
- ]),
183
- addRule({
184
- 'a->[3,5]': 'string'
185
- }, [
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)
193
- ])
194
- ],
195
- };
196
-
197
- export default createTestDefinition(testItems);
@@ -1,220 +0,0 @@
1
- /**
2
- * Copyright 2023 Angus Fenying <fenying@litert.org>
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * https://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import { createTestDefinition, defaultItems, ITestSuite } from './abstracts';
18
-
19
- const testItems: ITestSuite = {
20
-
21
- name: 'Tuple',
22
- sections: [
23
-
24
- {
25
- 'name': 'Simple tuple',
26
- 'rule': ['$.tuple', 'string', 'int'],
27
- 'items': [
28
- {
29
- title: '[string]',
30
- value: ['fff'],
31
- expect: false
32
- },
33
- {
34
- title: '[string,int]',
35
- value: ['fff', 1213],
36
- expect: true
37
- },
38
- {
39
- title: '[int, string]',
40
- value: [123, 'fff'],
41
- expect: false
42
- },
43
- ...defaultItems({
44
- 'empty array': false
45
- })
46
- ]
47
- },
48
- {
49
- 'name': 'Empty tuple',
50
- 'rule': ['$.tuple'],
51
- 'items': [
52
- {
53
- title: '[string]',
54
- value: ['fff'],
55
- expect: false
56
- },
57
- {
58
- title: '[string,int]',
59
- value: ['fff', 1213],
60
- expect: false
61
- },
62
- {
63
- title: '[int, string]',
64
- value: [123, 'fff'],
65
- expect: false
66
- },
67
- ...defaultItems({
68
- 'empty array': true
69
- })
70
- ]
71
- },
72
- {
73
- 'name': 'Unlimited optional tuple',
74
- 'rule': ['$.tuple', 'string', 'int', '...'],
75
- 'items': [
76
- {
77
- title: '[string]',
78
- value: ['fff'],
79
- expect: true
80
- },
81
- {
82
- title: '[string,int]',
83
- value: ['fff', 1213],
84
- expect: true
85
- },
86
- {
87
- title: '[string,int,int]',
88
- value: ['fff', 1213, 233],
89
- expect: true
90
- },
91
- {
92
- title: '[int, string]',
93
- value: [123, 'fff'],
94
- expect: false
95
- },
96
- ...defaultItems({
97
- 'empty array': false
98
- })
99
- ]
100
- },
101
- {
102
- 'name': 'Limited optional tuple',
103
- 'rule': ['$.tuple', 'string', 'int', '...3', 'string'],
104
- 'items': [
105
- {
106
- title: '[string,int,int,int,string]',
107
- value: ['fff', 1, 3, 5, 'ccc'],
108
- expect: true
109
- },
110
- {
111
- title: '[string,int]',
112
- value: ['fff', 1213],
113
- expect: false
114
- },
115
- {
116
- title: '[string,int,string]',
117
- value: ['fff', 1213, 'ccc'],
118
- expect: false
119
- },
120
- {
121
- title: '[string,int,int]',
122
- value: ['fff', 1213, 233],
123
- expect: false
124
- },
125
- {
126
- title: '[int, string]',
127
- value: [123, 'fff'],
128
- expect: false
129
- },
130
- ...defaultItems({
131
- 'empty array': false
132
- })
133
- ]
134
- },
135
- {
136
- 'name': 'Mixed omitted tuple',
137
- 'rule': ['$.tuple', 'string', 'int', '...4', 'string', '...'],
138
- 'items': [
139
- {
140
- title: '[string,int,int,int,int,string]',
141
- value: ['fff', 1, 3, 5, 2, 'ccc'],
142
- expect: true
143
- },
144
- {
145
- title: '[string,int,int,int,int,string,string]',
146
- value: ['fff', 1, 3, 5, 2, 'ccc', 'aaa'],
147
- expect: true
148
- },
149
- {
150
- title: '[string,int,int,int,int]',
151
- value: ['fff', 1, 3, 5, 2],
152
- expect: true
153
- },
154
- {
155
- title: '[string,int,int,int]',
156
- value: ['fff', 1, 3, 5],
157
- expect: false
158
- },
159
- {
160
- title: '[string,int]',
161
- value: ['fff', 1213],
162
- expect: false
163
- },
164
- {
165
- title: '[string,int,string]',
166
- value: ['fff', 1213, 'ccc'],
167
- expect: false
168
- },
169
- {
170
- title: '[string,int,int]',
171
- value: ['fff', 1213, 233],
172
- expect: false
173
- },
174
- {
175
- title: '[int, string]',
176
- value: [123, 'fff'],
177
- expect: false
178
- },
179
- ...defaultItems({
180
- 'empty array': false
181
- })
182
- ]
183
- },
184
- {
185
- 'name': 'Invalid syntax: [\'$.tuple\', \'...\']',
186
- 'rule': ['$.tuple', '...'],
187
- 'items': [
188
- {
189
- title: 'any',
190
- value: 'any',
191
- expect: 'throw'
192
- }
193
- ]
194
- },
195
- {
196
- 'name': 'Invalid syntax: [\'$.tuple\', \'string\', \'...\', \'...\']',
197
- 'rule': ['$.tuple', 'string', '...', '...'],
198
- 'items': [
199
- {
200
- title: 'any',
201
- value: 'any',
202
- expect: 'throw'
203
- }
204
- ]
205
- },
206
- {
207
- 'name': 'Invalid syntax: [\'$.tuple\', \'string\', \'...d\']',
208
- 'rule': ['$.tuple', 'string', '...d'],
209
- 'items': [
210
- {
211
- title: 'any',
212
- value: 'any',
213
- expect: 'throw'
214
- }
215
- ]
216
- }
217
- ]
218
- };
219
-
220
- export default createTestDefinition(testItems);