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
|
package textutils
import "testing"
func TestCollapseInlineCodeContent(t *testing.T) {
runs := []struct {
desc string
input string
expected string
}{
{
desc: "empty",
input: "",
expected: "",
},
{
desc: "not needed",
input: "a b",
expected: "a b",
},
{
desc: "one newline",
input: "a\nb",
expected: "a b",
},
{
desc: "multiple newlines",
input: "a\nb\n\nc",
expected: "a b c",
},
{
desc: "also trim",
input: " a b ",
expected: "a b",
},
{
desc: "realistic code content",
input: `
body {
color: yellow;
font-size: 16px;
}
`,
expected: "body { color: yellow; font-size: 16px; }",
},
}
for _, run := range runs {
t.Run(run.desc, func(t *testing.T) {
actual := CollapseInlineCodeContent([]byte(run.input))
if string(actual) != run.expected {
t.Errorf("expected %q but got %q", run.expected, string(actual))
}
})
}
}
|