Add function to check if `config.Value` is valid (#1009)

## Changes

Small function broken out from other work in progress.
This commit is contained in:
Pieter Noordhuis 2023-11-24 14:21:47 +01:00 committed by GitHub
parent 6187803007
commit ef97e249ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -51,6 +51,10 @@ func (v Value) Location() Location {
return v.l
}
func (v Value) IsValid() bool {
return v.k != KindInvalid
}
func (v Value) AsAny() any {
switch v.k {
case KindInvalid:

View File

@ -35,3 +35,10 @@ func TestValueAsMap(t *testing.T) {
assert.True(t, ok)
assert.Len(t, m, 1)
}
func TestValueIsValid(t *testing.T) {
var zeroValue config.Value
assert.False(t, zeroValue.IsValid())
var intValue = config.NewValue(1, config.Location{})
assert.True(t, intValue.IsValid())
}