Repository navigation
Expand file tree
/
Copy pathitems_test.go
More file actions
88 lines (79 loc) · 2.01 KB
/
Copy pathitems_test.go
File metadata and controls
88 lines (79 loc) · 2.01 KB
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
package pokemonbattlelib
import (
"encoding/json"
"math"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("Using items", func() {
DescribeTable("should correctly retrieve items by ID",
func(item Item, name string) {
Expect(item.Name()).To(Equal(name))
},
Entry("No item", ItemNone, ""),
Entry("Potion", ItemPotion, "Potion"),
Entry("Flame orb", ItemFlameOrb, "Flame Orb"),
)
It("should panic if item is invalid", func() {
Expect(func() { Item(math.MaxUint16).Data() }).To(Panic())
})
})
var _ = Describe("Item Marshalling and Unmarshalling", func() {
entries := []TableEntry{
Entry("None", ItemNone),
Entry("Potion", ItemPotion),
Entry("Oran Berry", ItemOranBerry),
Entry("Ultra Ball", ItemUltraBall),
}
DescribeTable("should marshall and unmarshall items",
func(i Item) {
b, err := json.Marshal(i)
Expect(err).To(Succeed())
var got Item
err = json.Unmarshal(b, &got)
Expect(err).To(Succeed())
Expect(got).To(BeEquivalentTo(i))
},
entries...,
)
DescribeTable("marshalled items should include data",
func(i Item) {
b, err := json.Marshal(i)
Expect(err).To(Succeed())
var got ItemData
err = json.Unmarshal(b, &got)
Expect(err).To(Succeed())
Expect(got.Name).To(BeEquivalentTo(i.Name()))
Expect(got.Flags).To(BeEquivalentTo(i.Flags()))
},
entries...,
)
DescribeTable("unmarshalling items should accept just the ID",
func(i Item) {
b, err := json.Marshal(uint16(i))
Expect(err).To(Succeed())
var got Item
err = json.Unmarshal(b, &got)
Expect(err).To(Succeed())
Expect(got).To(BeEquivalentTo(i))
},
entries...,
)
DescribeTable("unmarshalling items should accept a struct with an Id field",
func(i Item) {
item := struct {
Id uint16
}{
Id: uint16(i),
}
b, err := json.Marshal(item)
Expect(err).To(Succeed())
var got Item
err = json.Unmarshal(b, &got)
Expect(err).To(Succeed())
Expect(got).To(BeEquivalentTo(i))
},
entries...,
)
})