forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbers_test.go
67 lines (53 loc) · 1.53 KB
/
numbers_test.go
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
package openrtb
import (
"encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("NumberOrString", func() {
It("should decode numbers", func() {
var n NumberOrString
Expect(json.Unmarshal([]byte(`33`), &n)).To(Succeed())
Expect(n).To(Equal(NumberOrString(33)))
})
It("should decode strings", func() {
var n NumberOrString
Expect(json.Unmarshal([]byte(`"33"`), &n)).To(Succeed())
Expect(n).To(Equal(NumberOrString(33)))
})
It("should encode to numbers", func() {
var n NumberOrString = 33
bin, err := json.Marshal(n)
Expect(err).NotTo(HaveOccurred())
Expect(string(bin)).To(Equal(`33`))
})
})
var _ = Describe("StringOrNumber", func() {
It("should decode numbers", func() {
var n StringOrNumber
Expect(json.Unmarshal([]byte(`33`), &n)).To(Succeed())
Expect(n).To(Equal(StringOrNumber("33")))
})
It("should decode strings", func() {
var n StringOrNumber
Expect(json.Unmarshal([]byte(`"33"`), &n)).To(Succeed())
Expect(n).To(Equal(StringOrNumber("33")))
})
It("should decode strings", func() {
var n StringOrNumber
Expect(json.Unmarshal([]byte(`""`), &n)).To(Succeed())
Expect(n).To(Equal(StringOrNumber("")))
})
It("should encode to strings", func() {
var n StringOrNumber = "33"
bin, err := json.Marshal(n)
Expect(err).NotTo(HaveOccurred())
Expect(string(bin)).To(Equal(`"33"`))
})
It("should encode to strings", func() {
var n StringOrNumber = ""
bin, err := json.Marshal(n)
Expect(err).NotTo(HaveOccurred())
Expect(string(bin)).To(Equal(`""`))
})
})