...

Source file src/google.golang.org/protobuf/internal/impl/legacy_export_test.go

Documentation: google.golang.org/protobuf/internal/impl

     1  // Copyright 2019 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 impl
     6  
     7  import (
     8  	"bytes"
     9  	"compress/gzip"
    10  	"io/ioutil"
    11  	"math"
    12  	"strings"
    13  	"testing"
    14  )
    15  
    16  func TestCompressGZIP(t *testing.T) {
    17  	tests := []string{
    18  		"",
    19  		"a",
    20  		"ab",
    21  		"abc",
    22  		strings.Repeat("a", math.MaxUint16-1),
    23  		strings.Repeat("b", math.MaxUint16),
    24  		strings.Repeat("c", math.MaxUint16+1),
    25  		strings.Repeat("abcdefghijklmnopqrstuvwxyz", math.MaxUint16-13),
    26  	}
    27  	for _, want := range tests {
    28  		rb := bytes.NewReader(Export{}.CompressGZIP([]byte(want)))
    29  		zr, err := gzip.NewReader(rb)
    30  		if err != nil {
    31  			t.Errorf("unexpected gzip.NewReader error: %v", err)
    32  		}
    33  		b, err := ioutil.ReadAll(zr)
    34  		if err != nil {
    35  			t.Errorf("unexpected ioutil.ReadAll error: %v", err)
    36  		}
    37  		if got := string(b); got != want {
    38  			t.Errorf("output mismatch: got %q, want %q", got, want)
    39  		}
    40  	}
    41  }
    42  

View as plain text