1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/testing/assert/bytessubject.go
2015-12-12 13:11:49 +01:00

42 lines
948 B
Go

package assert
import (
"bytes"
"fmt"
)
func Bytes(value []byte) *BytesSubject {
return &BytesSubject{value: value}
}
type BytesSubject struct {
Subject
value []byte
}
func (subject *BytesSubject) Named(name string) *BytesSubject {
subject.Subject.Named(name)
return subject
}
func (subject *BytesSubject) Fail(verb string, other []byte) {
otherString := fmt.Sprintf("%v", other)
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + otherString + ">.")
}
func (subject *BytesSubject) DisplayString() string {
return subject.Subject.DisplayString(fmt.Sprintf("%v", subject.value))
}
func (subject *BytesSubject) Equals(expectation []byte) {
if !bytes.Equal(subject.value, expectation) {
subject.Fail("is equal to", expectation)
}
}
func (subject *BytesSubject) NotEquals(expectation []byte) {
if bytes.Equal(subject.value, expectation) {
subject.Fail("is not equal to", expectation)
}
}