Move scene shape facts into the scene family
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/candidatejson"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/sourcerange"
|
||||
scenefacts "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/scenedescriptions"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -91,7 +92,7 @@ func validate(value dnd.SceneDescriptionList) error {
|
||||
if strings.TrimSpace(scene.ID) == "" {
|
||||
return fmt.Errorf("%s.id must not be empty", prefix)
|
||||
}
|
||||
if !validSceneKind(scene.Kind) {
|
||||
if !scenefacts.ValidKind(scene.Kind) {
|
||||
return fmt.Errorf("%s.kind must be supported", prefix)
|
||||
}
|
||||
if strings.TrimSpace(scene.Title) == "" {
|
||||
@@ -109,12 +110,3 @@ func validate(value dnd.SceneDescriptionList) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validSceneKind(value dnd.SceneKind) bool {
|
||||
switch value {
|
||||
case dnd.SceneKindCombat, dnd.SceneKindNarrative, dnd.SceneKindRecap, dnd.SceneKindMeta:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,22 @@ func TestCodecCandidatePreservesValidatorOwnedValues(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodecAllowsNonblankUntrimmedFields(t *testing.T) {
|
||||
value := validList()
|
||||
value.Scenes[0].ID = " id "
|
||||
value.Scenes[0].Title = " title "
|
||||
value.Scenes[0].Summary = " summary "
|
||||
value.Scenes[0].SourceRef.SourceID = " source "
|
||||
encoded, err := New().Encode(value)
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want untrimmed nonblank values accepted", err)
|
||||
}
|
||||
decoded, err := New().Decode(encoded)
|
||||
if err != nil || !reflect.DeepEqual(decoded, value) {
|
||||
t.Fatalf("Decode() = %#v, %v", decoded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodecRejectsInvalidDurableRangesWhileCandidatesPreserveThem(t *testing.T) {
|
||||
codec := New()
|
||||
for _, test := range []struct {
|
||||
|
||||
Reference in New Issue
Block a user