@@ -60,7 +60,34 @@ class ManifestValidationTest : FunSpec({
60
60
val manifest = Manifest (
61
61
typingSpec = expectedTypingSpec,
62
62
inputs = mapOf(
63
- "list-input" to ApiItem (type = "list", separator = "\n"),
63
+ "list-of-strings-input" to ApiItem (
64
+ type = "list",
65
+ separator = "\n",
66
+ listItem = ApiItem (type = "string"),
67
+ ),
68
+ "list-of-booleans-input" to ApiItem (
69
+ type = "list",
70
+ separator = "\n",
71
+ listItem = ApiItem (type = "boolean"),
72
+ ),
73
+ "list-of-integers-input" to ApiItem (
74
+ type = "list",
75
+ separator = "\n",
76
+ listItem = ApiItem (type = "integer"),
77
+ ),
78
+ "list-of-floats-input" to ApiItem (
79
+ type = "list",
80
+ separator = "\n",
81
+ listItem = ApiItem (type = "float"),
82
+ ),
83
+ "list-of-enums-input" to ApiItem (
84
+ type = "list",
85
+ separator = "\n",
86
+ listItem = ApiItem (
87
+ type = "enum",
88
+ allowedValues = listOf("foo", "bar")
89
+ ),
90
+ ),
64
91
),
65
92
)
66
93
@@ -71,7 +98,11 @@ class ManifestValidationTest : FunSpec({
71
98
result shouldBe ActionValidationResult (
72
99
overallResult = ItemValidationResult .Valid ,
73
100
inputs = mapOf(
74
- "list-input" to ItemValidationResult .Valid ,
101
+ "list-of-strings-input" to ItemValidationResult .Valid ,
102
+ "list-of-booleans-input" to ItemValidationResult .Valid ,
103
+ "list-of-integers-input" to ItemValidationResult .Valid ,
104
+ "list-of-floats-input" to ItemValidationResult .Valid ,
105
+ "list-of-enums-input" to ItemValidationResult .Valid ,
75
106
),
76
107
)
77
108
}
@@ -229,6 +260,39 @@ class ManifestValidationTest : FunSpec({
229
260
)
230
261
}
231
262
263
+ test("non-list types with 'listItem' attribute") {
264
+ // given
265
+ val manifest = Manifest (
266
+ typingSpec = expectedTypingSpec,
267
+ inputs = mapOf(
268
+ "string-input" to ApiItem (type = "string", listItem = ApiItem (type = "string")),
269
+ "boolean-input" to ApiItem (type = "boolean", listItem = ApiItem (type = "string")),
270
+ "integer-input" to ApiItem (type = "integer", listItem = ApiItem (type = "string")),
271
+ "float-input" to ApiItem (type = "float", listItem = ApiItem (type = "string")),
272
+ "enum-input" to ApiItem (
273
+ type = "enum",
274
+ allowedValues = listOf("foo", "bar"),
275
+ listItem = ApiItem (type = "string"),
276
+ ),
277
+ ),
278
+ )
279
+
280
+ // when
281
+ val result = manifest.validate()
282
+
283
+ // then
284
+ result shouldBe ActionValidationResult (
285
+ overallResult = ItemValidationResult .Invalid ("Some typing is invalid."),
286
+ inputs = mapOf(
287
+ "string-input" to ItemValidationResult .Invalid ("'listItem' is not allowed for this type."),
288
+ "boolean-input" to ItemValidationResult .Invalid ("'listItem' is not allowed for this type."),
289
+ "integer-input" to ItemValidationResult .Invalid ("'listItem' is not allowed for this type."),
290
+ "float-input" to ItemValidationResult .Invalid ("'listItem' is not allowed for this type."),
291
+ "enum-input" to ItemValidationResult .Invalid ("'listItem' is not allowed for this type."),
292
+ ),
293
+ )
294
+ }
295
+
232
296
test("enum type with 'separator' attribute") {
233
297
// given
234
298
val manifest = Manifest (
@@ -292,12 +356,33 @@ class ManifestValidationTest : FunSpec({
292
356
)
293
357
}
294
358
359
+ test("list type without 'listItem' attribute") {
360
+ // given
361
+ val manifest = Manifest (
362
+ typingSpec = expectedTypingSpec,
363
+ inputs = mapOf(
364
+ "list-input" to ApiItem (type = "list", separator = ","),
365
+ ),
366
+ )
367
+
368
+ // when
369
+ val result = manifest.validate()
370
+
371
+ // then
372
+ result shouldBe ActionValidationResult (
373
+ overallResult = ItemValidationResult .Invalid ("Some typing is invalid."),
374
+ inputs = mapOf(
375
+ "list-input" to ItemValidationResult .Invalid ("List item information must be specified."),
376
+ ),
377
+ )
378
+ }
379
+
295
380
test("list type without 'separator' attribute") {
296
381
// given
297
382
val manifest = Manifest (
298
383
typingSpec = expectedTypingSpec,
299
384
inputs = mapOf(
300
- "list-input" to ApiItem (type = "list"),
385
+ "list-input" to ApiItem (type = "list", listItem = ApiItem (type = "string") ),
301
386
),
302
387
)
303
388
@@ -318,7 +403,12 @@ class ManifestValidationTest : FunSpec({
318
403
val manifest = Manifest (
319
404
typingSpec = expectedTypingSpec,
320
405
inputs = mapOf(
321
- "list-input" to ApiItem (type = "list", separator = "\n", allowedValues = listOf("foo", "bar")),
406
+ "list-input" to ApiItem (
407
+ type = "list",
408
+ separator = "\n",
409
+ allowedValues = listOf("foo", "bar"),
410
+ listItem = ApiItem (type = "string"),
411
+ ),
322
412
),
323
413
)
324
414
@@ -333,5 +423,79 @@ class ManifestValidationTest : FunSpec({
333
423
),
334
424
)
335
425
}
426
+
427
+ test("list type with forbidden list item type") {
428
+ // given
429
+ val manifest = Manifest (
430
+ typingSpec = expectedTypingSpec,
431
+ inputs = mapOf(
432
+ "list-of-lists-input" to ApiItem (
433
+ type = "list",
434
+ separator = "\n",
435
+ listItem = ApiItem (
436
+ type = "list",
437
+ separator = ",",
438
+ listItem = ApiItem (type = "string"),
439
+ ),
440
+ ),
441
+ ),
442
+ )
443
+
444
+ // when
445
+ val result = manifest.validate()
446
+
447
+ // then
448
+ result shouldBe ActionValidationResult (
449
+ overallResult = ItemValidationResult .Invalid ("Some typing is invalid."),
450
+ inputs = mapOf(
451
+ "list-of-lists-input" to ItemValidationResult .Invalid (
452
+ "List item type: List can be parameterized only with a primitive or enum type.",
453
+ ),
454
+ ),
455
+ )
456
+ }
457
+
458
+ test("list type with list item type with incorrect attributes") {
459
+ // given
460
+ val manifest = Manifest (
461
+ typingSpec = expectedTypingSpec,
462
+ inputs = mapOf(
463
+ "list-of-enums-without-allowed-values-input" to ApiItem (
464
+ type = "list",
465
+ separator = "\n",
466
+ listItem = ApiItem (type = "enum"),
467
+ ),
468
+ "list-of-integers-with-allowed-values-input" to ApiItem (
469
+ type = "list",
470
+ separator = "\n",
471
+ listItem = ApiItem (type = "integer", allowedValues = listOf("foo", "bar")),
472
+ ),
473
+ "list-of-unknown-type-input" to ApiItem (
474
+ type = "list",
475
+ separator = "\n",
476
+ listItem = ApiItem (type = "for-sure-unknown-type"),
477
+ ),
478
+ ),
479
+ )
480
+
481
+ // when
482
+ val result = manifest.validate()
483
+
484
+ // then
485
+ result shouldBe ActionValidationResult (
486
+ overallResult = ItemValidationResult .Invalid ("Some typing is invalid."),
487
+ inputs = mapOf(
488
+ "list-of-enums-without-allowed-values-input" to ItemValidationResult .Invalid (
489
+ "List item type: Allowed values must be specified.",
490
+ ),
491
+ "list-of-integers-with-allowed-values-input" to ItemValidationResult .Invalid (
492
+ "List item type: 'allowedValues' is not allowed for this type."
493
+ ),
494
+ "list-of-unknown-type-input" to ItemValidationResult .Invalid (
495
+ "List item type: Unknown type: 'for-sure-unknown-type'."
496
+ )
497
+ ),
498
+ )
499
+ }
336
500
}
337
501
})
0 commit comments