diff options
Diffstat (limited to 'internal/world/room_test.go')
| -rw-r--r-- | internal/world/room_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/world/room_test.go b/internal/world/room_test.go index 855eba5..893f858 100644 --- a/internal/world/room_test.go +++ b/internal/world/room_test.go @@ -6,6 +6,8 @@ import ( "testing" "gopkg.in/yaml.v3" + "thehouseoficarus/internal/behavior" + "thehouseoficarus/internal/object" ) func writeRoom(t *testing.T, dir string, body string) { @@ -137,3 +139,32 @@ func TestExitDefUnmarshalAlwaysBlocked(t *testing.T) { t.Error("east exit should not have AlwaysBlocked") } } + +func TestRoomObjectMarshalYAMLRoundTripsWander(t *testing.T) { + ro := RoomObject{ + ID: "fence", + WanderRooms: []int{2, 3}, + WanderInterval: 5, + Local: &object.ObjectDef{ + Name: "fence", + Description: behavior.DescList{{Text: "A fence."}}, + }, + } + data, err := yaml.Marshal(ro) + if err != nil { + t.Fatalf("marshal: %v", err) + } + var out RoomObject + if err := yaml.Unmarshal(data, &out); err != nil { + t.Fatalf("unmarshal: %v", err) + } + if len(out.WanderRooms) != 2 || out.WanderRooms[0] != 2 || out.WanderRooms[1] != 3 { + t.Fatalf("wander_rooms round trip = %v, want [2 3]", out.WanderRooms) + } + if out.WanderInterval != 5 { + t.Fatalf("wander_interval round trip = %v, want 5", out.WanderInterval) + } + if out.Local == nil || out.Local.Name != "fence" { + t.Fatalf("local object lost: %+v", out.Local) + } +} |
