github.com/grailbio/base@v0.0.11/tsv/writer_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 tsv_test
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  
    11  	"github.com/grailbio/base/tsv"
    12  )
    13  
    14  func TestWriter(t *testing.T) {
    15  	var buf bytes.Buffer
    16  	tw := tsv.NewWriter(&buf)
    17  	tw.WriteString("field1")
    18  	tw.WriteUint32(2)
    19  	tw.WritePartialString("field")
    20  	tw.WriteByte('3')
    21  	tw.WriteBytes([]byte{'f', 'i', 'e', 'l', 'd', '4'})
    22  	tw.WriteFloat64(1.2345, 'G', 6)
    23  	tw.WriteInt64(123456)
    24  	err := tw.EndLine()
    25  	if err != nil {
    26  		t.Errorf("Error while adding end of line")
    27  	}
    28  	tw.Flush()
    29  	got := buf.String()
    30  	want := "field1\t2\tfield3\tfield4\t1.2345\t123456\n"
    31  	if got != want {
    32  		t.Errorf("got: %q, want %q", got, want)
    33  	}
    34  }