Skip to content

Commit 72ed068

Browse files
author
Julien Pivotto
authored
Merge pull request #449 from roidelapluie/test444
expfmt: add test cases for TextParser startOfLine error handling
2 parents 81fdf5b + 69ed1ea commit 72ed068

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

expfmt/text_parse_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package expfmt
1515

1616
import (
17+
"errors"
1718
"math"
1819
"strings"
1920
"testing"
@@ -667,3 +668,39 @@ func BenchmarkParseError(b *testing.B) {
667668
testTextParseError(b)
668669
}
669670
}
671+
672+
func TestTextParserStartOfLine(t *testing.T) {
673+
t.Run("EOF", func(t *testing.T) {
674+
p := TextParser{}
675+
in := strings.NewReader("")
676+
p.reset(in)
677+
fn := p.startOfLine()
678+
if fn != nil {
679+
t.Errorf("Unexpected non-nil function: %v", fn)
680+
}
681+
if p.err != nil {
682+
t.Errorf("Unexpected error: %v", p.err)
683+
}
684+
})
685+
686+
t.Run("OtherError", func(t *testing.T) {
687+
p := TextParser{}
688+
in := &errReader{err: errors.New("unexpected error")}
689+
p.reset(in)
690+
fn := p.startOfLine()
691+
if fn != nil {
692+
t.Errorf("Unexpected non-nil function: %v", fn)
693+
}
694+
if p.err != in.err {
695+
t.Errorf("Unexpected error: %v, expected %v", p.err, in.err)
696+
}
697+
})
698+
}
699+
700+
type errReader struct {
701+
err error
702+
}
703+
704+
func (r *errReader) Read(p []byte) (int, error) {
705+
return 0, r.err
706+
}

0 commit comments

Comments
 (0)