-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanstring_test.go
More file actions
62 lines (58 loc) · 1.43 KB
/
cleanstring_test.go
File metadata and controls
62 lines (58 loc) · 1.43 KB
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
package cleanstring
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCleanstring(t *testing.T) {
type testCase struct {
Description string
Input string
Expected string
}
testCases := []testCase{
{
Description: "Non-matching strings should be unmodified.",
Input: "foo",
Expected: "foo",
},
{
Description: "Whitespace-only prefix lines should be stripped.",
Input: "\n\nfoo",
Expected: "foo",
},
{
Description: "Different whitespaces should be stripped",
Input: "\n\n\t\n \t \nfoo",
Expected: "foo",
},
{
Description: "Trailing whitespace should be stripped",
Input: "foo\n\n",
Expected: "foo",
},
{
Description: "Prefixes should be stripped",
Input: " |foo",
Expected: "foo",
},
{
Description: "Whitespace-only suffix lines should be stripped",
Input: " |foo\n\n \n",
Expected: "foo",
},
{
Description: "Prefix and suffix lines are trimmed but intermediate lines are untouched",
Input: "\n\n |foo\n\n |bar\n\n",
Expected: "foo\n\nbar",
},
{
Description: "Whitespace only prefix lines preserve whitespace",
Input: "\n\n |foo\n | \n |bar\n\n",
Expected: "foo\n \nbar",
},
}
for _, tc := range testCases {
output := Get(tc.Input)
require.Equal(t, tc.Expected, output, tc.Description)
}
}