-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin_test.go
73 lines (60 loc) · 1.91 KB
/
join_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
61
62
63
64
65
66
67
68
69
70
71
72
73
package slices2_test
import (
"fmt"
"testing"
"github.com/Pilatuz/slices2"
)
// ExampleJoin an example for `Join` function.
func ExampleJoin() {
s := slices2.Join(
[]string{"foo", "bar"},
[]string{"baz"})
fmt.Println(s)
// Output:
// [foo bar baz]
}
// TestJoin unit tests for `Join` function.
func TestJoin(tt *testing.T) {
// string
tt.Run("str", func(t *testing.T) {
var Nil []string
Empty := []string{}
Foo := []string{"foo"}
Bar := []string{"bar"}
FooBar := []string{"foo", "bar"}
test := func(expected []string, aa ...[]string) {
t.Helper()
if actual := slices2.Join(aa...); !equal(actual, expected) {
t.Errorf("Join(`%#v`)=`%#v`, expected `%#v`", aa, actual, expected)
}
}
test(Nil) // Join() => nil
test(Nil, Nil) // Join(nil) => nil
test(Empty, Empty) // Join([]) => nil
test(Nil, Empty, Nil, Empty) // Join([], nil, []) => nil
test(Foo, Nil, Foo, Empty) // Join(nil, [foo], []) => [foo]
test(Bar, Nil, Bar, Empty) // Join(nil, [bar], []) => [bar]
test(FooBar, Nil, Foo, Bar, Empty) // Join(nil, [foo] [bar], []) => [foo bar]
})
// integer
tt.Run("int", func(t *testing.T) {
var Nil []int
Empty := []int{}
Foo := []int{123}
Bar := []int{456}
FooBar := []int{123, 456}
test := func(expected []int, aa ...[]int) {
t.Helper()
if actual := slices2.Join(aa...); !equal(actual, expected) {
t.Errorf("Join(`%#v`)=`%#v`, expected `%#v`", aa, actual, expected)
}
}
test(Nil) // Join() => nil
test(Nil, Nil) // Join(nil) => nil
test(Empty, Empty) // Join([]) => nil
test(Nil, Empty, Nil, Empty) // Join([], nil, []) => nil
test(Foo, Nil, Foo, Empty) // Join(nil, [foo], []) => [foo]
test(Bar, Nil, Bar, Empty) // Join(nil, [bar], []) => [bar]
test(FooBar, Nil, Foo, Bar, Empty) // Join(nil, [foo] [bar], []) => [foo bar]
})
}