byte_test.go 703 B

123456789101112131415161718192021222324252627282930313233343536
  1. package bitmask_test
  2. import (
  3. "testing"
  4. . "github.com/xtls/xray-core/common/bitmask"
  5. )
  6. func TestBitmaskByte(t *testing.T) {
  7. b := Byte(0)
  8. b.Set(Byte(1))
  9. if !b.Has(1) {
  10. t.Fatal("expected ", b, " to contain 1, but actually not")
  11. }
  12. b.Set(Byte(2))
  13. if !b.Has(2) {
  14. t.Fatal("expected ", b, " to contain 2, but actually not")
  15. }
  16. if !b.Has(1) {
  17. t.Fatal("expected ", b, " to contain 1, but actually not")
  18. }
  19. b.Clear(Byte(1))
  20. if !b.Has(2) {
  21. t.Fatal("expected ", b, " to contain 2, but actually not")
  22. }
  23. if b.Has(1) {
  24. t.Fatal("expected ", b, " to not contain 1, but actually did")
  25. }
  26. b.Toggle(Byte(2))
  27. if b.Has(2) {
  28. t.Fatal("expected ", b, " to not contain 2, but actually did")
  29. }
  30. }