-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ast): equality for Object, Array, Tuple, and FuncCall
- Loading branch information
Showing
2 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package ast_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sanity-io/go-groq/ast" | ||
) | ||
|
||
func TestAST_ObjectEquality(t *testing.T) { | ||
a := &ast.Object{ | ||
Expressions: []ast.Expression{ | ||
&ast.Attribute{Name: "a"}, | ||
&ast.Attribute{Name: "b"}, | ||
}, | ||
} | ||
|
||
b := &ast.Object{ | ||
Expressions: []ast.Expression{ | ||
&ast.Attribute{Name: "a"}, | ||
&ast.Attribute{Name: "b"}, | ||
}, | ||
} | ||
|
||
c := &ast.Object{ | ||
Expressions: []ast.Expression{ | ||
&ast.Attribute{Name: "b"}, | ||
&ast.Attribute{Name: "a"}, | ||
}, | ||
} | ||
|
||
assert.True(t, a.Equal(a)) // should be equal to itself | ||
assert.True(t, a.Equal(b)) // should be equal to another identical object | ||
assert.False(t, a.Equal(c)) | ||
} | ||
|
||
func TestAST_ArrayEquality(t *testing.T) { | ||
a := &ast.Array{ | ||
Expressions: []ast.Expression{ | ||
&ast.Attribute{Name: "a"}, | ||
&ast.Attribute{Name: "b"}, | ||
}, | ||
} | ||
|
||
b := &ast.Array{ | ||
Expressions: []ast.Expression{ | ||
&ast.Attribute{Name: "a"}, | ||
&ast.Attribute{Name: "b"}, | ||
}, | ||
} | ||
|
||
c := &ast.Array{ | ||
Expressions: []ast.Expression{ | ||
&ast.Attribute{Name: "b"}, | ||
&ast.Attribute{Name: "a"}, | ||
}, | ||
} | ||
|
||
assert.True(t, a.Equal(a)) // should be equal to itself | ||
assert.True(t, a.Equal(b)) // should be equal to another identical array | ||
assert.False(t, a.Equal(c)) | ||
} | ||
|
||
func TestAST_TupleEquality(t *testing.T) { | ||
a := &ast.Tuple{ | ||
Members: []ast.Expression{ | ||
&ast.Attribute{Name: "a"}, | ||
&ast.Attribute{Name: "b"}, | ||
}, | ||
} | ||
|
||
b := &ast.Tuple{ | ||
Members: []ast.Expression{ | ||
&ast.Attribute{Name: "a"}, | ||
&ast.Attribute{Name: "b"}, | ||
}, | ||
} | ||
|
||
c := &ast.Tuple{ | ||
Members: []ast.Expression{ | ||
&ast.Attribute{Name: "b"}, | ||
&ast.Attribute{Name: "a"}, | ||
}, | ||
} | ||
|
||
assert.True(t, a.Equal(a)) // should be equal to itself | ||
assert.True(t, a.Equal(b)) // should be equal to another identical tuple | ||
assert.False(t, a.Equal(c)) | ||
} |