-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7778aca
commit f4254bd
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package field | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Entries map[Field]Structure | ||
|
||
// String returns the string representation of an Entries value. | ||
func (e Entries) String() string { | ||
s := new(strings.Builder) | ||
s.WriteString("Entries:\n") | ||
|
||
for k, v := range e { | ||
ks := fmt.Sprintf("%s:", k.String()) | ||
s.WriteString(fmt.Sprintf("\t%-14s %v,\n", ks, v)) | ||
} | ||
|
||
return s.String() | ||
} | ||
|
||
// GoString returns the Go syntax representation of an Entries value. | ||
func (e Entries) GoString() string { | ||
s := new(strings.Builder) | ||
s.WriteString("field.Entries{\n") | ||
|
||
for k, v := range e { | ||
ks := fmt.Sprintf("%#v:", k) | ||
s.WriteString(fmt.Sprintf("\t%-14s %#v,\n", ks, v)) | ||
} | ||
|
||
s.WriteRune('}') | ||
return s.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package field | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestEntries_StringInterfaces(t *testing.T) { | ||
assert.Implements(t, (*fmt.Stringer)(nil), new(Entries)) | ||
assert.Implements(t, (*fmt.GoStringer)(nil), new(Entries)) | ||
} | ||
|
||
func TestEntries_String(t *testing.T) { | ||
f := Reflectivity | ||
fString := fmt.Sprintf("%s:", f) | ||
|
||
s := Structure{ | ||
Type: TypeUint8, | ||
Offset: 1, | ||
ValueMask: 0xF, | ||
Shift: 32, | ||
} | ||
|
||
e := Entries{f: s} | ||
want := fmt.Sprintf("Entries:\n\t%-14s %v,\n", fString, s) | ||
got := e.String() | ||
|
||
assert.Equal(t, want, got, "it should return the correct representation") | ||
} | ||
|
||
func TestEntries_GoString(t *testing.T) { | ||
f := Reflectivity | ||
fString := fmt.Sprintf("%#v:", f) | ||
|
||
s := Structure{ | ||
Type: TypeUint8, | ||
Offset: 1, | ||
ValueMask: 0xF, | ||
Shift: 32, | ||
} | ||
|
||
e := Entries{f: s} | ||
want := fmt.Sprintf("field.Entries{\n\t%-14s %#v,\n}", fString, s) | ||
got := e.GoString() | ||
|
||
assert.Equal(t, want, got, "it should return the correct representation") | ||
} |