Skip to content

Commit 99b8591

Browse files
committed
Add a couple of unit tests for type | null disjunctions handling in the DisjunctionToType compiler pass
1 parent 7129109 commit 99b8591

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

internal/ast/compiler/disjunctions_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,58 @@ func TestDisjunctionToType_WithNonDisjunctionObjects_HasNoImpact(t *testing.T) {
3636
runDisjunctionPass(t, objects, objects)
3737
}
3838

39+
func TestDisjunctionToType_WithDisjunctionOfTypeAndNull_AsAnObject(t *testing.T) {
40+
// Prepare test input
41+
objects := []ast.Object{
42+
ast.NewObject("ScalarWithNull", ast.NewDisjunction([]ast.Type{
43+
ast.String(),
44+
ast.Null(),
45+
})),
46+
ast.NewObject("RefWithNull", ast.NewDisjunction([]ast.Type{
47+
ast.NewRef("SomeType"),
48+
ast.Null(),
49+
})),
50+
}
51+
52+
expectedObjects := []ast.Object{
53+
ast.NewObject("ScalarWithNull", ast.String(ast.Nullable())),
54+
ast.NewObject("RefWithNull", ast.NewRef("SomeType", ast.Nullable())),
55+
}
56+
57+
// Call the compiler pass
58+
runDisjunctionPass(t, objects, expectedObjects)
59+
}
60+
61+
func TestDisjunctionToType_WithDisjunctionOfTypeAndNull_AsAStructField(t *testing.T) {
62+
// Prepare test input
63+
objects := []ast.Object{
64+
ast.NewObject("StructWithScalarWithNull", ast.NewStruct(
65+
ast.NewStructField("Field", ast.NewDisjunction([]ast.Type{
66+
ast.String(),
67+
ast.Null(),
68+
})),
69+
)),
70+
ast.NewObject("StructWithRefWithNull", ast.NewStruct(
71+
ast.NewStructField("Field", ast.NewDisjunction([]ast.Type{
72+
ast.NewRef("SomeType"),
73+
ast.Null(),
74+
})),
75+
)),
76+
}
77+
78+
expectedObjects := []ast.Object{
79+
ast.NewObject("StructWithScalarWithNull", ast.NewStruct(
80+
ast.NewStructField("Field", ast.String(ast.Nullable())),
81+
)),
82+
ast.NewObject("StructWithRefWithNull", ast.NewStruct(
83+
ast.NewStructField("Field", ast.NewRef("SomeType", ast.Nullable())),
84+
)),
85+
}
86+
87+
// Call the compiler pass
88+
runDisjunctionPass(t, objects, expectedObjects)
89+
}
90+
3991
func TestDisjunctionToType_WithDisjunctionOfScalars_AsAnObject(t *testing.T) {
4092
// Prepare test input
4193
objects := []ast.Object{

0 commit comments

Comments
 (0)