summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-29 11:04:25 +0200
committerJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-29 11:04:25 +0200
commit677eb20cbed2c57a4c6650b4232e528bab9a9b6f (patch)
treee5b1544ffa044ed52019a671b90c2545279fbb58 /src/test
parent36b57f6b11be973f09d1ca3178c57ca4b25f99aa (diff)
downloadspray-json-677eb20cbed2c57a4c6650b4232e528bab9a9b6f.tar.gz
spray-json-677eb20cbed2c57a4c6650b4232e528bab9a9b6f.tar.bz2
spray-json-677eb20cbed2c57a4c6650b4232e528bab9a9b6f.zip
first messy version
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/cc/spray/json/Updater2Spec.scala65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/scala/cc/spray/json/Updater2Spec.scala b/src/test/scala/cc/spray/json/Updater2Spec.scala
new file mode 100644
index 0000000..516945b
--- /dev/null
+++ b/src/test/scala/cc/spray/json/Updater2Spec.scala
@@ -0,0 +1,65 @@
+package cc.spray.json
+
+import DefaultJsonProtocol._
+
+import org.specs2.mutable.Specification
+
+class Updater2Spec extends Specification {
+ val json = JsonParser(
+ """{
+ | "n": 2,
+ | "els": [
+ | {
+ | "name": "John",
+ | "money": 23
+ | },
+ | {
+ | "name": "Paul",
+ | "money": 42
+ | }
+ | ]
+ |}
+ """.stripMargin)
+
+ import Lens2._
+
+ val n = field("n")
+
+ "Lenses" should {
+ "access" in {
+ "field" in {
+ n.get[Int].apply(json) must be_==(2)
+ }
+ "field of member" in {
+ val json = JsonParser( """{"n": {"b": 4}}""")
+
+ ("n" / "b").get[Int].apply(json) must be_==(4)
+ }
+ }
+
+ "modify" in {
+ "set field" in {
+ val simple = JsonParser( """{"n": 12}""")
+
+ simple.update(n ! set(23)) must be_json( """{"n": 23}""")
+ }
+ "update field" in {
+ val simple = JsonParser( """{"n": 12}""")
+ simple.update(n ! updated[Int](_ + 1)) must be_json( """{"n": 13}""")
+ }
+ "set field of member" in {
+ val json = JsonParser( """{"n": {"b": 4}}""")
+
+ json update ("n" / "b" ! set(23)) must be_json( """{"n": {"b": 23}}""")
+ }
+ "update field of member" in {
+ val json = JsonParser( """{"n": {"b": 4}}""")
+
+ json update ("n" / "b" ! updated[Int](1 +)) must be_json( """{"n": {"b": 5}}""")
+ }
+ }
+ }
+
+ def be_json(json: String) =
+ be_==(JsonParser(json))
+}