@@ -3,10 +3,14 @@ package io.github.optimumcode.json.schema.objects.wrapper
3
3
import io.github.optimumcode.json.schema.model.ArrayElement
4
4
import io.github.optimumcode.json.schema.model.ObjectElement
5
5
import io.github.optimumcode.json.schema.model.PrimitiveElement
6
+ import io.kotest.assertions.asClue
6
7
import io.kotest.assertions.assertSoftly
7
8
import io.kotest.assertions.throwables.shouldNotThrowAny
8
9
import io.kotest.assertions.throwables.shouldThrow
10
+ import io.kotest.core.Platform
11
+ import io.kotest.core.platform
9
12
import io.kotest.core.spec.style.FunSpec
13
+ import io.kotest.core.test.Enabled
10
14
import io.kotest.matchers.booleans.shouldBeFalse
11
15
import io.kotest.matchers.booleans.shouldBeTrue
12
16
import io.kotest.matchers.collections.shouldContainExactly
@@ -44,57 +48,57 @@ class WrappersTest : FunSpec() {
44
48
}
45
49
46
50
test(" primitive wrapper for null" ) {
47
- wrapAsElement(null ).shouldBeInstanceOf<PrimitiveElement > {
51
+ wrapAsElement(null ).shouldBeInstanceOf<PrimitiveElement > { el ->
48
52
assertSoftly {
49
- it. isString.shouldBeFalse()
50
- it. isNumber.shouldBeFalse()
51
- it. isBoolean.shouldBeFalse()
52
- it. isNull.shouldBeTrue()
53
- it. content shouldBe " null"
54
- it. longOrNull.shouldBeNull()
55
- it. doubleOrNull.shouldBeNull()
53
+ " isString " .asClue { el. isString.shouldBeFalse() }
54
+ " isNumber " .asClue { el. isNumber.shouldBeFalse() }
55
+ " isBoolean " .asClue { el. isBoolean.shouldBeFalse() }
56
+ " isNull " .asClue { el. isNull.shouldBeTrue() }
57
+ " content " .asClue { el. content shouldBe " null" }
58
+ " longOrNull " .asClue { el. longOrNull.shouldBeNull() }
59
+ " doubleOrNull " .asClue { el. doubleOrNull.shouldBeNull() }
56
60
}
57
61
}
58
62
}
59
63
60
64
test(" primitive wrapper for boolean" ) {
61
- wrapAsElement(true ).shouldBeInstanceOf<PrimitiveElement > {
65
+ wrapAsElement(true ).shouldBeInstanceOf<PrimitiveElement > { el ->
62
66
assertSoftly {
63
- it. isString.shouldBeFalse()
64
- it. isNumber.shouldBeFalse()
65
- it. isBoolean.shouldBeTrue()
66
- it. isNull.shouldBeFalse()
67
- it. content shouldBe " true"
68
- it. longOrNull.shouldBeNull()
69
- it. doubleOrNull.shouldBeNull()
67
+ " isString " .asClue { el. isString.shouldBeFalse() }
68
+ " isNumber " .asClue { el. isNumber.shouldBeFalse() }
69
+ " isBoolean " .asClue { el. isBoolean.shouldBeTrue() }
70
+ " isNull " .asClue { el. isNull.shouldBeFalse() }
71
+ " content " .asClue { el. content shouldBe " true" }
72
+ " longOrNull " .asClue { el. longOrNull.shouldBeNull() }
73
+ " doubleOrNull " .asClue { el. doubleOrNull.shouldBeNull() }
70
74
}
71
75
}
72
76
}
73
77
74
78
test(" primitive wrapper for number" ) {
75
- wrapAsElement(42 ).shouldBeInstanceOf<PrimitiveElement > {
79
+ wrapAsElement(42 ).shouldBeInstanceOf<PrimitiveElement > { el ->
76
80
assertSoftly {
77
- it. isString.shouldBeFalse()
78
- it. isNumber.shouldBeTrue()
79
- it. isBoolean.shouldBeFalse()
80
- it. isNull.shouldBeFalse()
81
- it. content shouldBe " 42"
82
- it. longOrNull shouldBe 42L
83
- it. doubleOrNull.shouldBeNull()
81
+ " isString " .asClue { el. isString.shouldBeFalse() }
82
+ " isNumber " .asClue { el. isNumber.shouldBeTrue() }
83
+ " isBoolean " .asClue { el. isBoolean.shouldBeFalse() }
84
+ " isNull " .asClue { el. isNull.shouldBeFalse() }
85
+ " content " .asClue { el. content shouldBe " 42" }
86
+ " longOrNull " .asClue { el. longOrNull shouldBe 42L }
87
+ " doubleOrNull " .asClue { el. doubleOrNull.shouldBeNull() }
84
88
}
85
89
}
86
90
}
87
91
88
92
test(" primitive wrapper for string" ) {
89
- wrapAsElement(" 42" ).shouldBeInstanceOf<PrimitiveElement > {
93
+ wrapAsElement(" 42" ).shouldBeInstanceOf<PrimitiveElement > { el ->
90
94
assertSoftly {
91
- it. isString.shouldBeTrue()
92
- it. isNumber.shouldBeFalse()
93
- it. isBoolean.shouldBeFalse()
94
- it. isNull.shouldBeFalse()
95
- it. content shouldBe " 42"
96
- it. longOrNull.shouldBeNull()
97
- it. doubleOrNull.shouldBeNull()
95
+ " isString " .asClue { el. isString.shouldBeTrue() }
96
+ " isNumber " .asClue { el. isNumber.shouldBeFalse() }
97
+ " isBoolean " .asClue { el. isBoolean.shouldBeFalse() }
98
+ " isNull " .asClue { el. isNull.shouldBeFalse() }
99
+ " content " .asClue { el. content shouldBe " 42" }
100
+ " longOrNull " .asClue { el. longOrNull.shouldBeNull() }
101
+ " doubleOrNull " .asClue { el. doubleOrNull.shouldBeNull() }
98
102
}
99
103
}
100
104
}
@@ -212,24 +216,32 @@ class WrappersTest : FunSpec() {
212
216
}
213
217
}
214
218
215
- test(" other number implementations are not allowed" ) {
216
- shouldThrow<IllegalStateException > {
217
- wrapAsElement(
218
- object : Number () {
219
- override fun toByte (): Byte = TODO (" Not yet implemented" )
219
+ test(" other number implementations are not allowed" )
220
+ .config(
221
+ enabledOrReasonIf = {
222
+ when (platform) {
223
+ Platform .JS -> Enabled .disabled(" you cannot create a class that is a Number on JS" )
224
+ else -> Enabled .enabled
225
+ }
226
+ },
227
+ ) {
228
+ shouldThrow<IllegalStateException > {
229
+ wrapAsElement(MyNumber ())
230
+ }.message.shouldStartWith(" unsupported number type:" )
231
+ }
232
+ }
233
+ }
220
234
221
- override fun toDouble (): Double = TODO (" Not yet implemented" )
235
+ private class MyNumber : Number () {
236
+ override fun toByte (): Byte = TODO (" Not yet implemented" )
222
237
223
- override fun toFloat (): Float = TODO (" Not yet implemented" )
238
+ override fun toDouble (): Double = TODO (" Not yet implemented" )
224
239
225
- override fun toInt (): Int = TODO (" Not yet implemented" )
240
+ override fun toFloat (): Float = TODO (" Not yet implemented" )
226
241
227
- override fun toLong (): Long = TODO (" Not yet implemented" )
242
+ override fun toInt (): Int = TODO (" Not yet implemented" )
228
243
229
- override fun toShort (): Short = TODO (" Not yet implemented" )
230
- },
231
- )
232
- }.message.shouldStartWith(" unsupported number type:" )
233
- }
234
- }
244
+ override fun toLong (): Long = TODO (" Not yet implemented" )
245
+
246
+ override fun toShort (): Short = TODO (" Not yet implemented" )
235
247
}
0 commit comments