-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_test.go
More file actions
82 lines (78 loc) · 1.52 KB
/
capture_test.go
File metadata and controls
82 lines (78 loc) · 1.52 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bytes"
"testing"
)
func TestWriteInSingleLineUnsafe(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "no newlines",
input: "hello world",
expected: "hello world",
},
{
name: "single newline in middle",
input: "hello\nworld",
expected: "hello world",
},
{
name: "multiple newlines",
input: "hello\nworld\ntest",
expected: "hello world test",
},
{
name: "consecutive newlines",
input: "hello\n\nworld",
expected: "hello world",
},
{
name: "newline at start",
input: "\nhello",
expected: " hello",
},
{
name: "newline at end",
input: "hello\n",
expected: "hello ",
},
{
name: "newline at both ends",
input: "\nhello\n",
expected: " hello ",
},
{
name: "empty string",
input: "",
expected: "",
},
{
name: "only newlines",
input: "\n\n\n",
expected: " ",
},
{
name: "complex multiline text",
input: "SELECT *\nFROM users\nWHERE id = 1",
expected: "SELECT * FROM users WHERE id = 1",
},
{
name: "text with trailing newlines",
input: "query text\n\n",
expected: "query text ",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
writeInSingleLineUnsafe(&buf, tt.input)
got := buf.String()
if got != tt.expected {
t.Errorf("writeInSingleLineUnsafe() = %q, want %q", got, tt.expected)
}
})
}
}