Add NPC interaction normalization
This commit is contained in:
@@ -185,6 +185,33 @@ func TestAppendNPCListsPreservesOrderAndArrayPresence(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendNPCInteractionListsPreservesOrderPresenceAndOwnership(t *testing.T) {
|
||||
refs := []source.SourceRef{{SourceID: "session", StartUnitID: 10, EndUnitID: 10}}
|
||||
input := []dnd.NPCInteractionList{
|
||||
{},
|
||||
{Interactions: []dnd.NPCInteraction{}},
|
||||
{Interactions: []dnd.NPCInteraction{{Name: "Aria", Kind: dnd.NPCInteractionKindDialogue, SourceRefs: refs}}},
|
||||
{Interactions: []dnd.NPCInteraction{{Name: "Borin", Kind: dnd.NPCInteractionKindMentioned, SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 20, EndUnitID: 20}}}}},
|
||||
}
|
||||
got, err := appendNPCInteractionLists(input)
|
||||
if err != nil {
|
||||
t.Fatalf("appendNPCInteractionLists() error = %v", err)
|
||||
}
|
||||
if got.Interactions == nil || !reflect.DeepEqual([]string{got.Interactions[0].Name, got.Interactions[1].Name}, []string{"Aria", "Borin"}) {
|
||||
t.Fatalf("combined interactions = %#v", got)
|
||||
}
|
||||
got.Interactions[0].SourceRefs[0].StartUnitID = 999
|
||||
if input[2].Interactions[0].SourceRefs[0].StartUnitID == 999 {
|
||||
t.Fatal("merged interactions share source reference storage")
|
||||
}
|
||||
for _, values := range [][]dnd.NPCInteractionList{nil, []dnd.NPCInteractionList{{}, {}}} {
|
||||
result, err := appendNPCInteractionLists(values)
|
||||
if err != nil || result.Interactions != nil {
|
||||
t.Fatalf("nil-only merge = %#v, %v; want nil interactions", result, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendCombatTurnListsPreservesOrderPresenceAndOwnership(t *testing.T) {
|
||||
refs := []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}
|
||||
input := []dnd.CombatTurnList{
|
||||
|
||||
Reference in New Issue
Block a user