mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 19:27:46 +08:00
add unit test
This commit is contained in:
parent
468c315087
commit
053a3c1a53
51
g/encoding/gbase64/gbase64_test.go
Normal file
51
g/encoding/gbase64/gbase64_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
package gbase64_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/g/encoding/gbase64"
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testpair struct {
|
||||
decoded, encoded string
|
||||
}
|
||||
|
||||
var pairs = []testpair{
|
||||
// RFC 3548 examples
|
||||
{"\x14\xfb\x9c\x03\xd9\x7e", "FPucA9l+"},
|
||||
{"\x14\xfb\x9c\x03\xd9", "FPucA9k="},
|
||||
{"\x14\xfb\x9c\x03", "FPucAw=="},
|
||||
|
||||
// RFC 4648 examples
|
||||
{"", ""},
|
||||
{"f", "Zg=="},
|
||||
{"fo", "Zm8="},
|
||||
{"foo", "Zm9v"},
|
||||
{"foob", "Zm9vYg=="},
|
||||
{"fooba", "Zm9vYmE="},
|
||||
{"foobar", "Zm9vYmFy"},
|
||||
|
||||
// Wikipedia examples
|
||||
{"sure.", "c3VyZS4="},
|
||||
{"sure", "c3VyZQ=="},
|
||||
{"sur", "c3Vy"},
|
||||
{"su", "c3U="},
|
||||
{"leasure.", "bGVhc3VyZS4="},
|
||||
{"easure.", "ZWFzdXJlLg=="},
|
||||
{"asure.", "YXN1cmUu"},
|
||||
{"sure.", "c3VyZS4="},
|
||||
}
|
||||
|
||||
func TestBase64(t *testing.T) {
|
||||
for k := range pairs{
|
||||
gtest.Assert(gbase64.Encode(pairs[k].decoded), pairs[k].encoded)
|
||||
|
||||
e, _ := gbase64.Decode(pairs[k].encoded)
|
||||
gtest.Assert(e, pairs[k].decoded)
|
||||
}
|
||||
}
|
28
g/encoding/gcompress/gcompress_test.go
Normal file
28
g/encoding/gcompress/gcompress_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
package gcompress_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/g/util/grand"
|
||||
"github.com/gogf/gf/g/encoding/gcompress"
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var times = 10
|
||||
var length = 2000
|
||||
|
||||
func TestCompress(t *testing.T) {
|
||||
for i := 0; i < times; i++ {
|
||||
src := grand.RandStr(length + i * 10)
|
||||
zlibVal := gcompress.Zlib([]byte(src))
|
||||
dst := gcompress.UnZlib(zlibVal)
|
||||
gtest.Assert(dst, []byte(src))
|
||||
|
||||
dst1 := gcompress.UnGzip(gcompress.Gzip([]byte(src)))
|
||||
gtest.Assert(dst1, []byte(src))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user