diff options
author | Johannes Rudolph <johannes.rudolph@gmail.com> | 2013-05-29 15:06:05 +0200 |
---|---|---|
committer | Johannes Rudolph <johannes.rudolph@gmail.com> | 2013-05-29 15:06:05 +0200 |
commit | 4279fcebd188987e9f74aa9aa046a1b8d9bdfbd4 (patch) | |
tree | 456971ec3fd4a1ed9f3e29a8db71b3300262c807 /src/test | |
parent | 64e2e332fa962a90185025ea3788cf4c56a65647 (diff) | |
download | spray-json-4279fcebd188987e9f74aa9aa046a1b8d9bdfbd4.tar.gz spray-json-4279fcebd188987e9f74aa9aa046a1b8d9bdfbd4.tar.bz2 spray-json-4279fcebd188987e9f74aa9aa046a1b8d9bdfbd4.zip |
new `setOrUpdateField` operation to udpate `optionalFields`
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/cc/spray/json/lenses/JsonLensesSpec.scala | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/lenses/JsonLensesSpec.scala b/src/test/scala/cc/spray/json/lenses/JsonLensesSpec.scala index a6a7697..3f7b0ff 100644 --- a/src/test/scala/cc/spray/json/lenses/JsonLensesSpec.scala +++ b/src/test/scala/cc/spray/json/lenses/JsonLensesSpec.scala @@ -124,6 +124,13 @@ class JsonLensesSpec extends Specification with SpecHelpers { "create" in { """[{"b": 4}, {"c": 5}]""".update((* / 'b.?) ! set(38)) must be_json("""[{"b": 38}, {"c": 5, "b": 38}]""") } + "set or update with default" in { + """[{"b": 4}, {"c": 5}]""".update((* / 'b.?) ! setOrUpdateField(38)(1 + )) must be_json("""[{"b": 5}, {"c": 5, "b": 38}]""") + } + "set or update with function" in { + """[{"b": 4}, {"c": 5}]""".update((* / 'b.?) ! setOrUpdateField[Int]((_: Option[Int]).map(1+).getOrElse(38))) must be_json("""[{"b": 5}, {"c": 5, "b": 38}]""") + } + "create nested (current behavior)" in { // One could think that nested `optionalField`s and `set` would create intermediate // objects as well. However, this is currently not possible, since |