github.com/EagleQL/Xray-core@v1.4.3/common/bitmask/byte_test.go (about)

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