Commit 028486bd authored by Kirill Smelkov's avatar Kirill Smelkov

fuse: Don't print default if flags != 0

flagString(flags, "default") should return default only if flags == 0.

Noticed by Han-Wen: https://review.gerrithub.io/c/hanwen/go-fuse/+/555490/comment/9cbd50ed_d836c29c/

Without the fix added test fails as

    --- FAIL: TestFlagStringDefault (0.00s)
        print_test.go:48: flagString(8, "X") -> got "X,0x8" ;  want "0x8"

Change-Id: I5b9432741e30948d490b276c097fbcfe45ecd936
parent d5638ffd
...@@ -133,12 +133,12 @@ func flagString(names *flagNames, fl int64, def string) string { ...@@ -133,12 +133,12 @@ func flagString(names *flagNames, fl int64, def string) string {
} }
} }
} }
if len(s) == 0 && def != "" {
s = []string{def}
}
if fl != 0 { if fl != 0 {
s = append(s, fmt.Sprintf("0x%x", fl)) s = append(s, fmt.Sprintf("0x%x", fl))
} }
if len(s) == 0 && def != "" {
return def
}
return strings.Join(s, ",") return strings.Join(s, ",")
} }
......
...@@ -20,3 +20,33 @@ func TestFlagStringOrder(t *testing.T) { ...@@ -20,3 +20,33 @@ func TestFlagStringOrder(t *testing.T) {
} }
} }
} }
// verify how flagString handles provided default.
func TestFlagStringDefault(t *testing.T) {
names := newFlagNames(map[int64]string{
1: "AAA",
2: "BBB",
4: "CCC",
})
testv := []struct {
flags int64
def string
strok string
}{
{0, "", ""},
{0, "X", "X"},
{1, "X", "AAA"},
{5, "X", "AAA,CCC"},
{8, "X", "0x8"},
{9, "X", "AAA,0x8"},
}
for _, test := range testv {
str := flagString(names, test.flags, test.def)
if str != test.strok {
t.Errorf("flagString(%x, %q) -> got %q ; want %q",
test.flags, test.def, str, test.strok)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment