-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags_test.go
More file actions
44 lines (39 loc) · 1.13 KB
/
flags_test.go
File metadata and controls
44 lines (39 loc) · 1.13 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
package bitflags
import (
"testing"
)
var s = struct {
FLa, FLb, FLc, FLd, FLe, FLf, FLg int8 // works with any other integer types
}{}
func TestBuildFlags(t *testing.T) {
err := BuildFlagsStruct(&s) // need pointer
if err != nil {
t.Fatalf("%s", err)
}
if (s.FLa | s.FLb | s.FLc | s.FLd | s.FLe | s.FLf | s.FLg) != 127 {
t.Fatal("inconsistent flag enumeration")
}
}
func TestGetFlagComponents(t *testing.T) {
BuildFlagsStruct(&s)
data := GetFlagComponents(s.FLb | s.FLd | s.FLg) // need to be in the ascending order for this test case
if len(data) != 3 {
t.Fatal("Inconsistent number of components returned")
}
params := []int8{s.FLb, s.FLd, s.FLg}
for i := range data {
if params[i] != data[i].(int8) { // the same datatype as the input
t.Fatalf("Flag %v is not present in the component slice", params[i])
}
}
}
func TestFlagInSum(t *testing.T) {
truth, left := FlagInSum(int8(4), uint8(5))
if truth != true || left.(uint8) != 1 {
t.Fatal("1. Unexpected result in FlagInSum")
}
truth, left = FlagInSum(s.FLd|s.FLa, s.FLa|s.FLc|s.FLg)
if truth != false || left != nil {
t.Fatal("2. Unexpected result in FlagInSum")
}
}