Skip to content

Commit

Permalink
refactor: remove regex-match
Browse files Browse the repository at this point in the history
  • Loading branch information
speezepearson committed Mar 20, 2022
1 parent 16a6f67 commit de37d10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 0 additions & 4 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package schema

import (
"fmt"
"regexp"
"text/scanner"

"github.com/graph-gophers/graphql-go/errors"
Expand Down Expand Up @@ -524,9 +523,6 @@ func parseDirectiveDef(l *common.Lexer) *types.DirectiveDefinition {

for {
loc := l.ConsumeIdent()
if ok, err := regexp.MatchString("^[A-Z][A-Z_]+$", loc); err != nil || !ok {
l.SyntaxError(fmt.Sprintf("expected directive location-spec to be SNAKE_CASE, but got %q", loc))
}
d.Locations = append(d.Locations, loc)
if l.Peek() != '|' {
break
Expand Down
7 changes: 4 additions & 3 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schema_test

import (
"fmt"
"strings"
"testing"

"github.com/graph-gophers/graphql-go/internal/schema"
Expand Down Expand Up @@ -912,9 +913,9 @@ Second line of the description.
scalar MyScalar @mydirective
`,
validateError: func(err error) error {
msg := `graphql: syntax error: expected directive location-spec to be SNAKE_CASE, but got "on" (line 2, column 33)`
if err == nil || err.Error() != msg {
return fmt.Errorf("expected error %q, but got %q", msg, err)
prefix := `graphql: syntax error:`
if err == nil || !strings.HasPrefix(err.Error(), prefix) {
return fmt.Errorf("expected error starting with %q, but got %q", prefix, err)
}
return nil
},
Expand Down

0 comments on commit de37d10

Please sign in to comment.