blob: 93d763a66b042a8d5a13ea31d9300f3ee06cb887 (
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
51
52
53
|
package yamlesque
import spray.json._
import utest._
object FormatTests extends TestSuite {
case class A(a1: Int, a2: Seq[B])
case class B(a: String, b: Option[Boolean])
object Protocol extends DefaultJsonProtocol with JsonYamlFormats {
implicit def bFormat = jsonFormat2(B)
implicit def aFormat = jsonFormat2(A)
}
import Protocol._
val tests = Tests {
"parse" - {
val str =
s"""|a1: 42
|a2:
| - a: hello world
| b: true
| - a: yoyo
|""".stripMargin
"parse yaml" - {
str.parseYaml ==> YamlMapping(
"a1" -> YamlScalar("42"),
"a2" -> YamlSequence(
YamlMapping(
"a" -> YamlScalar("hello world"),
"b" -> YamlScalar("true")
),
YamlMapping(
"a" -> YamlScalar("yoyo")
)
)
)
}
"parse with json readers" - {
str.parseYaml.convertTo[A] ==> A(
42,
Seq(
B("hello world", Some(true)),
B("yoyo", None),
)
)
}
}
}
}
|