-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converters_test.go
67 lines (52 loc) · 1.57 KB
/
converters_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gosl
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var resultConvertersString string
var resultConvertersByte []byte
func BenchmarkToString_HelloWorld(b *testing.B) {
var r string
for i := 0; i < b.N; i++ {
r, _ = ToString([]byte(`hello, world`))
}
resultConvertersString = r
}
func BenchmarkToBytes_HelloWorld(b *testing.B) {
var r []byte
for i := 0; i < b.N; i++ {
r, _ = ToBytes("hello, world")
}
resultConvertersByte = r
}
func TestToString(t *testing.T) {
_, err := ToString(nil)
require.Error(t, err)
s, err := ToString([]byte(`hello, world`))
require.NoError(t, err)
assert.EqualValues(t, s, "hello, world", "should be equal")
assert.NotEqual(t, s, "wrong", "should not be equal")
g := Utility{} // tests for method
_, err = g.ToString(nil)
require.Error(t, err)
s, err = g.ToString([]byte(`hello, world`))
require.NoError(t, err)
assert.EqualValues(t, s, "hello, world", "should be equal")
assert.NotEqual(t, s, "wrong", "should not be equal")
}
func TestToBytes(t *testing.T) {
_, err := ToBytes("")
require.Error(t, err)
b, err := ToBytes("hello, world")
require.NoError(t, err)
assert.EqualValues(t, b, []byte(`hello, world`), "should be equal")
assert.NotEqual(t, b, []byte(`wrong`), "should not be equal")
g := Utility{} // tests for method
_, err = g.ToBytes("")
require.Error(t, err)
b, err = g.ToBytes("hello, world")
require.NoError(t, err)
assert.EqualValues(t, b, []byte(`hello, world`), "should be equal")
assert.NotEqual(t, b, []byte(`wrong`), "should not be equal")
}