summaryrefslogtreecommitdiff
path: root/src/test/scala
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-29 17:29:45 +0200
committerJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-29 17:29:45 +0200
commit6e50bcf8c62e153667921f92fd8af95c913066c2 (patch)
treec9bc82865979ff0449d449d0c4cbcc02eb156bb7 /src/test/scala
parent1a992f3b4eea1da49d9d6f36ddcb6faeef7340ca (diff)
downloadspray-json-6e50bcf8c62e153667921f92fd8af95c913066c2.tar.gz
spray-json-6e50bcf8c62e153667921f92fd8af95c913066c2.tar.bz2
spray-json-6e50bcf8c62e153667921f92fd8af95c913066c2.zip
enable nested finding
Diffstat (limited to 'src/test/scala')
-rw-r--r--src/test/scala/cc/spray/json/JsonLensesSpec.scala26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/JsonLensesSpec.scala b/src/test/scala/cc/spray/json/JsonLensesSpec.scala
index ab77f78..5679c01 100644
--- a/src/test/scala/cc/spray/json/JsonLensesSpec.scala
+++ b/src/test/scala/cc/spray/json/JsonLensesSpec.scala
@@ -46,6 +46,19 @@ class JsonLensesSpec extends Specification {
"""["a", "b", 2, 5, 8, 3]""" extract JsonLenses.find(JsonLenses.value.is[Int](_ < 4)).get[Int] must beSome(2)
"""["a", "b", 2, 5, 8, 3]""" extract JsonLenses.find(JsonLenses.value.is[String](_ == "unknown")).get[Int] must beNone
}
+ "nested finding" in {
+ val lens = JsonLenses.find("a".is[Int](_ == 12)) / "b" / "c" andThen JsonLenses.find(JsonLenses.value.is[Int](_ == 5))
+
+ "existing" in {
+ """[{"a": 12, "b": {"c": [2, 5]}}, 13]""" extract lens.get[Int] must beSome(5)
+ }
+ "missing in first find" in {
+ """[{"a": 2, "b": {"c": [5]}}, 13]""" extract lens.get[Int] must beNone
+ }
+ "missing in second find" in {
+ """[{"a": 2, "b": {"c": [7]}}, 13]""" extract lens.get[Int] must beNone
+ }
+ }
}
}
@@ -99,6 +112,19 @@ class JsonLensesSpec extends Specification {
"""["a", "b", "test", 5, 8, 3]"""
)
}
+ "nested" in {
+ val lens = JsonLenses.find("a".is[Int](_ == 12)) / "b" / "c" andThen JsonLenses.find(JsonLenses.value.is[Int](_ == 5))
+
+ "existing" in {
+ """[{"a": 12, "b": {"c": [2, 5]}}, 13]""" update (lens ! set(42)) must be_json("""[{"a": 12, "b": {"c": [2, 42]}}, 13]""")
+ }
+ "missing in first find" in {
+ """[{"a": 2, "b": {"c": [5]}}, 13]""" update (lens ! set(42)) must be_json("""[{"a": 2, "b": {"c": [5]}}, 13]""")
+ }
+ "missing in second find" in {
+ """[{"a": 2, "b": {"c": [7]}}, 13]""" update (lens ! set(42)) must be_json("""[{"a": 2, "b": {"c": [7]}}, 13]""")
+ }
+ }
}
}
}