intsubject.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package assert
  2. import (
  3. "github.com/v2ray/v2ray-core/common/serial"
  4. )
  5. func Int(value int) *IntSubject {
  6. return &IntSubject{value: serial.IntLiteral(value)}
  7. }
  8. type IntSubject struct {
  9. Subject
  10. value serial.IntLiteral
  11. }
  12. func (subject *IntSubject) Named(name string) *IntSubject {
  13. subject.Subject.Named(name)
  14. return subject
  15. }
  16. func (subject *IntSubject) DisplayString() string {
  17. return subject.Subject.DisplayString(subject.value.String())
  18. }
  19. func (subject *IntSubject) Equals(expectation int) {
  20. if subject.value.Value() != expectation {
  21. subject.Fail(subject.DisplayString(), "is equal to", serial.IntLiteral(expectation))
  22. }
  23. }
  24. func (subject *IntSubject) GreaterThan(expectation int) {
  25. if subject.value.Value() <= expectation {
  26. subject.Fail(subject.DisplayString(), "is greater than", serial.IntLiteral(expectation))
  27. }
  28. }
  29. func (subject *IntSubject) LessThan(expectation int) {
  30. if subject.value.Value() >= expectation {
  31. subject.Fail(subject.DisplayString(), "is less than", serial.IntLiteral(expectation))
  32. }
  33. }