summaryrefslogtreecommitdiff
path: root/src/test/scala/spray/json/SortedPrinterSpec.scala
blob: 0ea10456c15769ed85299c0b1068f5e0cef8dac5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package spray.json

import scala.collection.immutable.ListMap
import org.specs2.mutable._

class SortedPrinterSpec extends Specification {

  "The SortedPrinter" should {
    "print a more complicated JsObject nicely aligned with fields sorted" in {
      val obj = JsonParser {
        """{
          |  "Unic\u00f8de" :  "Long string with newline\nescape",
          |  "Boolean no": false,
          |  "number": -1.2323424E-5,
          |  "key with \"quotes\"" : "string",
          |  "key with spaces": null,
          |  "simpleKey" : "some value",
          |    "zero": 0,
          |  "sub object" : {
          |    "sub key": 26.5,
          |    "a": "b",
          |    "array": [1, 2, { "yes":1, "no":0 }, ["a", "b", null], false]
          |  },
          |  "Boolean yes":true
          |}""".stripMargin
      }
      SortedPrinter(obj) mustEqual {
        """{
          |  "Boolean no": false,
          |  "Boolean yes": true,
          |  "Unic\u00f8de": "Long string with newline\nescape",
          |  "key with \"quotes\"": "string",
          |  "key with spaces": null,
          |  "number": -0.000012323424,
          |  "simpleKey": "some value",
          |  "sub object": {
          |    "a": "b",
          |    "array": [1, 2, {
          |      "no": 0,
          |      "yes": 1
          |    }, ["a", "b", null], false],
          |    "sub key": 26.5
          |  },
          |  "zero": 0
          |}""".stripMargin
      }
    }
  }

}