github.com/robhaswell/grandperspective-scan@v0.1.0/test/go-go1.7.1/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  }
    40  
    41  func TestResetDict(t *testing.T) {
    42  	dict := []byte("the lorem fox")
    43  	ss := []string{
    44  		"lorem ipsum izzle fo rizzle",
    45  		"the quick brown fox jumped over",
    46  	}
    47  
    48  	deflated := make([]bytes.Buffer, len(ss))
    49  	for i, s := range ss {
    50  		w, _ := NewWriterDict(&deflated[i], DefaultCompression, dict)
    51  		w.Write([]byte(s))
    52  		w.Close()
    53  	}
    54  
    55  	inflated := make([]bytes.Buffer, len(ss))
    56  
    57  	f := NewReader(nil)
    58  	for i := range inflated {
    59  		f.(Resetter).Reset(&deflated[i], dict)
    60  		io.Copy(&inflated[i], f)
    61  	}
    62  	f.Close()
    63  
    64  	for i, s := range ss {
    65  		if s != inflated[i].String() {
    66  			t.Errorf("inflated[%d]:\ngot  %q\nwant %q", i, inflated[i], s)
    67  		}
    68  	}
    69  }