@@ -8,11 +8,17 @@ import {
8
8
IWithinRangeIntegerTag ,
9
9
IWithinRangeNumberTag
10
10
} from "italia-ts-commons/lib/numbers" ;
11
+ import { readableReport } from "italia-ts-commons/lib/reporters" ;
12
+ import { WithinRangeString } from "italia-ts-commons/lib/strings" ;
13
+ import { WithinRangeExclusiveMaximumIntegerTest } from "../../generated/testapi/WithinRangeExclusiveMaximumIntegerTest" ;
14
+ import { WithinRangeExclusiveMaximumNumberTest } from "../../generated/testapi/WithinRangeExclusiveMaximumNumberTest" ;
15
+ import { WithinRangeExclusiveMinimumIntegerTest } from "../../generated/testapi/WithinRangeExclusiveMinimumIntegerTest" ;
16
+ import { WithinRangeExclusiveMinimumNumberTest } from "../../generated/testapi/WithinRangeExclusiveMinimumNumberTest" ;
17
+ import { WithinRangeExclusiveMinMaxNumberTest } from "../../generated/testapi/WithinRangeExclusiveMinMaxNumberTest" ;
18
+
11
19
import { WithinRangeIntegerTest } from "../../generated/testapi/WithinRangeIntegerTest" ;
12
20
import { WithinRangeNumberTest } from "../../generated/testapi/WithinRangeNumberTest" ;
13
21
import { WithinRangeStringTest } from "../../generated/testapi/WithinRangeStringTest" ;
14
- import { WithinRangeString } from "italia-ts-commons/lib/strings" ;
15
- import { readableReport } from "italia-ts-commons/lib/reporters" ;
16
22
17
23
const { generatedFilesDir, isSpecEnabled } = config . specs . testapi ;
18
24
@@ -93,7 +99,7 @@ describe("Profile defintion", () => {
93
99
} ) ;
94
100
95
101
describe ( "WithinRangeIntegerTest defintion" , ( ) => {
96
- //WithinRangeIntegerTest is defined min=0 max=10 in the spec
102
+ // WithinRangeIntegerTest is defined min=0 max=10 in the spec
97
103
it . each `
98
104
value | expected
99
105
${ 0 } | ${ true /* lower bound */ }
@@ -115,7 +121,7 @@ describe("WithinRangeIntegerTest defintion", () => {
115
121
} ) ;
116
122
117
123
describe ( "WithinRangeNumberTest defintion" , ( ) => {
118
- //WithinRangeNumberTest is defined min=0 max=10 in the spec
124
+ // WithinRangeNumberTest is defined min=0 max=10 in the spec
119
125
it . each `
120
126
value | expected
121
127
${ 0 } | ${ true /* lower bound */ }
@@ -135,7 +141,78 @@ describe("WithinRangeNumberTest defintion", () => {
135
141
}
136
142
) ;
137
143
138
- /* it("should have correct ts types", () => {
144
+ describe ( "WithinRangeExclusiveMinimumNumberTest definition" , ( ) => {
145
+ // WithinRangeExclusiveMinimumNumberTest is defined min=0 max=10 exclusiveMinimum: true in the spec
146
+ it . each `
147
+ value | expected
148
+ ${ - 1 } | ${ false }
149
+ ${ 0 } | ${ false }
150
+ ${ 0.1 } | ${ true }
151
+ ${ 0.5 } | ${ true }
152
+ ${ 1 } | ${ true }
153
+ ${ 9.9999999 } | ${ true }
154
+ ${ 10 } | ${ true /* upper bound */ }
155
+ ${ 10.000001 } | ${ false }
156
+ ${ 11 } | ${ false }
157
+ ${ 100 } | ${ false }
158
+ ${ undefined } | ${ false }
159
+ ` (
160
+ "should decode $value with WithinRangeExclusiveMinimumNumberTest" ,
161
+ ( { value, expected } ) => {
162
+ const result = WithinRangeExclusiveMinimumNumberTest . decode ( value ) ;
163
+ expect ( result . isRight ( ) ) . toEqual ( expected ) ;
164
+ }
165
+ ) ;
166
+ } ) ;
167
+ describe ( "WithinRangeExclusiveMaximumNumberTest definition" , ( ) => {
168
+ // WithinRangeExclusiveMaximumNumberTest is defined min=0 max=10 exclusiveMaximum: true in the spec
169
+ it . each `
170
+ value | expected
171
+ ${ - 1 } | ${ false }
172
+ ${ 0 } | ${ true /* lower bound */ }
173
+ ${ 1.5 } | ${ true }
174
+ ${ 5.5 } | ${ true }
175
+ ${ 9 } | ${ true }
176
+ ${ 9.5 } | ${ true }
177
+ ${ 9.999 } | ${ true }
178
+ ${ 10 } | ${ false }
179
+ ${ 11 } | ${ false }
180
+ ${ 100 } | ${ false }
181
+ ${ undefined } | ${ false }
182
+ ` (
183
+ "should decode $value with WithinRangeExclusiveMaximumNumberTest" ,
184
+ ( { value, expected } ) => {
185
+ const result = WithinRangeExclusiveMaximumNumberTest . decode ( value ) ;
186
+ expect ( result . isRight ( ) ) . toEqual ( expected ) ;
187
+ }
188
+ ) ;
189
+ } ) ;
190
+
191
+ describe ( "WithinRangeExclusiveMinMaxNumberTest definition" , ( ) => {
192
+ // WithinRangeExclusiveMinMaxNumberTest is defined min=0 max=10 exclusiveMaximum: true exclusiveMinimum: true in the spec
193
+ it . each `
194
+ value | expected
195
+ ${ - 1 } | ${ false }
196
+ ${ 0 } | ${ false }
197
+ ${ 0.1 } | ${ true }
198
+ ${ 1.5 } | ${ true }
199
+ ${ 5.5 } | ${ true }
200
+ ${ 9 } | ${ true }
201
+ ${ 9.5 } | ${ true }
202
+ ${ 9.999 } | ${ true }
203
+ ${ 10 } | ${ false }
204
+ ${ 11 } | ${ false }
205
+ ${ 100 } | ${ false }
206
+ ${ undefined } | ${ false }
207
+ ` (
208
+ "should decode $value with WithinRangeExclusiveMinMaxNumberTest" ,
209
+ ( { value, expected } ) => {
210
+ const result = WithinRangeExclusiveMinMaxNumberTest . decode ( value ) ;
211
+ expect ( result . isRight ( ) ) . toEqual ( expected ) ;
212
+ }
213
+ ) ;
214
+ } ) ;
215
+ /* it("should have correct ts types", () => {
139
216
// value is actually "any"
140
217
const value1: WithinRangeNumberTest = WithinRangeNumberTest.decode(10).getOrElseL(err => {
141
218
throw new Error(readableReport(err))
@@ -149,8 +226,52 @@ describe("WithinRangeNumberTest defintion", () => {
149
226
}) */
150
227
} ) ;
151
228
229
+ describe ( "WithinRangeExclusiveMinimumIntegerTest definition" , ( ) => {
230
+ // WithinRangeExclusiveMinimumIntegerTest is defined min=0 max=10 exclusiveMinimum: true in the spec
231
+ it . each `
232
+ value | expected
233
+ ${ 0 } | ${ false }
234
+ ${ - 1 } | ${ false }
235
+ ${ 1 } | ${ true /* lower bound */ }
236
+ ${ 5 } | ${ true }
237
+ ${ 9 } | ${ true }
238
+ ${ 10 } | ${ true /* upper bound */ }
239
+ ${ 11 } | ${ false }
240
+ ${ 100 } | ${ false }
241
+ ${ undefined } | ${ false }
242
+ ` (
243
+ "should decode $value with WithinRangeExclusiveMinimumIntegerTest" ,
244
+ ( { value, expected } ) => {
245
+ const result = WithinRangeExclusiveMinimumIntegerTest . decode ( value ) ;
246
+ expect ( result . isRight ( ) ) . toEqual ( expected ) ;
247
+ }
248
+ ) ;
249
+ } ) ;
250
+
251
+ describe ( "WithinRangeExclusiveMaximumIntegerTest definition" , ( ) => {
252
+ // WithinRangeExclusiveMaximumIntegerTest is defined min=0 max=10 exclusiveMaximum: true in the spec
253
+ it . each `
254
+ value | expected
255
+ ${ 0 } | ${ true /* lower bound */ }
256
+ ${ - 1 } | ${ false }
257
+ ${ 1 } | ${ true }
258
+ ${ 5 } | ${ true }
259
+ ${ 9 } | ${ true }
260
+ ${ 10 } | ${ false /* upper bound */ }
261
+ ${ 11 } | ${ false }
262
+ ${ 100 } | ${ false }
263
+ ${ undefined } | ${ false }
264
+ ` (
265
+ "should decode $value with WithinRangeExclusiveMaximumIntegerTest" ,
266
+ ( { value, expected } ) => {
267
+ const result = WithinRangeExclusiveMaximumIntegerTest . decode ( value ) ;
268
+ expect ( result . isRight ( ) ) . toEqual ( expected ) ;
269
+ }
270
+ ) ;
271
+ } ) ;
272
+
152
273
describe ( "WithinRangeStringTest defintion" , ( ) => {
153
- //WithinRangeStringTest is defined min=8 max=10 in the spec
274
+ // WithinRangeStringTest is defined min=8 max=10 in the spec
154
275
it . each `
155
276
value | expected
156
277
${ "a" . repeat ( 7 ) } | ${ false }
0 commit comments