Skip to content

Commit

Permalink
Add aliases and nested aliases test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
noamcohen97 committed Sep 27, 2024
1 parent 1aeff60 commit 891a170
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions codegen/config/binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"go/token"
"go/types"
"testing"

Expand Down Expand Up @@ -266,6 +267,11 @@ func TestEnumBinding(t *testing.T) {
require.Equal(t, cf.Schema.Types["Baz"].EnumValues[1], baz.EnumValues[1].Definition)
}

func createTypeAlias(name string, t types.Type) *types.Alias {
var nopos token.Pos
return types.NewAlias(types.NewTypeName(nopos, nil, name, nil), t)
}

func TestIsNilable(t *testing.T) {
type aTest struct {
input types.Type
Expand All @@ -285,6 +291,10 @@ func TestIsNilable(t *testing.T) {
{types.NewMap(types.Typ[types.Int], types.Typ[types.Int]), true},
{types.NewSlice(types.Typ[types.Int]), true},
{types.NewInterfaceType(nil, nil), true},
{createTypeAlias("interfaceAlias", types.NewInterfaceType(nil, nil)), true},
{createTypeAlias("interfaceNestedAlias", createTypeAlias("interfaceAlias", types.NewInterfaceType(nil, nil))), true},
{createTypeAlias("intAlias", types.Typ[types.Int]), false},
{createTypeAlias("intNestedAlias", createTypeAlias("intAlias", types.Typ[types.Int])), false},
}

for _, at := range theTests {
Expand Down

0 comments on commit 891a170

Please sign in to comment.