-
Notifications
You must be signed in to change notification settings - Fork 26
/
substring_test.go
50 lines (44 loc) · 1.13 KB
/
substring_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
package strutil
import (
"fmt"
"testing"
)
func TestMustSubstring(t *testing.T) {
tests := []struct {
input string
start int
end int
expected string
mustPanic bool
}{
{"lorem", 0, 1, "l", false},
{"", 0, 1, "", true},
{"lorem", 0, 5, "lorem", false},
{"lorem", 0, 10, "", true},
{"lorem", -1, 4, "", true},
{"lorem", 9, 10, "", true},
{"lorem", 4, 3, "", true},
{"Υπάρχουν", 1, 4, "πάρ", false},
{"Υπάρχουν", 1, 0, "πάρχουν", false},
{"Υπάρχουν", 1, 9, "", true},
{"žůžo", 1, 4, "ůžo", false},
}
for i, test := range tests {
if test.mustPanic {
AssertPanics(t, func() {
_ = MustSubstring(test.input, test.start, test.end)
}, "Test case %d is not successful\n", i)
} else {
output := MustSubstring(test.input, test.start, test.end)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
}
func ExampleMustSubstring() {
fmt.Println(MustSubstring("Υπάρχουν", 1, 4))
// Output: πάρ
}
func ExampleMustSubstring_tillTheEnd() {
fmt.Println(MustSubstring("Υπάρχουν", 1, 0))
// Output: πάρχουν
}