diff --git a/lib.go b/lib.go index 5227a60..08b6d5e 100644 --- a/lib.go +++ b/lib.go @@ -140,15 +140,6 @@ func (w *Writer) flush() error { return w.err } - if f, ok := w.out.(interface{ Flush() error }); ok { - if err := f.Flush(); err != nil { - w.err = err - return w.err - } - } else if f, ok := w.out.(interface{ Flush() }); ok { - f.Flush() - } - return nil } @@ -169,10 +160,7 @@ func (w *Writer) WriteRune(r rune) (int, error) { // Flush makes the underlying editors to release their associated state, and writes out the resulting text to // the underlying io.Writer, but first passes it to the subsequent editors for editing. When the used editor // instances comply with the expectations of the Editor interface, the writer will have a fresh state and can be -// reused for further editing. -// -// If the underlying io.Writer also implements Flusher (Flush() error or Flush()), then it will be implicitly -// called. +// reused for further editing. The Flush method of underlying writers is not called. func (w *Writer) Flush() error { return w.flush() } diff --git a/lib_test.go b/lib_test.go index 5294628..8e534c4 100644 --- a/lib_test.go +++ b/lib_test.go @@ -139,7 +139,7 @@ func TestFailingWriter(t *testing.T) { } func TestFlush(t *testing.T) { - t.Run("with err succeed", func(t *testing.T) { + t.Run("with err", func(t *testing.T) { var b bytes.Buffer fw := flusherWriter{out: &b} w := textedit.New(&fw, textedit.Replace("o", "e")) @@ -155,22 +155,8 @@ func TestFlush(t *testing.T) { t.Fatal(b.String()) } - if !fw.flushed { - t.Fatal("failed to flush underlying flusher") - } - }) - - t.Run("with err fail", func(t *testing.T) { - var b bytes.Buffer - fw := flusherWriter{out: &b} - w := textedit.New(&fw, textedit.Replace("o", "e")) - if _, err := w.Write([]byte("foo bar")); err != nil { - t.Fatal(err) - } - - fw.fail = true - if err := w.Flush(); !errors.Is(err, errTest) { - t.Fatal("failed to fail with the right error", err) + if fw.flushed { + t.Fatal("should not flush") } }) @@ -190,8 +176,8 @@ func TestFlush(t *testing.T) { t.Fatal(b.String()) } - if !fw.flushed { - t.Fatal("failed to flush underlying flusher") + if fw.flushed { + t.Fatal("should not flush") } }) }