-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringy_test.go
60 lines (50 loc) · 1.42 KB
/
stringy_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
package listy_test
import (
"testing"
"github.com/xdg/listy"
"github.com/xdg/testy"
)
func TestSJoin(t *testing.T) {
is := testy.New(t)
defer func() { t.Logf(is.Done()) }()
cases := []struct {
Label string
Input []string
Sep string
Output string
}{
{Label: "empty list", Input: []string{}, Sep: " ", Output: ""},
{Label: "one item", Input: []string{"one"}, Sep: " ", Output: "one"},
{Label: "two items", Input: []string{"one", "two"}, Sep: " ", Output: "one two"},
{Label: "three items", Input: []string{"one", "two", "three"}, Sep: " ", Output: "one two three"},
}
for _, v := range cases {
xs := listy.S(v.Input)
got := xs.Join(v.Sep)
is.Label(v.Label).Equal(got, v.Output)
}
}
func TestBSJoin(t *testing.T) {
is := testy.New(t)
defer func() { t.Logf(is.Done()) }()
cases := []struct {
Label string
Input []string
Sep string
Output string
}{
{Label: "empty list", Input: []string{}, Sep: " ", Output: ""},
{Label: "one item", Input: []string{"one"}, Sep: " ", Output: "one"},
{Label: "two items", Input: []string{"one", "two"}, Sep: " ", Output: "one two"},
{Label: "three items", Input: []string{"one", "two", "three"}, Sep: " ", Output: "one two three"},
}
for _, v := range cases {
bs := make([][]byte, 0)
for _, v := range v.Input {
bs = append(bs, []byte(v))
}
xs := listy.BS(bs)
got := xs.Join([]byte(v.Sep))
is.Label(v.Label).Equal(got, []byte(v.Output))
}
}