-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain_test.go
135 lines (117 loc) · 3.79 KB
/
main_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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
package tmx
import (
"os"
"path"
"testing"
)
func TestDecoder(t *testing.T) {
file, err := os.Open(path.Join("fixtures", "test.tmx"))
if err != nil {
t.Fatalf(err.Error())
}
m, err := Decode(file)
if err != nil {
t.Fatalf(err.Error())
}
if m == nil {
t.Fatalf("map was nil")
}
if walls := m.LayerWithName("walls"); walls != nil {
trs, err := walls.TileGlobalRefs()
if err != nil {
t.Error(err)
}
if l, e := len(trs), m.Width*m.Height; l != e {
t.Errorf("expected tiles of length %v, got %v", e, l)
}
tds, err := walls.TileDefs(m.TileSets)
if err != nil {
t.Error(err)
}
// we have three known tiles and IDs as our first few tiles; check those
type Expected struct {
tsName string
tID TileID
HorizontallyFlipped bool
VerticallyFlipped bool
DiagonallyFlipped bool
}
exp := []Expected{
Expected{"temp", 142, false, false, false},
Expected{"temp", 141, false, false, false},
Expected{"temp", 141, false, false, false},
Expected{"temp", 127, false, false, false},
Expected{"temp", 127, true, false, true},
Expected{"temp", 127, true, true, false},
Expected{"temp", 127, false, true, true},
Expected{"temp", 127, false, false, false},
}
for i, e := range exp {
tile := tds[i]
if tile.TileSet.Name != e.tsName {
t.Errorf("idx(%v): expected tileset named `%v`, got `%v`", i, e.tsName, tile.TileSet.Name)
}
if tile.ID != e.tID {
t.Errorf("idx(%v): expected tile id `%v`, got `%v`", i, e.tID, tile.ID)
}
if tile.HorizontallyFlipped != e.HorizontallyFlipped {
t.Errorf("idx(%v): expected tile to be horizontally flipped: %v", i, e.HorizontallyFlipped)
}
if tile.VerticallyFlipped != e.VerticallyFlipped {
t.Errorf("idx(%v): expected tile to be vertically flipped: %v", i, e.VerticallyFlipped)
}
if tile.DiagonallyFlipped != e.DiagonallyFlipped {
t.Errorf("idx(%v): expected tile to be diagonally flipped: %v", i, e.DiagonallyFlipped)
}
}
} else {
t.Error("expected layer with name `walls`, but found none.")
}
if nonSolid := m.LayerWithName("non-solid"); nonSolid != nil {
trs, err := nonSolid.TileGlobalRefs()
if err != nil {
t.Error(err)
}
if l, e := len(trs), m.Width*m.Height; l != e {
t.Errorf("expected tiles of length %v, got %v", e, l)
}
} else {
t.Error("expected layer with name `non-solid`, but found none.")
}
if players := m.ObjectGroupWithName("players"); players != nil {
} else {
t.Error("expected objectgroup with name `players`, but found none.")
}
if ts := m.TileSetWithName("temp"); ts != nil {
} else {
t.Error("expected tileset with name `temp`, but found none.")
}
if enemies := m.ObjectGroupWithName("enemies"); enemies != nil {
if enemy := enemies.Objects.WithName("enemy1"); enemy != nil {
if cool, err := enemy.Properties.Bool("cool"); err != nil {
t.Errorf("unexpected error getting property `cool`")
} else if cool != true {
t.Errorf("expected property `cool` to be true")
}
if velX, err := enemy.Properties.Float("velX"); err != nil {
t.Errorf("unexpected error getting property `velX`")
} else if velX != 1.1 {
t.Errorf("expected property `velX` to have value `1.1`")
}
if health, err := enemy.Properties.Int("health"); err != nil {
t.Errorf("unexpected error getting property `health`")
} else if health != 100 {
t.Errorf("expected property `health` to have value `100`")
}
if food := enemy.Properties.WithName("food"); food == nil {
t.Error("expected to find property named food, found none.")
} else if food.Value != "pizza" {
t.Error("expected property `food` to have value `pizza`")
}
} else {
t.Errorf("expected object with name `enemy1`, but found none.")
}
} else {
t.Error("expected objectgroup with name `enemies`, but found none.")
}
}