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
|
package game
import (
"strings"
"testing"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func TestLookMiniMapLongContentWrapsWithoutCollision(t *testing.T) {
// A long status line (for example a room fixture's live table overview)
// must wrap before the map column instead of writing through it.
for _, side := range []string{"right", "left"} {
t.Run(side, func(t *testing.T) {
p := player.New("alice")
p.Options = map[string]any{"tiny_map": side, "wrap_width": 80}
conn := &casinoTestConn{}
sess := &net.Session{Player: p, Conn: conn}
long := "Roulette / Single zero | Limits 1-10000 | 1/8 seated | Betting open and the wheel is spinning right now"
content := []string{long}
mapLines := []string{"╔═════╗", "║□-□-□║", "║ ↑ ║", "║ @ ║", "║ │ ║", "║ ■ ║", "╚═════╝"}
(&Game{}).writeLookSideBySide(sess, p, content, mapLines, 71)
lines := strings.Split(strings.TrimSuffix(string(conn.data), "\r\n"), "\r\n")
if len(lines) < len(mapLines) {
t.Fatalf("got %d lines, want at least %d", len(lines), len(mapLines))
}
for i, line := range lines[:len(mapLines)] {
index := strings.Index(line, mapLines[i])
if index < 0 {
t.Fatalf("line %d missing map row: %q", i, line)
}
want := 73
if side == "left" {
want = 0
}
if got := visibleLen(line[:index]); got != want {
t.Errorf("line %d: map column = %d, want %d (content collided)", i, got, want)
}
}
})
}
}
func TestLookMiniMapAlignment(t *testing.T) {
for _, side := range []string{"right", "left"} {
for _, colored := range []bool{false, true} {
t.Run(side+map[bool]string{false: "/plain", true: "/colored"}[colored], func(t *testing.T) {
p := player.New("alice")
p.Options = map[string]any{"tiny_map": side, "wrap_width": 80}
conn := &casinoTestConn{}
sess := &net.Session{Player: p, Conn: conn}
content := wrapText("A ceiling of tiny brass suns hangs over polished stone. Icarus Leisure’s emblem repeats on every column. Stairs and galleries are open to all visitors.", 71)
if colored {
for i := range content {
content[i] = color.Render("xterm256", color.ColorSpec{Fg: 42, Bg: -1}, content[i])
}
}
mapLines := []string{"╔═════╗", "║□-□-□║", "║ ↑ ║", "║ @ ║", "║ │ ║", "║ ■ ║", "╚═════╝"}
(&Game{}).writeLookSideBySide(sess, p, content, mapLines, 71)
lines := strings.Split(strings.TrimSuffix(string(conn.data), "\r\n"), "\r\n")
if len(lines) != len(mapLines) {
t.Fatalf("got %d lines, want %d: %q", len(lines), len(mapLines), conn.data)
}
for i, line := range lines {
index := strings.Index(line, mapLines[i])
if index < 0 {
t.Fatalf("line %d missing map row: %q", i, line)
}
want := 73
if side == "left" {
want = 0
}
if got := visibleLen(line[:index]); got != want {
t.Errorf("line %d: map column = %d, want %d", i, got, want)
}
}
})
}
}
}
|