mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-06 23:56:53 +00:00
types/opt: add Bool.EqualBool method
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
4732722b87
commit
0071888a17
@ -29,6 +29,13 @@ func (b Bool) Get() (v bool, ok bool) {
|
|||||||
return v, err == nil
|
return v, err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EqualBool reports whether b is equal to v.
|
||||||
|
// If b is empty or not a valid bool, it reports false.
|
||||||
|
func (b Bool) EqualBool(v bool) bool {
|
||||||
|
p, ok := b.Get()
|
||||||
|
return ok && p == v
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
trueBytes = []byte("true")
|
trueBytes = []byte("true")
|
||||||
falseBytes = []byte("false")
|
falseBytes = []byte("false")
|
||||||
|
@ -64,3 +64,26 @@ func TestBool(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBoolEqualBool(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
b Bool
|
||||||
|
v bool
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"", true, false},
|
||||||
|
{"", false, false},
|
||||||
|
{"sdflk;", true, false},
|
||||||
|
{"sldkf;", false, false},
|
||||||
|
{"true", true, true},
|
||||||
|
{"true", false, false},
|
||||||
|
{"false", true, false},
|
||||||
|
{"false", false, true},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
if got := tt.b.EqualBool(tt.v); got != tt.want {
|
||||||
|
t.Errorf("(%q).EqualBool(%v) = %v; want %v", string(tt.b), tt.v, got, tt.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user