-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathother_test.go
83 lines (67 loc) · 1.89 KB
/
other_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package just_test
import (
"bytes"
"github.com/kazhuravlev/just"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
"regexp"
"testing"
)
func TestBool(t *testing.T) {
t.Parallel()
t.Run("bool", func(t *testing.T) {
assert.True(t, just.Bool(true))
assert.False(t, just.Bool(false))
})
t.Run("int", func(t *testing.T) {
assert.True(t, just.Bool(int(1)))
assert.True(t, just.Bool(int8(1)))
assert.True(t, just.Bool(int16(1)))
assert.True(t, just.Bool(int32(1)))
assert.True(t, just.Bool(int64(1)))
assert.False(t, just.Bool(int(0)))
assert.False(t, just.Bool(int8(0)))
assert.False(t, just.Bool(int16(0)))
assert.False(t, just.Bool(int32(0)))
assert.False(t, just.Bool(int64(0)))
})
t.Run("uint", func(t *testing.T) {
assert.True(t, just.Bool(uint(1)))
assert.True(t, just.Bool(uint8(1)))
assert.True(t, just.Bool(uint16(1)))
assert.True(t, just.Bool(uint32(1)))
assert.True(t, just.Bool(uint64(1)))
assert.False(t, just.Bool(uint(0)))
assert.False(t, just.Bool(uint8(0)))
assert.False(t, just.Bool(uint16(0)))
assert.False(t, just.Bool(uint32(0)))
assert.False(t, just.Bool(uint64(0)))
})
t.Run("float", func(t *testing.T) {
assert.True(t, just.Bool(float32(1)))
assert.True(t, just.Bool(float64(1)))
assert.False(t, just.Bool(float32(0)))
assert.False(t, just.Bool(float64(0)))
})
t.Run("uintptr", func(t *testing.T) {
assert.True(t, just.Bool(uintptr(1)))
assert.False(t, just.Bool(uintptr(0)))
})
t.Run("string", func(t *testing.T) {
assert.True(t, just.Bool("1"))
assert.False(t, just.Bool(""))
})
}
func TestMust(t *testing.T) {
t.Run("success", func(t *testing.T) {
const str = "this is body!"
val := just.Must(io.ReadAll(bytes.NewBufferString(str)))
assert.Equal(t, str, string(val))
})
t.Run("panic", func(t *testing.T) {
require.Panics(t, func() {
just.Must(regexp.Compile("["))
})
})
}