Skip to content

Commit

Permalink
Improve coverage on newly added hexbyte functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-garrett committed Feb 19, 2017
1 parent 29b4a40 commit 3bd5d13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 2 additions & 4 deletions quotedprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ func (qp *qpCleaner) Read(dest []byte) (n int, err error) {
case b == '=':
// pass valid hex bytes through
hexBytes, err := qp.in.Peek(2)
if err != nil {
if err != io.EOF {
return 0, err
}
if err != nil && err != io.EOF {
return 0, err
}
if isValidHexBytes(hexBytes) {
dest[n] = b
Expand Down
21 changes: 21 additions & 0 deletions quotedprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package enmime

import (
"bytes"
"errors"
"io"
"strings"
"testing"
Expand All @@ -19,6 +20,8 @@ func TestQPCleaner(t *testing.T) {
{"\r\n\t", "\r\n\t"},
{"pédagogues", "p=C3=A9dagogues"},
{"Stuffs’s", "Stuffs=E2=80=99s"},
{"=", "=3D"},
{"=a", "=3Da"},
}

for _, tc := range ttable {
Expand Down Expand Up @@ -63,6 +66,24 @@ func TestQPCleanerOverflow(t *testing.T) {
}
}

var PEEK_ERR = errors.New("DIE BART DIE")

type peekBreakReader string

func (r peekBreakReader) Read(p []byte) (int, error) {
return copy(p, r), PEEK_ERR
}

func TestQPPeekError(t *testing.T) {
qp := newQPCleaner(peekBreakReader("=a"))

buf := make([]byte, 100)
_, err := qp.Read(buf)
if err != PEEK_ERR {
t.Errorf("Got: %q, want: %q", err, PEEK_ERR)
}
}

var result int

func BenchmarkQPCleaner(b *testing.B) {
Expand Down

0 comments on commit 3bd5d13

Please sign in to comment.