MCPcopy Create free account
hub / github.com/github/gh-aw / TestNormalizeWhitespace

Function TestNormalizeWhitespace

pkg/stringutil/stringutil_test.go:101–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func TestNormalizeWhitespace(t *testing.T) {
102 tests := []struct {
103 name string
104 content string
105 expected string
106 }{
107 {
108 name: "no trailing whitespace",
109 content: "hello\nworld",
110 expected: "hello\nworld\n",
111 },
112 {
113 name: "trailing spaces on lines",
114 content: "hello \nworld ",
115 expected: "hello\nworld\n",
116 },
117 {
118 name: "trailing tabs on lines",
119 content: "hello\t\nworld\t",
120 expected: "hello\nworld\n",
121 },
122 {
123 name: "multiple trailing newlines",
124 content: "hello\nworld\n\n\n",
125 expected: "hello\nworld\n",
126 },
127 {
128 name: "empty string",
129 content: "",
130 expected: "",
131 },
132 {
133 name: "single newline",
134 content: "\n",
135 expected: "",
136 },
137 {
138 name: "mixed whitespace",
139 content: "hello \t\nworld \t \n\n",
140 expected: "hello\nworld\n",
141 },
142 {
143 name: "content with no newline",
144 content: "hello world",
145 expected: "hello world\n",
146 },
147 {
148 name: "content already normalized",
149 content: "hello\nworld\n",
150 expected: "hello\nworld\n",
151 },
152 }
153
154 for _, tt := range tests {
155 t.Run(tt.name, func(t *testing.T) {
156 result := NormalizeWhitespace(tt.content)
157 assert.Equal(t, tt.expected, result, "NormalizeWhitespace(%q) should normalize trailing whitespace and newlines", tt.content)
158 })

Callers

nothing calls this directly

Calls 2

NormalizeWhitespaceFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected