...
Run Format

Source file src/net/textproto/writer_test.go

Documentation: net/textproto

     1  // Copyright 2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package textproto
     6  
     7  import (
     8  	"bufio"
     9  	"bytes"
    10  	"testing"
    11  )
    12  
    13  func TestPrintfLine(t *testing.T) {
    14  	var buf bytes.Buffer
    15  	w := NewWriter(bufio.NewWriter(&buf))
    16  	err := w.PrintfLine("foo %d", 123)
    17  	if s := buf.String(); s != "foo 123\r\n" || err != nil {
    18  		t.Fatalf("s=%q; err=%s", s, err)
    19  	}
    20  }
    21  
    22  func TestDotWriter(t *testing.T) {
    23  	var buf bytes.Buffer
    24  	w := NewWriter(bufio.NewWriter(&buf))
    25  	d := w.DotWriter()
    26  	n, err := d.Write([]byte("abc\n.def\n..ghi\n.jkl\n."))
    27  	if n != 21 || err != nil {
    28  		t.Fatalf("Write: %d, %s", n, err)
    29  	}
    30  	d.Close()
    31  	want := "abc\r\n..def\r\n...ghi\r\n..jkl\r\n..\r\n.\r\n"
    32  	if s := buf.String(); s != want {
    33  		t.Fatalf("wrote %q", s)
    34  	}
    35  }
    36  

View as plain text