Refactor the D&D spells module to apply deterministic fields where appropriate
This commit is contained in:
@@ -40,6 +40,10 @@ func (ref UnitRef) String() string {
|
||||
return strconv.Itoa(ref.value)
|
||||
}
|
||||
|
||||
func (ref UnitRef) Int() int {
|
||||
return ref.value
|
||||
}
|
||||
|
||||
func (ref *UnitRef) UnmarshalJSON(raw []byte) error {
|
||||
raw = bytes.TrimSpace(raw)
|
||||
if len(raw) == 0 {
|
||||
|
||||
@@ -16,6 +16,9 @@ func TestUnitRefUnmarshalAcceptsIntegerAndNumericString(t *testing.T) {
|
||||
if got := integerRef.String(); got != "12" {
|
||||
t.Fatalf("integer ref = %q, want 12", got)
|
||||
}
|
||||
if got := integerRef.Int(); got != 12 {
|
||||
t.Fatalf("integer ref value = %d, want 12", got)
|
||||
}
|
||||
|
||||
var stringRef UnitRef
|
||||
if err := json.Unmarshal([]byte(`"12"`), &stringRef); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user