Files
gf/encoding/gcompress/gcompress_z_unit_zlib_test.go

35 lines
911 B
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2019-04-09 19:12:48 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2019-04-09 19:12:48 +08:00
package gcompress_test
import (
2019-06-21 22:23:07 +08:00
"testing"
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/encoding/gcompress"
"github.com/gogf/gf/v2/test/gtest"
2019-04-09 19:12:48 +08:00
)
2020-03-06 15:38:32 +08:00
func Test_Zlib_UnZlib(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-04-18 12:34:01 +08:00
src := "hello, world\n"
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}
2019-06-21 22:23:07 +08:00
data, _ := gcompress.Zlib([]byte(src))
2020-03-19 22:56:12 +08:00
t.Assert(data, dst)
2019-04-09 19:12:48 +08:00
2019-06-21 22:23:07 +08:00
data, _ = gcompress.UnZlib(dst)
2020-03-19 22:56:12 +08:00
t.Assert(data, []byte(src))
2019-06-21 22:23:07 +08:00
data, _ = gcompress.Zlib(nil)
2020-03-19 22:56:12 +08:00
t.Assert(data, nil)
2019-06-21 22:23:07 +08:00
data, _ = gcompress.UnZlib(nil)
2020-03-19 22:56:12 +08:00
t.Assert(data, nil)
2019-06-21 22:23:07 +08:00
data, _ = gcompress.UnZlib(dst[1:])
2020-03-19 22:56:12 +08:00
t.Assert(data, nil)
2019-04-18 12:34:01 +08:00
})
2019-04-09 19:12:48 +08:00
}