forked from lrstanley/bubblezone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoneinfo_test.go
132 lines (109 loc) · 2.89 KB
/
zoneinfo_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
// Copyright (c) Liam Stanley <[email protected]>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package zone
import (
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
)
func TestValidPosition(t *testing.T) {
// Starts at X:4, Y:2, ends at X:12, Y:3.
_ = Scan("test\nfoo\naaa " + Mark("foo", "bar\ntest123456789") + " aaa\nbaz")
time.Sleep(100 * time.Millisecond)
xy := Get("foo")
if xy.IsZero() {
t.Error("rid not found")
}
if xy.StartX != 4 || xy.StartY != 2 || xy.EndX != 12 || xy.EndY != 3 {
t.Errorf("got %#v, want %#v", xy, &ZoneInfo{
id: xy.id,
rid: xy.rid,
iteration: xy.iteration,
StartX: 4,
StartY: 2,
EndX: 12,
EndY: 3,
})
}
}
func TestInBounds(t *testing.T) {
// Starts at X:4, Y:2, ends at X:12, Y:3.
_ = Scan("test\nfoo\naaa " + Mark("foo", "bar\ntest123456789") + " aaa\nbaz")
time.Sleep(100 * time.Millisecond)
xy := Get("foo")
if xy.IsZero() {
t.Error("rid not found")
}
// Outside left.
if xy.InBounds(tea.MouseMsg{X: 0, Y: 0}) {
t.Error("expected false")
}
// Outside directly left.
if xy.InBounds(tea.MouseMsg{X: 3, Y: 3}) {
t.Error("expected false")
}
// Outside right.
if xy.InBounds(tea.MouseMsg{X: 99, Y: 99}) {
t.Error("expected false")
}
// Outside directly right.
if xy.InBounds(tea.MouseMsg{X: 13, Y: 3}) {
t.Error("expected false")
}
// Outside top.
if xy.InBounds(tea.MouseMsg{X: 4, Y: 1}) {
t.Error("expected false")
}
// Outside bottom.
if xy.InBounds(tea.MouseMsg{X: 4, Y: 4}) {
t.Error("expected false")
}
// Inside left top.
if !xy.InBounds(tea.MouseMsg{X: 4, Y: 2}) {
t.Error("expected true")
}
// Inside right bottom.
if !xy.InBounds(tea.MouseMsg{X: 12, Y: 3}) {
t.Error("expected true")
}
_ = Scan("test " + Mark("foo", "bar\nt") + " other things here")
time.Sleep(100 * time.Millisecond)
xy = Get("foo")
if xy.InBounds(tea.MouseMsg{X: 2, Y: 1}) {
t.Error("expected false")
}
}
func TestInBoundsZero(t *testing.T) {
xy := &ZoneInfo{}
if xy.InBounds(tea.MouseMsg{X: 0, Y: 0}) {
t.Error("expected false")
}
xy = Get("non-existent")
if xy.InBounds(tea.MouseMsg{X: 0, Y: 0}) {
t.Error("expected false")
}
}
func TestPos(t *testing.T) {
// Starts at X:4, Y:2, ends at X:12, Y:3.
_ = Scan("test\nfoo\naaa " + Mark("foo", "bar\ntest123456789") + " aaa\nbaz")
time.Sleep(100 * time.Millisecond)
xy := Get("foo")
if xy.IsZero() {
t.Error("rid not found")
}
if x, y := xy.Pos(tea.MouseMsg{X: 4, Y: 2}); x != 0 || y != 0 {
t.Error("expected 0, 0")
}
if x, y := xy.Pos(tea.MouseMsg{X: 5, Y: 2}); x != 1 || y != 0 {
t.Error("expected 1, 0")
}
xy = &ZoneInfo{}
if x, y := xy.Pos(tea.MouseMsg{X: 0, Y: 0}); x != -1 || y != -1 {
t.Error("expected -1, -1")
}
xy = Get("non-existent")
if x, y := xy.Pos(tea.MouseMsg{X: 0, Y: 0}); x != -1 || y != -1 {
t.Error("expected -1, -1")
}
}