pointer.go 708 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package assert
  2. import (
  3. "github.com/v2ray/v2ray-core/common/serial"
  4. )
  5. func (this *Assert) Pointer(value interface{}) *PointerSubject {
  6. return &PointerSubject{
  7. Subject: Subject{
  8. a: this,
  9. disp: serial.PointerToString(value),
  10. },
  11. value: value,
  12. }
  13. }
  14. type PointerSubject struct {
  15. Subject
  16. value interface{}
  17. }
  18. func (subject *PointerSubject) Equals(expectation interface{}) {
  19. if subject.value != expectation {
  20. subject.Fail("is equal to", serial.PointerToString(expectation))
  21. }
  22. }
  23. func (subject *PointerSubject) IsNil() {
  24. if subject.value != nil {
  25. subject.Fail("is", "nil")
  26. }
  27. }
  28. func (subject *PointerSubject) IsNotNil() {
  29. if subject.value == nil {
  30. subject.Fail("is not", "nil")
  31. }
  32. }