blob: c26d3020129286d6e11fdaf5bd1b5c8c39e5602e (
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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package cc.spray.json
import org.specs.Specification
class BasicFormatsSpec extends Specification with DefaultJsonProtocol {
"The IntJsonFormat" should {
"convert an Int to a JsNumber" in {
42.toJson mustEqual JsNumber(42)
}
"convert a JsNumber to an Int" in {
JsNumber(42).fromJson[Int] mustEqual 42
}
}
"The LongJsonFormat" should {
"convert a Long to a JsNumber" in {
42L.toJson mustEqual JsNumber(42L)
}
"convert a JsNumber to a Long" in {
JsNumber(42L).fromJson[Long] mustEqual 42L
}
}
"The FloatJsonFormat" should {
"convert a Float to a JsNumber" in {
4.2f.toJson mustEqual JsNumber(4.2f)
}
"convert a JsNumber to a Float" in {
JsNumber(4.2f).fromJson[Float] mustEqual 4.2f
}
}
"The DoubleJsonFormat" should {
"convert a Double to a JsNumber" in {
4.2.toJson mustEqual JsNumber(4.2)
}
"convert a JsNumber to a Double" in {
JsNumber(4.2).fromJson[Double] mustEqual 4.2
}
}
"The ByteJsonFormat" should {
"convert a Byte to a JsNumber" in {
42.asInstanceOf[Byte].toJson mustEqual JsNumber(42)
}
"convert a JsNumber to a Byte" in {
JsNumber(42).fromJson[Byte] mustEqual 42
}
}
"The ShortJsonFormat" should {
"convert a Short to a JsNumber" in {
42.asInstanceOf[Short].toJson mustEqual JsNumber(42)
}
"convert a JsNumber to a Short" in {
JsNumber(42).fromJson[Short] mustEqual 42
}
}
"The BigDecimalJsonFormat" should {
"convert a BigDecimal to a JsNumber" in {
BigDecimal(42).toJson mustEqual JsNumber(42)
}
"convert a JsNumber to a BigDecimal" in {
JsNumber(42).fromJson[BigDecimal] mustEqual BigDecimal(42)
}
}
"The BigIntJsonFormat" should {
"convert a BigInt to a JsNumber" in {
BigInt(42).toJson mustEqual JsNumber(42)
}
"convert a JsNumber to a BigInt" in {
JsNumber(42).fromJson[BigInt] mustEqual BigInt(42)
}
}
"The UnitJsonFormat" should {
"convert Unit to a JsNumber(1)" in {
().toJson mustEqual JsNumber(1)
}
"convert a JsNumber to Unit" in {
JsNumber(1).fromJson[Unit] mustEqual ()
}
}
"The BooleanJsonFormat" should {
"convert true to a JsTrue" in { true.toJson mustEqual JsTrue }
"convert false to a JsFalse" in { false.toJson mustEqual JsFalse }
"convert a JsTrue to true" in { JsTrue.fromJson[Boolean] mustEqual true }
"convert a JsFalse to false" in { JsFalse.fromJson[Boolean] mustEqual false }
}
"The CharJsonFormat" should {
"convert a Char to a JsString" in {
'c'.toJson mustEqual JsString("c")
}
"convert a JsString to a Char" in {
JsString("c").fromJson[Char] mustEqual 'c'
}
}
"The StringJsonFormat" should {
"convert a String to a JsString" in {
"Hello".toJson mustEqual JsString("Hello")
}
"convert a JsString to a String" in {
JsString("Hello").fromJson[String] mustEqual "Hello"
}
}
"The SymbolJsonFormat" should {
"convert a Symbol to a JsString" in {
'Hello.toJson mustEqual JsString("Hello")
}
"convert a JsString to a Symbol" in {
JsString("Hello").fromJson[Symbol] mustEqual 'Hello
}
}
}
|