2023-12-22 13:20:45 +00:00
|
|
|
package dyn_test
|
2023-10-20 12:56:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-12-22 13:20:45 +00:00
|
|
|
"github.com/databricks/cli/libs/dyn"
|
2024-03-25 11:01:09 +00:00
|
|
|
assert "github.com/databricks/cli/libs/dyn/dynassert"
|
2023-10-20 12:56:59 +00:00
|
|
|
)
|
|
|
|
|
2024-01-05 13:02:04 +00:00
|
|
|
func TestInvalidValue(t *testing.T) {
|
|
|
|
// Assert that the zero value of [dyn.Value] is the invalid value.
|
|
|
|
var zero dyn.Value
|
|
|
|
assert.Equal(t, zero, dyn.InvalidValue)
|
|
|
|
}
|
|
|
|
|
2023-10-20 12:56:59 +00:00
|
|
|
func TestValueIsAnchor(t *testing.T) {
|
2023-12-22 13:20:45 +00:00
|
|
|
var zero dyn.Value
|
2023-10-20 12:56:59 +00:00
|
|
|
assert.False(t, zero.IsAnchor())
|
|
|
|
mark := zero.MarkAnchor()
|
|
|
|
assert.True(t, mark.IsAnchor())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValueAsMap(t *testing.T) {
|
2023-12-22 13:20:45 +00:00
|
|
|
var zeroValue dyn.Value
|
2024-03-25 11:01:09 +00:00
|
|
|
_, ok := zeroValue.AsMap()
|
2023-10-20 12:56:59 +00:00
|
|
|
assert.False(t, ok)
|
|
|
|
|
2023-12-22 13:20:45 +00:00
|
|
|
var intValue = dyn.NewValue(1, dyn.Location{})
|
2024-03-25 11:01:09 +00:00
|
|
|
_, ok = intValue.AsMap()
|
2023-10-20 12:56:59 +00:00
|
|
|
assert.False(t, ok)
|
|
|
|
|
2023-12-22 13:20:45 +00:00
|
|
|
var mapValue = dyn.NewValue(
|
|
|
|
map[string]dyn.Value{
|
|
|
|
"key": dyn.NewValue("value", dyn.Location{File: "file", Line: 1, Column: 2}),
|
2023-10-20 12:56:59 +00:00
|
|
|
},
|
2023-12-22 13:20:45 +00:00
|
|
|
dyn.Location{File: "file", Line: 1, Column: 2},
|
2023-10-20 12:56:59 +00:00
|
|
|
)
|
2024-03-25 11:01:09 +00:00
|
|
|
m, ok := mapValue.AsMap()
|
2023-10-20 12:56:59 +00:00
|
|
|
assert.True(t, ok)
|
2024-03-25 11:01:09 +00:00
|
|
|
assert.Equal(t, 1, m.Len())
|
2023-10-20 12:56:59 +00:00
|
|
|
}
|
2023-11-24 13:21:47 +00:00
|
|
|
|
|
|
|
func TestValueIsValid(t *testing.T) {
|
2023-12-22 13:20:45 +00:00
|
|
|
var zeroValue dyn.Value
|
2023-11-24 13:21:47 +00:00
|
|
|
assert.False(t, zeroValue.IsValid())
|
2023-12-22 13:20:45 +00:00
|
|
|
var intValue = dyn.NewValue(1, dyn.Location{})
|
2023-11-24 13:21:47 +00:00
|
|
|
assert.True(t, intValue.IsValid())
|
|
|
|
}
|