-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_dialog_test.go
More file actions
92 lines (82 loc) · 2.6 KB
/
detect_dialog_test.go
File metadata and controls
92 lines (82 loc) · 2.6 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
89
90
91
92
package awtree
import "testing"
func TestDetect_Dialog_CenteredPanelWithButton(t *testing.T) {
g := NewGrid(24, 80)
topRow, botRow := 8, 14
leftCol, rightCol := 30, 50
g.Set(topRow, leftCol, Cell{Char: '┌'})
g.Set(topRow, rightCol, Cell{Char: '┐'})
g.Set(botRow, leftCol, Cell{Char: '└'})
g.Set(botRow, rightCol, Cell{Char: '┘'})
for c := leftCol + 1; c < rightCol; c++ {
g.Set(topRow, c, Cell{Char: '─'})
g.Set(botRow, c, Cell{Char: '─'})
}
for r := topRow + 1; r < botRow; r++ {
g.Set(r, leftCol, Cell{Char: '│'})
g.Set(r, rightCol, Cell{Char: '│'})
}
g.SetText(topRow, leftCol+2, "─ Confirm ─", DefaultColor, DefaultColor, 0)
g.SetText(12, 38, "[OK]", DefaultColor, DefaultColor, 0)
m := Detect(g)
found := false
for _, el := range m.Elements {
if el.Type == ElementDialog {
found = true
if el.Bounds.Row != topRow || el.Bounds.Col != leftCol {
t.Errorf("dialog bounds start = (%d,%d), want (%d,%d)", el.Bounds.Row, el.Bounds.Col, topRow, leftCol)
}
}
}
if !found {
t.Fatal("dialog not detected for centered panel with button")
}
}
func TestDetect_Dialog_CenteredPanelNoButtons(t *testing.T) {
g := NewGrid(24, 80)
topRow, botRow := 8, 14
leftCol, rightCol := 30, 50
g.Set(topRow, leftCol, Cell{Char: '┌'})
g.Set(topRow, rightCol, Cell{Char: '┐'})
g.Set(botRow, leftCol, Cell{Char: '└'})
g.Set(botRow, rightCol, Cell{Char: '┘'})
for c := leftCol + 1; c < rightCol; c++ {
g.Set(topRow, c, Cell{Char: '─'})
g.Set(botRow, c, Cell{Char: '─'})
}
for r := topRow + 1; r < botRow; r++ {
g.Set(r, leftCol, Cell{Char: '│'})
g.Set(r, rightCol, Cell{Char: '│'})
}
g.SetText(10, 33, "Loading...", DefaultColor, DefaultColor, 0)
m := Detect(g)
for _, el := range m.Elements {
if el.Type == ElementDialog {
t.Fatal("centered panel without buttons should not be detected as dialog")
}
}
}
func TestDetect_Dialog_OffCenterPanelNotDialog(t *testing.T) {
g := NewGrid(24, 80)
topRow, botRow := 8, 14
leftCol, rightCol := 0, 20
g.Set(topRow, leftCol, Cell{Char: '┌'})
g.Set(topRow, rightCol, Cell{Char: '┐'})
g.Set(botRow, leftCol, Cell{Char: '└'})
g.Set(botRow, rightCol, Cell{Char: '┘'})
for c := leftCol + 1; c < rightCol; c++ {
g.Set(topRow, c, Cell{Char: '─'})
g.Set(botRow, c, Cell{Char: '─'})
}
for r := topRow + 1; r < botRow; r++ {
g.Set(r, leftCol, Cell{Char: '│'})
g.Set(r, rightCol, Cell{Char: '│'})
}
g.SetText(12, 5, "[OK]", DefaultColor, DefaultColor, 0)
m := Detect(g)
for _, el := range m.Elements {
if el.Type == ElementDialog {
t.Fatal("off-center panel should not be detected as dialog")
}
}
}