format_test.go (view raw)
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 | package htmlformat
import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestFormat(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "html elements are indented",
input: `<ol> <li style="&"> A </li> <li> B </li> </ol> `,
expected: `<ol>
<li style="&">
A
</li>
<li>
B
</li>
</ol>
`,
},
{
name: "text fragments are supported",
input: `test 123`,
expected: `test 123` + "\n",
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
r := strings.NewReader(test.input)
w := new(strings.Builder)
if err := Fragment(w, r); err != nil {
t.Fatalf("failed to format: %v", err)
}
if diff := cmp.Diff(test.expected, w.String()); diff != "" {
t.Error(diff)
}
})
}
}
|