-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
28 lines (26 loc) · 979 Bytes
/
main_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
package main
import "testing"
func TestReplaceHead(t *testing.T) {
cases := []struct {
target, replaceWith, in, want string
}{
{`[ \t]+`, " ", "no space", "no space"},
{`[ \t]+`, " ", " 1 half", " 1 half"},
{`[ \t]+`, " ", " 1 full", " 1 full"},
{`[ \t]+`, " ", " 1 tab", " 1 tab"},
{`[ \t]+`, " ", " 1 half 1 full 1 tab (3)", " 1 half 1 full 1 tab (3)"},
{`[ \t]+`, "ABC", "no space", "no space"},
{`[ \t]+`, "ABC", " 1 half", "ABC1 half"},
{`[ \t]+`, "ABC", " 1 full", "ABC1 full"},
{`[ \t]+`, "ABC", " 1 tab", "ABC1 tab"},
{`[ \t]+`, "ABC", " 1 half 1 full 1 tab (3)", "ABCABCABC1 half 1 full 1 tab (3)"},
{`[a-z]+`, "ABC", "no space", "ABCABC space"},
{`[a-z]+`, "ABC", " 1 tab", " 1 tab"},
}
for _, c := range cases {
got := ReplaceHead(c.in, c.target, c.replaceWith)
if got != c.want {
t.Errorf("ReplaceHead(%q, %q, %q) == %q, want %q", c.in, c.target, c.replaceWith, got, c.want)
}
}
}