-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathExampleSpec.scala
87 lines (69 loc) · 2.07 KB
/
ExampleSpec.scala
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.stephenn.scalatest.jsoniterscala
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
class ExampleSpec extends AnyFunSpec with Matchers with JsonMatchers {
case class Data(some: String, plus: Seq[String])
case class OtherData(someField: String, otherField: Seq[String])
implicit val codec: JsonValueCodec[Data] = JsonCodecMaker.make
// Please un-ignore test to see it in action
ignore("Jsoniter Scala JsonMatchers usage") {
it("should pass matching json with different spacing and order") {
val input =
"""
|{
| "some": "valid json",
| "plus": ["json", "content"]
|}
""".stripMargin
val expected =
"""
|{
| "plus": ["json", "content"],
| "some": "valid json"
|}
""".stripMargin
input should matchJson(expected)
}
it("should fail on slightly different json explaining why") {
val input =
"""
|{
| "some": "valid json"
|}
""".stripMargin
val expected =
"""
|{
| "some": "different json"
|}
""".stripMargin
input should matchJson(expected)
// Fails:
//
// Json did not match.
// Data(
// some: valid json -> different json,
// plus: List())
}
it("should fail on very different json explaining why") {
implicit val codec: JsonValueCodec[OtherData] = JsonCodecMaker.make
val input =
"""
|{
| "someField": "valid json",
| "otherField": ["json", "content"]
|}
""".stripMargin
val expected =
"""
|{
| "someField": "different json",
| "otherField": ["json", "stuff", "changes"]
|}
""".stripMargin
input should matchJson[OtherData](expected)
}
}
}