aboutsummaryrefslogtreecommitdiff
path: root/internal/game/map_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/map_test.go')
-rw-r--r--internal/game/map_test.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/internal/game/map_test.go b/internal/game/map_test.go
index a50c2c2..adba595 100644
--- a/internal/game/map_test.go
+++ b/internal/game/map_test.go
@@ -92,3 +92,89 @@ func TestWrapText(t *testing.T) {
}
}
}
+
+func TestBuildFullMap(t *testing.T) {
+ g := &Game{
+ World: world.New("../../data"),
+ MapWidth: 70,
+ }
+
+ tests := []struct {
+ name string
+ roomID int
+ width int
+ height int
+ }{
+ {"room 1 30x20", 1, 30, 20},
+ {"room 1 20x10", 1, 20, 10},
+ {"room 25 30x20", 25, 30, 20},
+ {"min size 5x5", 1, 5, 5},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ lines := buildFullMap(g, tt.roomID, tt.width, tt.height)
+ if len(lines) != tt.height {
+ t.Errorf("expected %d lines, got %d", tt.height, len(lines))
+ }
+ for i, line := range lines {
+ if len([]rune(line)) != tt.width {
+ t.Errorf("line %d: expected %d runes, got %d in %q", i, tt.width, len([]rune(line)), line)
+ }
+ }
+ t.Logf("Room %d %dx%d map:\n%s", tt.roomID, tt.width, tt.height, strings.Join(lines, "\n"))
+ })
+ }
+}
+
+func TestStripBlankRows(t *testing.T) {
+ input := []string{" ", "hello", "", " world ", " "}
+ want := []string{"hello", " world "}
+ got := stripBlankRows(input)
+ if len(got) != len(want) {
+ t.Fatalf("expected %d lines, got %d", len(want), len(got))
+ }
+ for i := range want {
+ if got[i] != want[i] {
+ t.Errorf("line %d: want %q, got %q", i, want[i], got[i])
+ }
+ }
+}
+
+func TestLeftTrimCommon(t *testing.T) {
+ input := []string{" hello", " world", " ", " foo"}
+ got := leftTrimCommon(input)
+ // min leading spaces across non-blank lines: " hello"=4, " world"=4, " foo"=2 → min=2
+ // trim 2 from all lines
+ if got[0] != " hello" {
+ t.Errorf("line 0: want %q, got %q", " hello", got[0])
+ }
+ if got[1] != " world" {
+ t.Errorf("line 1: want %q, got %q", " world", got[1])
+ }
+ if got[2] != "" {
+ t.Errorf("line 2: want %q, got %q", "", got[2])
+ }
+ if got[3] != "foo" {
+ t.Errorf("line 3: want %q, got %q", "foo", got[3])
+ }
+}
+
+func TestLeftTrimCommonEmpty(t *testing.T) {
+ input := []string{" ", "", " "}
+ got := leftTrimCommon(input)
+ if len(got) != 3 {
+ t.Fatalf("expected 3 lines, got %d", len(got))
+ }
+}
+
+func TestLeftTrimCommonZero(t *testing.T) {
+ input := []string{"hello", "world"}
+ got := leftTrimCommon(input)
+ if got[0] != "hello" {
+ t.Errorf("line 0: want %q, got %q", "hello", got[0])
+ }
+ if got[1] != "world" {
+ t.Errorf("line 1: want %q, got %q", "world", got[1])
+ }
+}