From 3a854c3bc47e75491b836c7fc12b617da5d68288 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 16 Feb 2021 00:30:13 +0100 Subject: Issue #46: Fix semantics of `n` result Per contract, the returned number of bytes written should be the number of bytes _from the input_. Therefore, the added bytes (`\r` or `\n`) shall not count into that number. --- pkg/rfc822/writer_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pkg/rfc822/writer_test.go') diff --git a/pkg/rfc822/writer_test.go b/pkg/rfc822/writer_test.go index 7beae8d..34c9d4a 100644 --- a/pkg/rfc822/writer_test.go +++ b/pkg/rfc822/writer_test.go @@ -34,10 +34,14 @@ func TestRfc822Writer_Write(t *testing.T) { t.Run(tt.before, func(t *testing.T) { b := bytes.Buffer{} w := Writer(&b) - if _, err := io.WriteString(w, tt.before); err != nil { + n, err := io.WriteString(w, tt.before) + if err != nil { t.Errorf("Error: %v", err) return } + if n != len(tt.before) { + t.Errorf("Unexpected number of bytes written: %d, expected: %d", n, len(tt.before)) + } res := b.String() if tt.after != res { t.Errorf("Expected: %q, got: %q", tt.after, res) -- cgit v1.2.3-54-g00ecf