aboutsummaryrefslogtreecommitdiff
path: root/internal/player/hardening_removeitem_test.go
blob: 5cb1e4c3028016c9b8196a62dac035d813eb3cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package player

import "testing"

// TestRemoveItemRejectsNonPositive: a non-positive quantity must never mutate
// a stack; a negative value used to increase it.
func TestRemoveItemRejectsNonPositive(t *testing.T) {
	p := New("alice")
	p.SetInvSlot(0, &InventorySlot{ItemID: "coin", Quantity: 5})

	if p.RemoveItem("coin", -3) {
		t.Fatal("negative quantity accepted")
	}
	if slot := p.InvSlot(0); slot == nil || slot.Quantity != 5 {
		t.Fatalf("stack mutated by a negative removal: %+v", slot)
	}
	if p.RemoveItem("coin", 0) {
		t.Fatal("zero quantity accepted")
	}
	if slot := p.InvSlot(0); slot == nil || slot.Quantity != 5 {
		t.Fatalf("stack mutated by a zero removal: %+v", slot)
	}
}