Add candidate artifact codec decoding
This commit is contained in:
@@ -112,6 +112,39 @@ func TestCodecCandidatePreservesInvalidTypedValues(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodecCandidateDecodeOwnsValues(t *testing.T) {
|
||||
codec := New()
|
||||
input := validList()
|
||||
content, err := codec.EncodeCandidate(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first, err := codec.DecodeCandidate(content)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := codec.DecodeCandidate(content)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nameOffset := bytes.Index(content, []byte("Mira Thorn"))
|
||||
if nameOffset < 0 {
|
||||
t.Fatal("candidate JSON does not contain NPC name")
|
||||
}
|
||||
content[nameOffset] = 'X'
|
||||
if first.NPCs[0].Name != "Mira Thorn" {
|
||||
t.Fatal("DecodeCandidate() retained input bytes")
|
||||
}
|
||||
first.NPCs[0].Name = "changed"
|
||||
first.NPCs[0].SourceRefs[0].SourceID = "changed"
|
||||
if input.NPCs[0].Name != "Mira Thorn" || input.NPCs[0].SourceRefs[0].SourceID != "session-alpha" {
|
||||
t.Fatal("DecodeCandidate() retained input values")
|
||||
}
|
||||
if second.NPCs[0].Name != "Mira Thorn" || second.NPCs[0].SourceRefs[0].SourceID != "session-alpha" {
|
||||
t.Fatal("DecodeCandidate() returned aliased values")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodecRejectsEveryRequiredShapeBoundary(t *testing.T) {
|
||||
base := validList().NPCs[0]
|
||||
tests := []struct {
|
||||
|
||||
Reference in New Issue
Block a user