github.com/gogf/gf@v1.16.9/internal/utils/utils_z_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/gogf/gf. 6 7 package utils_test 8 9 import ( 10 "github.com/gogf/gf/internal/utils" 11 "github.com/gogf/gf/test/gtest" 12 "io/ioutil" 13 "testing" 14 ) 15 16 func Test_ReadCloser(t *testing.T) { 17 gtest.C(t, func(t *gtest.T) { 18 var ( 19 n int 20 b = make([]byte, 3) 21 body = utils.NewReadCloser([]byte{1, 2, 3, 4}, false) 22 ) 23 n, _ = body.Read(b) 24 t.Assert(b[:n], []byte{1, 2, 3}) 25 n, _ = body.Read(b) 26 t.Assert(b[:n], []byte{4}) 27 28 n, _ = body.Read(b) 29 t.Assert(b[:n], []byte{}) 30 n, _ = body.Read(b) 31 t.Assert(b[:n], []byte{}) 32 }) 33 gtest.C(t, func(t *gtest.T) { 34 var ( 35 r []byte 36 body = utils.NewReadCloser([]byte{1, 2, 3, 4}, false) 37 ) 38 r, _ = ioutil.ReadAll(body) 39 t.Assert(r, []byte{1, 2, 3, 4}) 40 r, _ = ioutil.ReadAll(body) 41 t.Assert(r, []byte{}) 42 }) 43 gtest.C(t, func(t *gtest.T) { 44 var ( 45 n int 46 r []byte 47 b = make([]byte, 3) 48 body = utils.NewReadCloser([]byte{1, 2, 3, 4}, true) 49 ) 50 n, _ = body.Read(b) 51 t.Assert(b[:n], []byte{1, 2, 3}) 52 n, _ = body.Read(b) 53 t.Assert(b[:n], []byte{4}) 54 55 n, _ = body.Read(b) 56 t.Assert(b[:n], []byte{1, 2, 3}) 57 n, _ = body.Read(b) 58 t.Assert(b[:n], []byte{4}) 59 60 r, _ = ioutil.ReadAll(body) 61 t.Assert(r, []byte{1, 2, 3, 4}) 62 r, _ = ioutil.ReadAll(body) 63 t.Assert(r, []byte{1, 2, 3, 4}) 64 }) 65 } 66 67 func Test_RemoveSymbols(t *testing.T) { 68 gtest.C(t, func(t *gtest.T) { 69 t.Assert(utils.RemoveSymbols(`-a-b._a c1!@#$%^&*()_+:";'.,'01`), `abac101`) 70 }) 71 }