uint16subject.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package assert
  2. import (
  3. "github.com/v2ray/v2ray-core/common/serial"
  4. )
  5. func Uint16(value uint16) *Uint16Subject {
  6. return &Uint16Subject{value: serial.Uint16Literal(value)}
  7. }
  8. type Uint16Subject struct {
  9. Subject
  10. value serial.Uint16Literal
  11. }
  12. func (subject *Uint16Subject) Named(name string) *Uint16Subject {
  13. subject.Subject.Named(name)
  14. return subject
  15. }
  16. func (subject *Uint16Subject) DisplayString() string {
  17. return subject.Subject.DisplayString(subject.value.String())
  18. }
  19. func (subject *Uint16Subject) Equals(expectation uint16) {
  20. if subject.value.Value() != expectation {
  21. subject.Fail(subject.DisplayString(), "is equal to", serial.Uint16Literal(expectation))
  22. }
  23. }
  24. func (subject *Uint16Subject) GreaterThan(expectation uint16) {
  25. if subject.value.Value() <= expectation {
  26. subject.Fail(subject.DisplayString(), "is greater than", serial.Uint16Literal(expectation))
  27. }
  28. }
  29. func (subject *Uint16Subject) LessThan(expectation uint16) {
  30. if subject.value.Value() >= expectation {
  31. subject.Fail(subject.DisplayString(), "is less than", serial.Uint16Literal(expectation))
  32. }
  33. }
  34. func (subject *Uint16Subject) Positive() {
  35. if subject.value.Value() <= 0 {
  36. subject.FailWithMessage("Not true that " + subject.DisplayString() + " is positive.")
  37. }
  38. }