-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpad_test.go
89 lines (80 loc) · 1.93 KB
/
pad_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package strutil
import (
"fmt"
"testing"
)
func TestPadLeft(t *testing.T) {
tests := []struct {
width int
input string
pad string
expected string
}{
{10, "lorem", "-", "-----lorem"},
{5, "lorem", "-", "lorem"},
{6, "lorem", ".-", ".lorem"},
{9, "lorem", ".-", ".-.-lorem"},
{10, "lorem", "", "lorem"},
{0, "lorem", "-", "lorem"},
{4, "lorem", "-", "lorem"},
{4, "", "-", "----"},
{6, "lorem", ".-=", ".lorem"},
}
for i, test := range tests {
output := PadLeft(test.input, test.width, test.pad)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExamplePadLeft() {
fmt.Println(PadLeft("lorem", 10, "-"))
// Output: -----lorem
}
func TestPadRight(t *testing.T) {
tests := []struct {
width int
input string
pad string
expected string
}{
{10, "lorem", "-", "lorem-----"},
{5, "lorem", "-", "lorem"},
{6, "lorem", ".-", "lorem."},
{9, "lorem", ".-", "lorem.-.-"},
{10, "lorem", "", "lorem"},
{0, "lorem", "-", "lorem"},
{4, "lorem", "-", "lorem"},
{4, "", "-", "----"},
}
for i, test := range tests {
output := PadRight(test.input, test.width, test.pad)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExamplePadRight() {
fmt.Println(PadRight("lorem", 10, "-"))
// Output: lorem-----
}
func TestPad(t *testing.T) {
tests := []struct {
width int
input string
leftPad string
rightPad string
expected string
}{
{9, "lorem", "-", "-", "--lorem--"},
{10, "lorem", ".-", "-.", ".-lorem-.-"},
{1, "lorem", ".-", "-.", "lorem"},
{4, "", ".-", "-.", ".--."},
{10, "lorem", "", "", "lorem"},
{10, "lorem", "-", "", "-----lorem"},
}
for i, test := range tests {
output := Pad(test.input, test.width, test.leftPad, test.rightPad)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExamplePad() {
fmt.Println(Pad("lorem", 9, "-", "-"))
// Output: --lorem--
}