feat: first commit
1 file changed, 51 insertions(+), 0 deletions(-)
changed files
A format_test.go
@@ -0,0 +1,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) + } + }) + } +}