-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools_test.go
86 lines (72 loc) · 1.63 KB
/
tools_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
84
85
86
package fly
import (
"fmt"
"testing"
"time"
)
func TestIsChanClosed(t *testing.T) {
t.Run("close chantools", func(t *testing.T) {
ch := make(chan struct{})
close(ch)
println(IfChanClosed(ch))
if !IfChanClosed(ch) {
t.Errorf("should be true a closed channel")
}
})
t.Run("open and close chantools", func(t *testing.T) {
ch := make(chan int, 1)
fmt.Println(IfChanClosed(ch)) // 输出: false
if IfChanClosed(ch) {
t.Errorf("should be false a open channel")
}
close(ch)
println(IfChanClosed(ch))
if !IfChanClosed(ch) {
t.Errorf("should be true a closed channel")
}
})
t.Run("ifeatsign", func(t *testing.T) {
ch := make(chan struct{}, 1)
go func() {
time.Sleep(2 * time.Second)
select {
case <-ch:
println("receive chantools")
}
time.Sleep(10 * time.Second)
}()
go func() {
IfChanClosed(ch)
time.Sleep(3 * time.Second)
}()
ch <- struct{}{}
time.Sleep(20 * time.Second)
})
}
func TestStringToBytes(t *testing.T) {
t.Run("chstr2bytes", func(t *testing.T) {
//https://www.toolhelper.cn/EncodeDecode/EncodeDecode
str := "你好"
bytes := QuickStringToBytes(str)
for _, b := range bytes {
println(b)
}
})
t.Run("enstr2bytes", func(t *testing.T) {
str := "hello,world"
bytes := QuickStringToBytes(str)
for _, b := range bytes {
println(b)
}
})
t.Run("bytes2chstr", func(t *testing.T) {
b := []byte{0xe4, 0xbd, 0xa0}
toString := QuickBytesToString(b)
println(toString)
})
t.Run("bytes2enstr", func(t *testing.T) {
b := []byte{104, 101, 108, 108, 111, 44, 119, 111, 114, 108, 100}
toString := QuickBytesToString(b)
println(toString)
})
}