Skip to content

Commit 46077c6

Browse files
author
Oleg
committed
Extract common tests
1 parent 7156fb4 commit 46077c6

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/commonTest/kotlin/smirnov/oleg/json/schema/assertions/object/JsonSchemaMaxPropertiesValidationTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class JsonSchemaMaxPropertiesValidationTest : FunSpec() {
6868
}
6969
}
7070

71+
notAnObjectPasses(schema)
72+
7173
test("reports negative value") {
7274
shouldThrow<IllegalArgumentException> {
7375
JsonSchema.fromDescription(

src/commonTest/kotlin/smirnov/oleg/json/schema/assertions/object/JsonSchemaMinPropertiesValidationTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class JsonSchemaMinPropertiesValidationTest : FunSpec() {
7171
}
7272
}
7373

74+
notAnObjectPasses(schema)
75+
7476
test("reports negative value") {
7577
shouldThrow<IllegalArgumentException> {
7678
JsonSchema.fromDescription(

src/commonTest/kotlin/smirnov/oleg/json/schema/assertions/object/JsonSchemaRequiredValidationTest.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ class JsonSchemaRequiredValidationTest : FunSpec() {
7373
}
7474
}
7575

76-
listOf(
77-
JsonPrimitive("a"),
78-
JsonPrimitive(42),
79-
JsonPrimitive(42.5),
80-
JsonPrimitive(true),
81-
JsonNull,
82-
buildJsonArray { },
83-
).forEach {
84-
test("not an object $it passes validation") {
85-
val errors = mutableListOf<ValidationError>()
86-
val valid = schema.validate(it, errors::add)
87-
valid shouldBe true
88-
errors shouldHaveSize 0
89-
}
90-
}
76+
notAnObjectPasses(schema)
9177
}
9278
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package smirnov.oleg.json.schema.assertions.`object`
2+
3+
import io.kotest.core.spec.style.FunSpec
4+
import io.kotest.matchers.collections.shouldHaveSize
5+
import io.kotest.matchers.shouldBe
6+
import kotlinx.serialization.json.JsonNull
7+
import kotlinx.serialization.json.JsonPrimitive
8+
import kotlinx.serialization.json.buildJsonArray
9+
import smirnov.oleg.json.schema.JsonSchema
10+
import smirnov.oleg.json.schema.ValidationError
11+
12+
fun FunSpec.notAnObjectPasses(schema: JsonSchema) {
13+
listOf(
14+
JsonPrimitive("a"),
15+
JsonPrimitive(42),
16+
JsonPrimitive(42.5),
17+
JsonPrimitive(true),
18+
JsonNull,
19+
buildJsonArray { },
20+
).forEach {
21+
test("not an object $it passes validation") {
22+
val errors = mutableListOf<ValidationError>()
23+
val valid = schema.validate(it, errors::add)
24+
valid shouldBe true
25+
errors shouldHaveSize 0
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)