Skip to content

Commit d922f99

Browse files
committed
tweak
1 parent e68ca9b commit d922f99

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

playtest-http/src/main/kotlin/com/uzabase/playtest2/http/zoom/JsonSerializable.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ internal class IndefiniteJsonPathProxy(
108108
}
109109
}
110110

111-
override fun shouldBeExist(): Boolean {
112-
TODO("Not yet implemented")
113-
}
111+
/***
112+
* Indefinite なパスの場合、存在しないパスでも必ずリストが返ってくるので、例外の考慮は不要…?
113+
***/
114+
override fun shouldBeExist(): Boolean =
115+
JsonPath.parse(json).read<List<Any>>(path).isNotEmpty()
114116

115-
override fun shouldNotBeExist(): Boolean {
116-
TODO("Not yet implemented")
117-
}
117+
override fun shouldNotBeExist(): Boolean = !shouldBeExist()
118118
}

playtest-http/src/test/kotlin/com/uzabase/playtest2/http/zoom/JsonPathProxyTest.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import io.kotest.assertions.throwables.shouldThrow
55
import io.kotest.core.spec.style.FunSpec
66
import io.kotest.data.forAll
77
import io.kotest.data.row
8+
import io.kotest.matchers.booleans.shouldBeFalse
89
import io.kotest.matchers.booleans.shouldBeTrue
9-
import io.kotest.matchers.should
1010
import io.kotest.matchers.shouldBe
1111

1212
class JsonPathProxyTest : FunSpec({
@@ -142,5 +142,20 @@ class JsonPathProxyTest : FunSpec({
142142
.shouldMatch(".*")
143143
}.message.shouldBe("The path is indefinite and the result is not a single value")
144144
}
145+
146+
test("should be false if empty after filtering - should be exist") {
147+
JsonPathProxy.of(json, "$.people[?(@.name == 'xyz')].name")
148+
.shouldBeExist().shouldBe(false)
149+
}
150+
151+
test("should be true if not empty after filtering - should be exist") {
152+
JsonPathProxy.of(json, "$.people[?(@.name == 'abc')].name")
153+
.shouldBeExist().shouldBe(true)
154+
}
155+
156+
test("should be false if path not found - should be exist") {
157+
JsonPathProxy.of(json, "$.people[?(@.age > 0)][999]")
158+
.shouldBeExist().shouldBeFalse()
159+
}
145160
}
146161
})

0 commit comments

Comments
 (0)