1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-25 17:05:23 +00:00
v2fly/common/serial/string_test.go

60 lines
1.0 KiB
Go
Raw Normal View History

2018-02-19 22:01:00 +00:00
package serial_test
import (
"errors"
"testing"
2019-01-08 22:27:02 +00:00
"github.com/google/go-cmp/cmp"
2021-02-16 20:31:50 +00:00
. "github.com/v2fly/v2ray-core/v4/common/serial"
2018-02-19 22:01:00 +00:00
)
func TestToString(t *testing.T) {
s := "a"
data := []struct {
Value interface{}
String string
}{
{Value: s, String: s},
{Value: &s, String: s},
{Value: errors.New("t"), String: "t"},
2018-11-02 14:50:41 +00:00
{Value: []byte{'b', 'c'}, String: "[98 99]"},
2018-02-19 22:01:00 +00:00
}
for _, c := range data {
2019-01-08 22:27:02 +00:00
if r := cmp.Diff(ToString(c.Value), c.String); r != "" {
t.Error(r)
}
2018-02-19 22:01:00 +00:00
}
}
2018-10-01 10:42:14 +00:00
func TestConcat(t *testing.T) {
testCases := []struct {
Input []interface{}
Output string
}{
{
Input: []interface{}{
"a", "b",
},
Output: "ab",
},
}
for _, testCase := range testCases {
actual := Concat(testCase.Input...)
if actual != testCase.Output {
t.Error("Unexpected output: ", actual, " but want: ", testCase.Output)
}
}
}
func BenchmarkConcat(b *testing.B) {
input := []interface{}{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = Concat(input...)
}
}