Skip to content

Commit

Permalink
Merge pull request #449 from roidelapluie/test444
Browse files Browse the repository at this point in the history
expfmt: add test cases for TextParser startOfLine error handling
  • Loading branch information
roidelapluie committed Feb 21, 2023
2 parents 81fdf5b + 69ed1ea commit 72ed068
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions expfmt/text_parse_test.go
Expand Up @@ -14,6 +14,7 @@
package expfmt

import (
"errors"
"math"
"strings"
"testing"
Expand Down Expand Up @@ -667,3 +668,39 @@ func BenchmarkParseError(b *testing.B) {
testTextParseError(b)
}
}

func TestTextParserStartOfLine(t *testing.T) {
t.Run("EOF", func(t *testing.T) {
p := TextParser{}
in := strings.NewReader("")
p.reset(in)
fn := p.startOfLine()
if fn != nil {
t.Errorf("Unexpected non-nil function: %v", fn)
}
if p.err != nil {
t.Errorf("Unexpected error: %v", p.err)
}
})

t.Run("OtherError", func(t *testing.T) {
p := TextParser{}
in := &errReader{err: errors.New("unexpected error")}
p.reset(in)
fn := p.startOfLine()
if fn != nil {
t.Errorf("Unexpected non-nil function: %v", fn)
}
if p.err != in.err {
t.Errorf("Unexpected error: %v, expected %v", p.err, in.err)
}
})
}

type errReader struct {
err error
}

func (r *errReader) Read(p []byte) (int, error) {
return 0, r.err
}

0 comments on commit 72ed068

Please sign in to comment.