Skip to content

Commit

Permalink
utils.bytes: remove String() and FromString() functions, Go's native …
Browse files Browse the repository at this point in the history
…type conversions are good enough.
  • Loading branch information
Robin Zhong committed Sep 16, 2017
1 parent 7e69d24 commit 4b77caf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
10 changes: 0 additions & 10 deletions utils/bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,3 @@ func FromInt16(v int16) []byte {
binary.BigEndian.PutUint16(b, uint16(v))
return b
}

// string encode []byte
func String(data []byte) string {
return string(data)
}

// FromString decode s.
func FromString(s string) []byte {
return []byte(s)
}
78 changes: 0 additions & 78 deletions utils/bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,81 +598,3 @@ func TestFromInt16(t *testing.T) {
})
}
}

func TestString(t *testing.T) {
type args struct {
data []byte
}
tests := []struct {
name string
args args
want string
}{
{
"empty",
args{[]byte{}},
"",
},
{
"number",
args{[]byte{49, 50}},
"12",
},
{
"letter",
args{[]byte{97, 115}},
"as",
},
{
"special",
args{[]byte{42, 63, 49, 97}},
"*?1a",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := String(tt.args.data); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}

func TestFromString(t *testing.T) {
type args struct {
v string
}
tests := []struct {
name string
args args
wantB []byte
}{
{
"empty",
args{""},
[]byte{},
},
{
"number",
args{"12"},
[]byte{49, 50},
},
{
"letter",
args{"as"},
[]byte{97, 115},
},
{
"special",
args{"*?1a"},
[]byte{42, 63, 49, 97},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotB := FromString(tt.args.v); !reflect.DeepEqual(gotB, tt.wantB) {
t.Errorf("FromInt16() = %v, want %v", gotB, tt.wantB)
}
})
}
}

0 comments on commit 4b77caf

Please sign in to comment.