package main import ( "bufio" "bytes" "fmt" "io" "strings" "testing" ) func Test_Main(t *testing.T) { input := "\ta a a\t\tb b b\na a\t\tb b\fc c\td d\nc c\td." stdin = strings.NewReader(input) stdout = bytes.NewBuffer(nil) columnDelimiter = "\t" pageDelimiter = "\f" minimumInstances = 1 if err := _main(); err != nil { t.Error(err) } t.Logf("input:\n%s", input) t.Logf("result:\n%s", stdout.(*bytes.Buffer).Bytes()) } 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)) } }) } }