github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/src/compress/flate/inflate_test.go (about)

     1  // Copyright 2014 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 flate
     6  
     7  import (
     8  	"bytes"
     9  	"io"
    10  	"testing"
    11  )
    12  
    13  func TestReset(t *testing.T) {
    14  	ss := []string{
    15  		"lorem ipsum izzle fo rizzle",
    16  		"the quick brown fox jumped over",
    17  	}
    18  
    19  	deflated := make([]bytes.Buffer, 2)
    20  	for i, s := range ss {
    21  		w, _ := NewWriter(&deflated[i], 1)
    22  		w.Write([]byte(s))
    23  		w.Close()
    24  	}
    25  
    26  	inflated := make([]bytes.Buffer, 2)
    27  
    28  	f := NewReader(&deflated[0])
    29  	io.Copy(&inflated[0], f)
    30  	f.(Resetter).Reset(&deflated[1], nil)
    31  	io.Copy(&inflated[1], f)
    32  	f.Close()
    33  
    34  	for i, s := range ss {
    35  		if s != inflated[i].String() {
    36  			t.Errorf("inflated[%d]:\ngot  %q\nwant %q", i, inflated[i], s)
    37  		}
    38  	}
    39  }