github.com/grailbio/base@v0.0.11/iofmt/prefixwriter_test.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package iofmt
     6  
     7  import (
     8  	"bytes"
     9  	"io"
    10  	"testing"
    11  )
    12  
    13  func TestPrefixWriter(t *testing.T) {
    14  	var b bytes.Buffer
    15  	w := PrefixWriter(&b, "prefix: ")
    16  	io.WriteString(w, "hello")
    17  	io.WriteString(w, "\nworld\n\n")
    18  	io.WriteString(w, "another\ntest\nthere\n")
    19  	if got, want := b.String(), `prefix: hello
    20  prefix: world
    21  prefix: 
    22  prefix: another
    23  prefix: test
    24  prefix: there
    25  `; got != want {
    26  		t.Errorf("got %q, want %q", got, want)
    27  	}
    28  }