summaryrefslogtreecommitdiff
path: root/src/test/scala
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-30 14:03:28 +0200
committerJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-30 14:03:28 +0200
commit9491c92a66d496ca336f300cee26ecad81b746ea (patch)
treeacfb8a5e13cd162f93ab2e4c7517b3f1c878f21f /src/test/scala
parentd4e77ce2b3ffe1c9929e955cfb45ffb5e2f79e28 (diff)
downloadspray-json-9491c92a66d496ca336f300cee26ecad81b746ea.tar.gz
spray-json-9491c92a66d496ca336f300cee26ecad81b746ea.tar.bz2
spray-json-9491c92a66d496ca336f300cee26ecad81b746ea.zip
implement `elements` + `filter` and most of the combinators
Diffstat (limited to 'src/test/scala')
-rw-r--r--src/test/scala/cc/spray/json/JsonLensesSpec.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/JsonLensesSpec.scala b/src/test/scala/cc/spray/json/JsonLensesSpec.scala
index d6407c1..766084f 100644
--- a/src/test/scala/cc/spray/json/JsonLensesSpec.scala
+++ b/src/test/scala/cc/spray/json/JsonLensesSpec.scala
@@ -60,6 +60,31 @@ class JsonLensesSpec extends Specification with SpecHelpers {
}
}
}
+ "all elements of an array" in {
+ "simple" in {
+ """[18, 23, 2, 5, 8, 3]""" extract elements.get[Int] must be_==(Seq(18, 23, 2, 5, 8, 3))
+ }
+ "which is a scalar element" in {
+ """{"a": [1, 2, 3, 4]}""" extract ("a" andThen elements).get[Int] must be_==(Seq(1, 2, 3, 4))
+ }
+ "field of an array element" in {
+ """[{"a": 1}, {"a": 2}]""" extract (elements andThen "a").get[Int] must be_==(Seq(1, 2))
+ }
+ "nested" in {
+ """[[1, 2], [3, 4]]""" extract (elements andThen elements).get[Int] must be_==(Seq(1, 2, 3, 4))
+ }
+ "if outer is no array" in {
+ """{"a": 5}""" extract (elements / "a").get[Int] must throwAn[Exception]("""Not a json array: {"a":5}""")
+ """{"a": 5}""" extract (elements andThen elements).get[Int] must throwAn[Exception]("""Not a json array: {"a":5}""")
+ }
+ "if inner is no array" in {
+ """[{}, {}]""" extract (elements andThen elements).get[Int] must throwAn[Exception]("""Not a json array: {}""")
+ """{"a": 5}""" extract ("a" andThen elements).get[Int] must throwAn[Exception]("""Not a json array: 5""")
+ }
+ }
+ /*"filtered elements of an array" in {
+
+ }*/
}
"modify" in {