Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions field_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func (m FieldMap) SetField(tag Tag, field FieldValueWriter) FieldMap {
return m
}

//SetInt is a SetField wrapper for int fields
func (m FieldMap) SetInt(tag Tag, value int) FieldMap {
return m.SetField(tag, FIXInt(value))
}

//SetString is a SetField wrapper for string fields
func (m FieldMap) SetString(tag Tag, value string) FieldMap {
return m.SetField(tag, FIXString(value))
}

//Clear purges all fields from field map
func (m *FieldMap) Clear() {
m.tagLookup = make(map[Tag]TagValues)
Expand Down
34 changes: 34 additions & 0 deletions field_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,37 @@ func TestFieldMap_Total(t *testing.T) {
t.Error("Total should includes all fields but checkSum- got ", fMap.total())
}
}

func TestFieldMap_TypedSetAndGet(t *testing.T) {
var fMap FieldMap
fMap.init()

fMap.SetString(1, "hello")
fMap.SetInt(2, 256)

s, err := fMap.GetString(1)
if err != nil {
t.Error("Unexpected Error", err)
} else if s != "hello" {
t.Errorf("Expected %v got %v", "hello", s)
}

i, err := fMap.GetInt(2)
if err != nil {
t.Error("Unexpected Error", err)
} else if i != 256 {
t.Errorf("Expected %v got %v", 256, i)
}

_, err = fMap.GetInt(1)
if err == nil {
t.Error("Type mismatch should occur error but nil")
}

s, err = fMap.GetString(2)
if err != nil {
t.Error("Type mismatch should occur error but nil")
} else if s != "256" {
t.Errorf("Expected %v got %v", "256", s)
}
}