-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitespace_test.go
98 lines (95 loc) · 2.8 KB
/
whitespace_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
90
91
92
93
94
95
96
97
98
package main
import (
"testing"
)
func TestRemoveWhitespace(t *testing.T) {
tests := []struct {
name string
input string
removeSpaces bool
removeTabs bool
removeCR bool
removeNewlines bool
removeEmptyLines bool
expected string
}{
{
name: "Remove spaces",
input: "Hello, World!",
removeSpaces: true,
removeTabs: false,
removeCR: false,
removeNewlines: false,
removeEmptyLines: false,
expected: "Hello,World!",
},
{
name: "Remove tabs",
input: "Hello,\tWorld!",
removeSpaces: false,
removeTabs: true,
removeCR: false,
removeNewlines: false,
removeEmptyLines: false,
expected: "Hello,World!",
},
{
name: "Remove carriage returns",
input: "Hello,\rWorld!",
removeSpaces: false,
removeTabs: false,
removeCR: true,
removeNewlines: false,
removeEmptyLines: false,
expected: "Hello,World!",
},
{
name: "Remove newlines",
input: "Hello,\nWorld!",
removeSpaces: false,
removeTabs: false,
removeCR: false,
removeNewlines: true,
removeEmptyLines: false,
expected: "Hello,World!",
},
{
name: "Remove all whitespace characters",
input: "Hello,\tWorld!\r\nThis is a test.\nWith multiple lines\tand spaces.",
removeSpaces: true,
removeTabs: true,
removeCR: true,
removeNewlines: true,
removeEmptyLines: false,
expected: "Hello,World!Thisisatest.Withmultiplelinesandspaces.",
},
{
name: "Remove empty lines",
input: "Hello,\tWorld!\r\nThis is a test.\n\nWith multiple lines\tand spaces.\n\n \nAnother line.",
removeSpaces: false,
removeTabs: false,
removeCR: false,
removeNewlines: false,
removeEmptyLines: true,
expected: "Hello,\tWorld!\r\nThis is a test.\nWith multiple lines\tand spaces.\nAnother line.",
},
{
name: "Remove all whitespace characters and empty lines",
input: "Hello,\tWorld!\r\nThis is a test.\n\nWith multiple lines\tand spaces.\n\n \nAnother line.",
removeSpaces: true,
removeTabs: true,
removeCR: true,
removeNewlines: true,
removeEmptyLines: true,
expected: "Hello,World!Thisisatest.Withmultiplelinesandspaces.Anotherline.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := removeWhitespace(tt.input, tt.removeSpaces, tt.removeTabs, tt.removeCR, tt.removeNewlines, tt.removeEmptyLines)
if result != tt.expected {
t.Errorf("Expected '%s', but got '%s'", tt.expected, result)
}
})
}
}