Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
exported literal type for functions
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Rammer <[email protected]>
  • Loading branch information
hamersaw committed Mar 31, 2023
1 parent 17062d8 commit 4649cf9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions clients/go/coreutils/typing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)

func literalTypeForPrimitive(primitive *core.Primitive) *core.LiteralType {
func LiteralTypeForPrimitive(primitive *core.Primitive) *core.LiteralType {
simpleType := core.SimpleType_NONE
switch primitive.GetValue().(type) {
case *core.Primitive_Integer:
Expand All @@ -28,12 +28,12 @@ func literalTypeForPrimitive(primitive *core.Primitive) *core.LiteralType {
}

// Gets literal type for scalar value. This can be used to compare the underlying type of two scalars for compatibility.
func literalTypeForScalar(scalar *core.Scalar) *core.LiteralType {
func LiteralTypeForScalar(scalar *core.Scalar) *core.LiteralType {
// TODO: Should we just pass the type information with the value? That way we don't have to guess?
var literalType *core.LiteralType
switch v := scalar.GetValue().(type) {
case *core.Scalar_Primitive:
literalType = literalTypeForPrimitive(scalar.GetPrimitive())
literalType = LiteralTypeForPrimitive(scalar.GetPrimitive())
case *core.Scalar_Blob:
if scalar.GetBlob().GetMetadata() == nil {
return nil
Expand Down Expand Up @@ -88,25 +88,25 @@ func literalTypeForScalar(scalar *core.Scalar) *core.LiteralType {
func LiteralTypeForLiteral(l *core.Literal) *core.LiteralType {
switch l.GetValue().(type) {
case *core.Literal_Scalar:
return literalTypeForScalar(l.GetScalar())
return LiteralTypeForScalar(l.GetScalar())
case *core.Literal_Collection:
return &core.LiteralType{
Type: &core.LiteralType_CollectionType{
CollectionType: literalTypeForLiterals(l.GetCollection().Literals),
CollectionType: LiteralTypeForLiterals(l.GetCollection().Literals),
},
}
case *core.Literal_Map:
return &core.LiteralType{
Type: &core.LiteralType_MapValueType{
MapValueType: literalTypeForLiterals(maps.Values(l.GetMap().Literals)),
MapValueType: LiteralTypeForLiterals(maps.Values(l.GetMap().Literals)),
},
}
}

return nil
}

func literalTypeForLiterals(literals []*core.Literal) *core.LiteralType {
func LiteralTypeForLiterals(literals []*core.Literal) *core.LiteralType {
innerType := make([]*core.LiteralType, 0, 1)
innerTypeSet := sets.NewString()
for _, x := range literals {
Expand Down
8 changes: 4 additions & 4 deletions clients/go/coreutils/typing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

func TestLiteralTypeForLiterals(t *testing.T) {
t.Run("empty", func(t *testing.T) {
lt := literalTypeForLiterals(nil)
lt := LiteralTypeForLiterals(nil)
assert.Equal(t, core.SimpleType_NONE.String(), lt.GetSimple().String())
})

t.Run("homogenous", func(t *testing.T) {
lt := literalTypeForLiterals([]*core.Literal{
lt := LiteralTypeForLiterals([]*core.Literal{
MustMakeLiteral(5),
MustMakeLiteral(0),
MustMakeLiteral(5),
Expand All @@ -24,7 +24,7 @@ func TestLiteralTypeForLiterals(t *testing.T) {
})

t.Run("non-homogenous", func(t *testing.T) {
lt := literalTypeForLiterals([]*core.Literal{
lt := LiteralTypeForLiterals([]*core.Literal{
MustMakeLiteral("hello"),
MustMakeLiteral(5),
MustMakeLiteral("world"),
Expand All @@ -38,7 +38,7 @@ func TestLiteralTypeForLiterals(t *testing.T) {
})

t.Run("non-homogenous ensure ordering", func(t *testing.T) {
lt := literalTypeForLiterals([]*core.Literal{
lt := LiteralTypeForLiterals([]*core.Literal{
MustMakeLiteral(5),
MustMakeLiteral("world"),
MustMakeLiteral(0),
Expand Down

0 comments on commit 4649cf9

Please sign in to comment.