From 12db7b6935c30fc02cd7298a3bb75d136580c8c9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 3 Oct 2023 17:38:13 +0100 Subject: [PATCH] fs: add IsSet convenience method to Bits --- fs/bits.go | 5 +++++ fs/bits_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/fs/bits.go b/fs/bits.go index ed2ac6338..5c271e8c3 100644 --- a/fs/bits.go +++ b/fs/bits.go @@ -114,6 +114,11 @@ func (b *Bits[C]) Set(s string) error { 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. // // If C has a Type() string method then it will be used instead. diff --git a/fs/bits_test.go b/fs/bits_test.go index 6f6c55504..4ab1585a0 100644 --- a/fs/bits_test.go +++ b/fs/bits_test.go @@ -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) { f := bits(0) assert.Equal(t, "Bits", f.Type())