Add candidate artifact codec decoding
This commit is contained in:
@@ -24,6 +24,7 @@ const (
|
||||
var schemaAssets embed.FS
|
||||
|
||||
var _ contracts.ArtifactCodec[dnd.ItemOccurrenceList] = (*Codec)(nil)
|
||||
var _ contracts.CandidateArtifactCodec[dnd.ItemOccurrenceList] = (*Codec)(nil)
|
||||
|
||||
type Codec struct{}
|
||||
|
||||
|
||||
@@ -124,14 +124,29 @@ func TestCodecDeepCopiesBoundaryValuesAndMetadata(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sibling, err := codec.DecodeCandidate(content)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if decoded.Occurrences[1].Quantity == value.Occurrences[1].Quantity || &decoded.Occurrences[1].SourceRefs[0] == &value.Occurrences[1].SourceRefs[0] {
|
||||
t.Fatal("DecodeCandidate() retained caller-owned occurrence fields")
|
||||
}
|
||||
nameOffset := bytes.Index(content, []byte("Gold Pieces"))
|
||||
if nameOffset < 0 {
|
||||
t.Fatal("candidate JSON does not contain item name")
|
||||
}
|
||||
content[nameOffset] = 'X'
|
||||
if decoded.Occurrences[1].Name != "Gold Pieces" {
|
||||
t.Fatal("DecodeCandidate() retained input bytes")
|
||||
}
|
||||
*decoded.Occurrences[1].Quantity = 99
|
||||
decoded.Occurrences[1].SourceRefs[0].SourceID = "changed"
|
||||
if *value.Occurrences[1].Quantity != 12 || value.Occurrences[1].SourceRefs[0].SourceID != "session" {
|
||||
t.Fatal("decoded item occurrence aliases input")
|
||||
}
|
||||
if *sibling.Occurrences[1].Quantity != 12 || sibling.Occurrences[1].SourceRefs[0].SourceID != "session" {
|
||||
t.Fatal("decoded item occurrence aliases a sibling decode")
|
||||
}
|
||||
|
||||
first := codec.Schema()
|
||||
first.JSONSchema[0] = '['
|
||||
|
||||
Reference in New Issue
Block a user