mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-03 00:22:05 +00:00
remove dependency on assert lib
This commit is contained in:
5 files changed
+100
-85
No files matched your search
@@ -9,33 +9,34 @@ import (
|
||||
|
||||
"v2ray.com/core/common"
|
||||
. "v2ray.com/core/common/buf"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestMultiBufferRead(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
b1 := New()
|
||||
b1.WriteString("ab")
|
||||
common.Must2(b1.WriteString("ab"))
|
||||
|
||||
b2 := New()
|
||||
b2.WriteString("cd")
|
||||
common.Must2(b2.WriteString("cd"))
|
||||
mb := MultiBuffer{b1, b2}
|
||||
|
||||
bs := make([]byte, 32)
|
||||
_, nBytes := SplitBytes(mb, bs)
|
||||
assert(nBytes, Equals, 4)
|
||||
assert(bs[:nBytes], Equals, []byte("abcd"))
|
||||
if nBytes != 4 {
|
||||
t.Error("expect 4 bytes split, but got ", nBytes)
|
||||
}
|
||||
if r := cmp.Diff(bs[:nBytes], []byte("abcd")); r != "" {
|
||||
t.Error(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiBufferAppend(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
var mb MultiBuffer
|
||||
b := New()
|
||||
b.WriteString("ab")
|
||||
common.Must2(b.WriteString("ab"))
|
||||
mb = append(mb, b)
|
||||
assert(mb.Len(), Equals, int32(2))
|
||||
if mb.Len() != 2 {
|
||||
t.Error("expected length 2, but got ", mb.Len())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiBufferSliceBySizeLarge(t *testing.T) {
|
||||
|
||||
+29
-14
@@ -5,25 +5,40 @@ import (
|
||||
"testing"
|
||||
|
||||
. "v2ray.com/core/common"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestMust(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
f := func() error {
|
||||
return errors.New("test error")
|
||||
hasPanic := func(f func()) (ret bool) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ret = true
|
||||
}
|
||||
}()
|
||||
f()
|
||||
return false
|
||||
}
|
||||
|
||||
assert(func() { Must(f()) }, Panics)
|
||||
}
|
||||
|
||||
func TestMust2(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
f := func() (interface{}, error) {
|
||||
return nil, errors.New("test error")
|
||||
testCases := []struct {
|
||||
Input func()
|
||||
Panic bool
|
||||
}{
|
||||
{
|
||||
Panic: true,
|
||||
Input: func() { Must(func() error { return errors.New("test error") }()) },
|
||||
},
|
||||
{
|
||||
Panic: true,
|
||||
Input: func() { Must2(func() (int, error) { return 0, errors.New("test error") }()) },
|
||||
},
|
||||
{
|
||||
Panic: false,
|
||||
Input: func() { Must(func() error { return nil }()) },
|
||||
},
|
||||
}
|
||||
|
||||
assert(func() { Must2(f()) }, Panics)
|
||||
for idx, test := range testCases {
|
||||
if hasPanic(test.Input) != test.Panic {
|
||||
t.Error("test case #", idx, " expect panic ", test.Panic, " but actually not")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user