Skip to content

Commit 482f36b

Browse files
binkkatalpatil-ashutosh
authored andcommitted
FIX: refactor linebreak test in subtests
1 parent 20c30d4 commit 482f36b

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

regex/rstring/string_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,27 @@ func TestContainsSpecialChars(t *testing.T) {
104104
}
105105

106106
func TestRemoveLineBreaks(t *testing.T) {
107-
input := "One\r,\r\ntwo\u0085 three\u2028!\u2029'"
108-
result := "One,two three!'"
109-
output := rstring.RemoveLineBreaks(input)
110-
diff := reflect.DeepEqual(result, output)
111-
112-
if !diff {
113-
t.Errorf("RemoveLineBreaks(%s) Failed: expected %s, actual %s",
114-
input, result, output)
107+
type test struct {
108+
name string
109+
input string
110+
output string
111+
}
112+
113+
tests := []test{
114+
{name: "MultipleLineBreaks", input: "One\r,\r\ntwo\u0085 three\u2028!\u2029'", output: "One,two three!'"},
115+
{name: "WindowsLineBreak", input: "Win\r\n", output: "Win"},
116+
{name: "MacLineBreak", input: "Mac\r", output: "Mac"},
117+
}
118+
119+
for _, tc := range tests {
120+
tc := tc
121+
t.Run(tc.name, func(t *testing.T) {
122+
result := rstring.RemoveLineBreaks(tc.input)
123+
diff := reflect.DeepEqual(result, tc.output)
124+
if !diff {
125+
t.Errorf("RemoveLineBreaks(%s) Failed: expected %s, actual %s",
126+
tc.input, tc.output, result)
127+
}
128+
})
115129
}
116130
}

0 commit comments

Comments
 (0)