Skip to content

Commit

Permalink
Add a couple of unit tests for type | null disjunctions handling in…
Browse files Browse the repository at this point in the history
… the `DisjunctionToType` compiler pass
  • Loading branch information
K-Phoen committed Sep 21, 2023
1 parent 7129109 commit 99b8591
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions internal/ast/compiler/disjunctions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,58 @@ func TestDisjunctionToType_WithNonDisjunctionObjects_HasNoImpact(t *testing.T) {
runDisjunctionPass(t, objects, objects)
}

func TestDisjunctionToType_WithDisjunctionOfTypeAndNull_AsAnObject(t *testing.T) {
// Prepare test input
objects := []ast.Object{
ast.NewObject("ScalarWithNull", ast.NewDisjunction([]ast.Type{
ast.String(),
ast.Null(),
})),
ast.NewObject("RefWithNull", ast.NewDisjunction([]ast.Type{
ast.NewRef("SomeType"),
ast.Null(),
})),
}

expectedObjects := []ast.Object{
ast.NewObject("ScalarWithNull", ast.String(ast.Nullable())),
ast.NewObject("RefWithNull", ast.NewRef("SomeType", ast.Nullable())),
}

// Call the compiler pass
runDisjunctionPass(t, objects, expectedObjects)
}

func TestDisjunctionToType_WithDisjunctionOfTypeAndNull_AsAStructField(t *testing.T) {
// Prepare test input
objects := []ast.Object{
ast.NewObject("StructWithScalarWithNull", ast.NewStruct(
ast.NewStructField("Field", ast.NewDisjunction([]ast.Type{
ast.String(),
ast.Null(),
})),
)),
ast.NewObject("StructWithRefWithNull", ast.NewStruct(
ast.NewStructField("Field", ast.NewDisjunction([]ast.Type{
ast.NewRef("SomeType"),
ast.Null(),
})),
)),
}

expectedObjects := []ast.Object{
ast.NewObject("StructWithScalarWithNull", ast.NewStruct(
ast.NewStructField("Field", ast.String(ast.Nullable())),
)),
ast.NewObject("StructWithRefWithNull", ast.NewStruct(
ast.NewStructField("Field", ast.NewRef("SomeType", ast.Nullable())),
)),
}

// Call the compiler pass
runDisjunctionPass(t, objects, expectedObjects)
}

func TestDisjunctionToType_WithDisjunctionOfScalars_AsAnObject(t *testing.T) {
// Prepare test input
objects := []ast.Object{
Expand Down

0 comments on commit 99b8591

Please sign in to comment.