forked from go-python/gpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_test.go
More file actions
100 lines (97 loc) · 1.43 KB
/
Copy pathstring_test.go
File metadata and controls
100 lines (97 loc) · 1.43 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
94
95
96
97
98
99
100
// Copyright 2022 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package py
import "testing"
func TestStringFind(t *testing.T) {
for _, tc := range []struct {
str string
sub string
beg int
end int
idx int
}{
{
str: "hello world",
sub: "world",
idx: 6,
},
{
str: "hello world",
sub: "o",
idx: 4,
},
{
str: "hello world",
sub: "o",
beg: 5,
idx: 7,
},
{
str: "hello world",
sub: "bye",
idx: -1,
},
{
str: "Hello, 世界",
sub: "界",
idx: 8,
},
{
str: "01234 6789",
sub: " ",
beg: 6,
idx: -1,
},
{
str: "0123456789",
sub: "6",
beg: 1,
end: 6,
idx: -1,
},
{
str: "0123456789",
sub: "6",
beg: 1,
end: 7,
idx: 6,
},
{
str: "0123456789",
sub: "6",
beg: 1,
end: -1,
idx: 6,
},
{
str: "0123456789",
sub: "6",
beg: 100,
end: -1,
idx: -1,
},
{
str: "0123456789",
sub: "6",
beg: 2,
end: 1,
idx: -1,
},
} {
t.Run(tc.str+":"+tc.sub, func(t *testing.T) {
beg := tc.beg
end := tc.end
if end == 0 {
end = len(tc.str)
}
idx, err := String(tc.str).find(Tuple{String(tc.sub), Int(beg), Int(end)})
if err != nil {
t.Fatalf("invalid: %+v", err)
}
if got, want := int(idx.(Int)), tc.idx; got != want {
t.Fatalf("got=%d, want=%d", got, want)
}
})
}
}