-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_test.go
78 lines (68 loc) · 1.59 KB
/
string_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
package tips
import (
"errors"
"testing"
)
func TestStrPos(t *testing.T) {
str := "hello world go tips"
i := StrPos(str, "wo")
if i == -1 {
t.Error("strings StrPos expect index >= 0; not -1")
}
i = StrPos(str, "v")
if i != -1 {
t.Error("strings StrPos expect -1 not index >= 0")
}
i = StrPos(str, "tip")
if i == -1 {
t.Error("strings StrPos expect index >= 0; not -1")
}
i = StrPos(str, "tipv")
if i != -1 {
t.Error("strings StrPos expect -1 not index >= 0")
}
i = StrPos(str, "")
if i != 0 {
t.Error("strings StrPos expect 0 not -1", i)
}
}
func TestStrBegin(t *testing.T) {
str := "hello world go tips"
if StrBegin(str, "o") != "hell" {
t.Error("strings StrPos expect hell")
}
if StrBegin(str, "tip") != "hello world go " {
t.Error("strings StrPos expect 'hello world go '")
}
if StrBegin(str, "") != str {
t.Error("strings StrPos expect '", str, "'")
}
if StrBegin(str, " ") != "hello" {
t.Error("strings StrPos expect 'hello'")
}
}
func TestStrEnd(t *testing.T) {
str := "hello world go tips"
if StrEnd(str, "o") != " world go tips" {
t.Error("strings StrPos expect: world go tips")
}
if StrEnd(str, "tip") != "s" {
t.Error("strings StrPos expect:s")
}
if StrEnd(str, "wo") != "rld go tips" {
t.Error("strings StrPos expect:rld go tips")
}
if StrEnd(str, "") != "" {
t.Error("strings StrPos expect:")
}
if StrEnd(str, " ") != "world go tips" {
t.Error("strings StrPos expect:world go tips")
}
}
func TestString(t *testing.T) {
_trr := "error to string"
trr := errors.New(_trr)
if String(trr) != _trr {
t.Fatal("TIPS.String error to string")
}
}