-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbitset_test.go
More file actions
50 lines (39 loc) · 1.05 KB
/
Copy pathbitset_test.go
File metadata and controls
50 lines (39 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package helium
import (
"fmt"
"testing"
"github.com/lestrrat-go/helium/internal/bitset"
"github.com/stretchr/testify/require"
)
func TestLoadSubsetOptionFlagsAreUnique(t *testing.T) {
t.Parallel()
assertUniqueFlags(t, []LoadSubsetOption{
DetectIDs,
CompleteAttrs,
SkipIDs,
})
}
func TestSetAndIsSet(t *testing.T) {
t.Parallel()
var l LoadSubsetOption
require.False(t, l.IsSet(DetectIDs))
l.Set(DetectIDs)
require.True(t, l.IsSet(DetectIDs))
require.False(t, l.IsSet(CompleteAttrs))
l.Set(CompleteAttrs)
require.True(t, l.IsSet(DetectIDs))
require.True(t, l.IsSet(CompleteAttrs))
}
func assertUniqueFlags[T bitset.Field](t *testing.T, flags []T) {
t.Helper()
for i, f := range flags {
t.Run(fmt.Sprintf("flag_%d", i), func(t *testing.T) {
t.Parallel()
require.NotZero(t, f, "flag[%d] must be non-zero", i)
require.Zero(t, f&(f-1), "flag[%d]=%d must be a single-bit value", i, f)
for j := i + 1; j < len(flags); j++ {
require.Zero(t, f&flags[j], "flags[%d]=%d and flags[%d]=%d overlap", i, f, j, flags[j])
}
})
}
}