-
Notifications
You must be signed in to change notification settings - Fork 8
/
EnumerationDerivalSpec.scala
51 lines (38 loc) · 1.46 KB
/
EnumerationDerivalSpec.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
package com.evolution.playjson.generic
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import play.api.libs.json.{Format, Json}
class EnumerationDerivalSpec extends AnyFlatSpec with Matchers {
it should "be able to encode and decode case object enumerations using default low prio implicit" in {
implicit val format: Format[AnEvent] = Enumeration[AnEvent].format
val typ: AnEvent = AnEvent.DoneSome
val js = Json.toJson(typ)
js.toString() shouldBe "\"DoneSome\""
js.as[AnEvent] shouldBe typ
}
it should "be able to encode and decode in kebab case" in {
import NameCodingStrategies.kebabCase
implicit val format: Format[AnEvent] = Enumeration[AnEvent].format
val typ: AnEvent = AnEvent.DoneSome
val json = Json.toJson(typ)
json.toString() shouldBe "\"done-some\""
json.as[AnEvent] shouldBe typ
succeed
}
it should "be able to derive formats" in {
implicit val fmt = Enumeration[AnEvent].format
val typ: AnEvent = AnEvent.DoneSome
val js = Json.toJson(typ)
js.toString() shouldBe "\"DoneSome\""
js.as[AnEvent] shouldBe typ
}
it should "be able to encode and decode in no sep case" in {
import NameCodingStrategies.noSepCase
implicit val format: Format[AnEvent] = Enumeration[AnEvent].format
val typ: AnEvent = AnEvent.DoneSome
val json = Json.toJson(typ)
json.toString() shouldBe "\"donesome\""
json.as[AnEvent] shouldBe typ
succeed
}
}