-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_test.go
More file actions
93 lines (85 loc) · 2.06 KB
/
Copy pathutils_test.go
File metadata and controls
93 lines (85 loc) · 2.06 KB
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
87
88
89
90
91
92
93
package aliwepaystat
import "testing"
func TestContains(t *testing.T) {
if !Contains("hello world", "world") {
t.Error("expected true")
}
if Contains("hello", "world") {
t.Error("expected false")
}
if !Contains("abc", "") {
t.Error("empty substr should match")
}
}
func TestContainsAny(t *testing.T) {
if !ContainsAny("hello world", "xyz", "world") {
t.Error("expected true")
}
if ContainsAny("hello", "xyz", "abc") {
t.Error("expected false")
}
if ContainsAny("hello") {
t.Error("no args should return false")
}
}
func TestEitherContainsAny(t *testing.T) {
if !EitherContainsAny("hello", "world", "xyz", "llo") {
t.Error("expected true from s1")
}
if !EitherContainsAny("hello", "world", "xyz", "orl") {
t.Error("expected true from s2")
}
if EitherContainsAny("hello", "world", "xyz", "abc") {
t.Error("expected false")
}
}
func TestReplaceCsvLineFieldsSuffixBlank(t *testing.T) {
input := []byte("hello ,world ,test")
result := ReplaceCsvLineFieldsSuffixBlank(input)
expected := "hello,world,test"
if string(result) != expected {
t.Errorf("got %q, want %q", string(result), expected)
}
// no trailing blanks
input2 := []byte("a,b,c")
result2 := ReplaceCsvLineFieldsSuffixBlank(input2)
if string(result2) != "a,b,c" {
t.Errorf("got %q, want %q", string(result2), "a,b,c")
}
}
func TestRoundFloat(t *testing.T) {
tests := []struct {
input float64
expected float64
}{
{1.23456, 1.2346},
{0.0, 0.0},
{100.0, 100.0},
{1.99999, 2.0},
}
for _, tt := range tests {
got := RoundFloat(tt.input)
if got != tt.expected {
t.Errorf("RoundFloat(%v) = %v, want %v", tt.input, got, tt.expected)
}
}
}
func TestIsInvestment(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"XX财富YY买入ZZ", true},
{"XX基金YY买入ZZ", true},
{"XX股票YY买入ZZ", true},
{"买入基金", false},
{"财富管理", false},
{"", false},
}
for _, tt := range tests {
got := IsInvestment(tt.input)
if got != tt.expected {
t.Errorf("IsInvestment(%q) = %v, want %v", tt.input, got, tt.expected)
}
}
}