github.com/wangyougui/gf/v2@v2.6.5/encoding/gcompress/gcompress_z_unit_zlib_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gcompress_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/encoding/gcompress"
    13  	"github.com/wangyougui/gf/v2/test/gtest"
    14  )
    15  
    16  func Test_Zlib_UnZlib(t *testing.T) {
    17  	gtest.C(t, func(t *gtest.T) {
    18  		src := "hello, world\n"
    19  		dst := []byte{120, 156, 202, 72, 205, 201, 201, 215, 81, 40, 207, 47, 202, 73, 225, 2, 4, 0, 0, 255, 255, 33, 231, 4, 147}
    20  		data, _ := gcompress.Zlib([]byte(src))
    21  		t.Assert(data, dst)
    22  
    23  		data, _ = gcompress.UnZlib(dst)
    24  		t.Assert(data, []byte(src))
    25  
    26  		data, _ = gcompress.Zlib(nil)
    27  		t.Assert(data, nil)
    28  		data, _ = gcompress.UnZlib(nil)
    29  		t.Assert(data, nil)
    30  
    31  		data, _ = gcompress.UnZlib(dst[1:])
    32  		t.Assert(data, nil)
    33  	})
    34  }