subject.go 783 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package assert
  2. import (
  3. "github.com/v2ray/v2ray-core/common/serial"
  4. v2testing "github.com/v2ray/v2ray-core/testing"
  5. )
  6. type Subject struct {
  7. name string
  8. }
  9. func NewSubject() *Subject {
  10. return &Subject{
  11. name: "",
  12. }
  13. }
  14. func (subject *Subject) Fail(displayString string, verb string, other serial.String) {
  15. subject.FailWithMessage("Not true that " + displayString + " " + verb + " <" + other.String() + ">.")
  16. }
  17. func (subject *Subject) FailWithMessage(message string) {
  18. v2testing.Fail(message)
  19. }
  20. func (subject *Subject) Named(name string) {
  21. subject.name = name
  22. }
  23. func (subject *Subject) DisplayString(value string) string {
  24. if len(value) == 0 {
  25. value = "unknown"
  26. }
  27. if len(subject.name) == 0 {
  28. return "<" + value + ">"
  29. }
  30. return subject.name + "(<" + value + ">)"
  31. }