Skip to content

Commit e4b9343

Browse files
author
Oleg
committed
Add tests for pointer extensions
1 parent ff947eb commit e4b9343

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package smirnov.oleg.json.pointer
2+
3+
import io.kotest.core.spec.style.FunSpec
4+
import io.kotest.matchers.shouldBe
5+
import smirnov.oleg.json.pointer.JsonPointer.Companion
6+
7+
@Suppress("unused")
8+
class JsonPointerExtensionsTest : FunSpec() {
9+
init {
10+
data class TestCase<T>(
11+
val firstArg: JsonPointer,
12+
val secondArg: T,
13+
val result: JsonPointer,
14+
)
15+
16+
listOf(
17+
TestCase(JsonPointer.ROOT, "prop", JsonPointer("/prop")),
18+
TestCase(JsonPointer("/test"), "prop", JsonPointer("/test/prop")),
19+
).forEach { (initial, prop, result) ->
20+
test("$initial / $prop => $result") {
21+
(initial / prop) shouldBe result
22+
}
23+
}
24+
25+
listOf(
26+
TestCase(JsonPointer.ROOT, 0, JsonPointer("/0")),
27+
TestCase(JsonPointer("/test"), 0, JsonPointer("/test/0")),
28+
).forEach { (initial, prop, result) ->
29+
test("$initial [ $prop ] => $result") {
30+
(initial[prop]) shouldBe result
31+
}
32+
}
33+
34+
listOf(
35+
TestCase(JsonPointer.ROOT, JsonPointer.ROOT, JsonPointer.ROOT),
36+
TestCase(JsonPointer.ROOT, JsonPointer("/test"), JsonPointer("/test")),
37+
TestCase(JsonPointer("/test"), JsonPointer.ROOT, JsonPointer("/test")),
38+
TestCase(JsonPointer("/test1"), JsonPointer("/test2"), JsonPointer("/test1/test2")),
39+
).forEach { (init, append, result) ->
40+
test("$init + $append => $result") {
41+
(init + append) shouldBe result
42+
}
43+
}
44+
45+
listOf(
46+
TestCase(JsonPointer.ROOT, JsonPointer.ROOT, JsonPointer.ROOT),
47+
TestCase(JsonPointer.ROOT, JsonPointer("/test"), JsonPointer("/test")),
48+
TestCase(JsonPointer("/test"), JsonPointer("/test/data"), JsonPointer("/data")),
49+
).forEach { (base, relativeToBase, relativePath) ->
50+
test("relative path from '$base' to '$relativeToBase' is '$relativePath'") {
51+
base.relative(relativeToBase) shouldBe relativePath
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)