From 4b77caf5909daa8b381990f2432e64c3ba29867b Mon Sep 17 00:00:00 2001 From: Robin Zhong Date: Sun, 17 Sep 2017 01:03:40 +0800 Subject: [PATCH] utils.bytes: remove String() and FromString() functions, Go's native type conversions are good enough. --- utils/bytes/bytes.go | 10 ----- utils/bytes/bytes_test.go | 78 --------------------------------------- 2 files changed, 88 deletions(-) diff --git a/utils/bytes/bytes.go b/utils/bytes/bytes.go index 127737379..5ad679b79 100644 --- a/utils/bytes/bytes.go +++ b/utils/bytes/bytes.go @@ -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) -} diff --git a/utils/bytes/bytes_test.go b/utils/bytes/bytes_test.go index 48c16d9b0..cb230c348 100644 --- a/utils/bytes/bytes_test.go +++ b/utils/bytes/bytes_test.go @@ -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) - } - }) - } -}