-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define constant for the invalid
dyn.Value
(#1101)
## Changes The nil value is a real valid value that we need to represent. To accommodate this we introduced `dyn.KindInvalid` as the zero-value for `dyn.Kind` (see #904), but did not yet update the comments on `dyn.NilValue` or add tests for `kind.go`. This also moves `KindNil` to be last in the definition order (least likely to care about it). ## Tests Tests pass.
- Loading branch information
Showing
4 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dyn_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/databricks/cli/libs/dyn" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestKindZeroValue(t *testing.T) { | ||
// Assert that the zero value of [dyn.Kind] is the invalid kind. | ||
var k dyn.Kind | ||
assert.Equal(t, dyn.KindInvalid, k) | ||
} | ||
|
||
func TestKindToString(t *testing.T) { | ||
for _, tt := range []struct { | ||
k dyn.Kind | ||
s string | ||
}{ | ||
{dyn.KindInvalid, "invalid"}, | ||
{dyn.KindMap, "map"}, | ||
{dyn.KindSequence, "sequence"}, | ||
{dyn.KindString, "string"}, | ||
{dyn.KindBool, "bool"}, | ||
{dyn.KindInt, "int"}, | ||
{dyn.KindFloat, "float"}, | ||
{dyn.KindTime, "time"}, | ||
{dyn.KindNil, "nil"}, | ||
} { | ||
assert.Equal(t, tt.s, tt.k.String()) | ||
} | ||
|
||
// Panic on unknown kind. | ||
assert.PanicsWithValue(t, "invalid kind value: 100", func() { | ||
_ = dyn.Kind(100).String() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters