reflow-multi-column/main_test.go

58 lines
892 B
Go

package main
import (
"bufio"
"fmt"
"io"
"strings"
"testing"
)
func TestReadPage(t *testing.T) {
cases := map[string]struct {
input string
d rune
want string
err error
}{
"ez": {
input: "helloXworld",
d: 'X',
want: "hello",
err: nil,
},
"eof found": {
input: "helloX",
d: 'X',
want: "hello",
err: nil,
},
"eof not found": {
input: "hello",
d: 'X',
want: "hello",
err: io.EOF,
},
"start of file": {
input: "Xhello",
d: 'X',
want: "",
err: nil,
},
}
for name, d := range cases {
c := d
t.Run(name, func(t *testing.T) {
r := bufio.NewReader(strings.NewReader(c.input))
d := byte(c.d)
got, err := _readPage(d, r)
if fmt.Sprint(err) != fmt.Sprint(c.err) {
t.Fatal(c.err, err)
}
if string(got) != c.want {
t.Fatal(c.want, string(got))
}
})
}
}