You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/testing/assert/bytes.go

44 lines
922 B

9 years ago
package assert
import (
"bytes"
"fmt"
"v2ray.com/core/common/serial"
9 years ago
)
8 years ago
func (v *Assert) Bytes(value []byte) *BytesSubject {
9 years ago
return &BytesSubject{
Subject: Subject{
disp: serial.BytesToHexString(value),
8 years ago
a: v,
9 years ago
},
value: value,
}
}
type BytesSubject struct {
Subject
value []byte
}
func (subject *BytesSubject) Equals(expectation []byte) {
if len(subject.value) != len(expectation) {
subject.FailWithMessage(fmt.Sprint("Bytes arrays have differen size: expected ", len(expectation), ", actual ", len(subject.value)))
return
}
for idx, b := range expectation {
if subject.value[idx] != b {
subject.FailWithMessage(fmt.Sprint("Bytes are different: ", b, " vs ", subject.value[idx]))
return
}
9 years ago
}
}
func (subject *BytesSubject) NotEquals(expectation []byte) {
if bytes.Equal(subject.value, expectation) {
subject.Fail("is not equal to", serial.BytesToHexString(expectation))
}
}