Skip to content

Commit

Permalink
Remove comments from AST dump in test expectations
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
StevenACoffman committed Jul 16, 2023
1 parent 4fb27a5 commit 394978a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion generate/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package generate
import (
"path/filepath"
"sort"
"strings"
"testing"

"github.com/vektah/gqlparser/v2/ast"
Expand Down Expand Up @@ -57,7 +58,8 @@ func TestParse(t *testing.T) {
t.Run(ext, func(t *testing.T) {
queries := getTestQueries(t, ext)

got, want := ast.Dump(graphqlQueries), ast.Dump(queries)
got, want := ast.Dump(graphqlQueries), removeComments(ast.Dump(queries))

if got != want {
// TODO: nice diffing
t.Errorf("got:\n%v\nwant:\n%v\n", got, want)
Expand All @@ -66,6 +68,18 @@ func TestParse(t *testing.T) {
}
}

func removeComments(gotWithComments string) string {
var gots []string
for _, s := range strings.Split(gotWithComments, "\n") {
if strings.Contains(s, `Comment:`) {
continue
}
gots = append(gots, s)
}
got := strings.Join(gots, "\n")
return got
}

// TestParseErrors tests that query-extraction from different language source files
// produces appropriate errors if your query is invalid.
func TestParseErrors(t *testing.T) {
Expand Down

0 comments on commit 394978a

Please sign in to comment.