diff options
Diffstat (limited to 'internal/world/fix_regressions_test.go')
| -rw-r--r-- | internal/world/fix_regressions_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/world/fix_regressions_test.go b/internal/world/fix_regressions_test.go index f2ef795..770d2ef 100644 --- a/internal/world/fix_regressions_test.go +++ b/internal/world/fix_regressions_test.go @@ -151,3 +151,64 @@ func TestRekeyRoomsRemapsHomeRoomID(t *testing.T) { t.Fatalf("HomeRoomID after rekey = %d, want 3", moved.HomeRoomID) } } + +// TestSetObjPropsMatchHomeRoomNotCurrentRoom: content edits pass the declaring +// room, so property setters must match on HomeRoomID rather than the object's +// current RoomID (which differs while it has wandered away). +func TestSetObjPropsMatchHomeRoomNotCurrentRoom(t *testing.T) { + w := New(t.TempDir()) + w.objStates[w.ObjStateKey(2, "anvil", 0)] = &ObjState{ + RoomID: 2, + HomeRoomID: 1, + DefID: "anvil", + Index: 0, + } + w.SetObjName(1, "anvil", "iron anvil") + w.SetObjAliases(1, "anvil", []string{"workbench"}) + w.SetObjWander(1, "anvil", []int{2, 3}, 4) + w.SetObjDepleteTimer(1, "anvil", 7) + + st := w.GetObjState(2, "anvil", 0) + if st.Name != "iron anvil" { + t.Fatalf("name not applied: %+v", st) + } + if len(st.Aliases) != 1 || st.Aliases[0] != "workbench" { + t.Fatalf("aliases not applied: %+v", st) + } + if len(st.WanderRooms) != 2 || st.WanderInterval != 4 { + t.Fatalf("wander not applied: %+v", st) + } + if st.SharedMax != 7 { + t.Fatalf("deplete timer not applied: %+v", st) + } +} + +// TestTickObjWanderSkipsOccupiedDestination: a wandering instance whose +// destination key is already occupied must not evict the occupant for the +// process lifetime. +func TestTickObjWanderSkipsOccupiedDestination(t *testing.T) { + w := New(t.TempDir()) + w.AddRoomPath(1, "room-1") + w.AddRoomPath(2, "room-2") + w.objStates[w.ObjStateKey(2, "anvil", 0)] = &ObjState{ + RoomID: 2, + HomeRoomID: 2, + DefID: "anvil", + Index: 0, + } + w.objStates[w.ObjStateKey(1, "anvil", 0)] = &ObjState{ + RoomID: 1, + HomeRoomID: 1, + DefID: "anvil", + Index: 0, + WanderRooms: []int{2}, + WanderInterval: 1, + } + w.TickObjWander() + if w.GetObjState(2, "anvil", 0) == nil { + t.Fatal("destination occupant was evicted by a colliding wanderer") + } + if w.GetObjState(1, "anvil", 0) == nil { + t.Fatal("wanderer was lost instead of skipping the occupied destination") + } +} |
