aboutsummaryrefslogtreecommitdiff
path: root/internal/world/p2_hardening_test.go
blob: 01f8a049c5334ed0e80a43ca53afb8460ed7fbfd (plain)
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
package world

import (
	"testing"

	"gopkg.in/yaml.v3"
)

// TestRoomObjectRejectsUnknownField: RoomObject.UnmarshalYAML uses
// Node.Decode, which does not inherit KnownFields(true), so without an
// explicit check a misspelled field inside a room's objects: entry is
// silently discarded even though the top-level room file is strict.
func TestRoomObjectRejectsUnknownField(t *testing.T) {
	var ro RoomObject
	if err := yaml.Unmarshal([]byte("name: anvil\nin_room_description: typo\n"), &ro); err == nil {
		t.Fatal("accepted an unknown room object field")
	}
	// A legitimate local object still parses.
	if err := yaml.Unmarshal([]byte("name: anvil\ninroom_description: A heavy anvil.\n"), &ro); err != nil {
		t.Fatalf("rejected a valid local object: %v", err)
	}
}

// TestSeedGroundItemsDoesNotMarkUnloadedRoom: a room that fails to load must
// not be marked seeded, or its item_spawns stay disabled for the rest of the
// process even after the room file is fixed/created.
func TestSeedGroundItemsDoesNotMarkUnloadedRoom(t *testing.T) {
	w := New(t.TempDir())
	w.SeedGroundItems(999)
	if w.seeded[999] {
		t.Fatal("a room that failed to load was marked seeded; its spawns would never appear")
	}
}