2015-12-02 09:27:18 -05:00
|
|
|
package assert
|
2015-09-09 08:51:26 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
func Bytes(value []byte) *BytesSubject {
|
|
|
|
return &BytesSubject{value: value}
|
2015-09-09 08:51:26 -04:00
|
|
|
}
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
type BytesSubject struct {
|
|
|
|
Subject
|
|
|
|
value []byte
|
2015-09-09 08:51:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2015-12-12 07:11:49 -05:00
|
|
|
|
|
|
|
func (subject *BytesSubject) NotEquals(expectation []byte) {
|
|
|
|
if bytes.Equal(subject.value, expectation) {
|
|
|
|
subject.Fail("is not equal to", expectation)
|
|
|
|
}
|
|
|
|
}
|