forked from TrueCloudLab/rclone
fs: add IsSet convenience method to Bits
This commit is contained in:
parent
7434ad8618
commit
12db7b6935
2 changed files with 14 additions and 0 deletions
|
@ -114,6 +114,11 @@ func (b *Bits[C]) Set(s string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSet returns true all the bits in mask are set in b.
|
||||||
|
func (b Bits[C]) IsSet(mask Bits[C]) bool {
|
||||||
|
return (b & mask) == mask
|
||||||
|
}
|
||||||
|
|
||||||
// Type of the value.
|
// Type of the value.
|
||||||
//
|
//
|
||||||
// If C has a Type() string method then it will be used instead.
|
// If C has a Type() string method then it will be used instead.
|
||||||
|
|
|
@ -80,6 +80,15 @@ func TestBitsSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBitsIsSet(t *testing.T) {
|
||||||
|
b := bitA | bitB
|
||||||
|
assert.True(t, b.IsSet(bitA))
|
||||||
|
assert.True(t, b.IsSet(bitB))
|
||||||
|
assert.True(t, b.IsSet(bitA|bitB))
|
||||||
|
assert.False(t, b.IsSet(bitC))
|
||||||
|
assert.False(t, b.IsSet(bitA|bitC))
|
||||||
|
}
|
||||||
|
|
||||||
func TestBitsType(t *testing.T) {
|
func TestBitsType(t *testing.T) {
|
||||||
f := bits(0)
|
f := bits(0)
|
||||||
assert.Equal(t, "Bits", f.Type())
|
assert.Equal(t, "Bits", f.Type())
|
||||||
|
|
Loading…
Reference in a new issue