Skip to content

Commit

Permalink
e2e: prevent identifiers from being keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedt committed Apr 14, 2022
1 parent f237d1c commit a3cfd42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 9 additions & 1 deletion e2e/generator/names.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package generator

import "github.com/brianvoe/gofakeit/v6"
import (
"github.com/brianvoe/gofakeit/v6"

"github.com/authzed/spicedb/pkg/schemadsl/lexer"
)

type UniqueGenerator struct {
seen map[string]struct{}
Expand All @@ -17,6 +21,10 @@ func NewUniqueGenerator(regex string) *UniqueGenerator {
func (g *UniqueGenerator) Next() string {
for {
val := gofakeit.Regex(g.regex)
if lexer.IsKeyword(val) {
continue
}

if _, ok := g.seen[val]; !ok {
g.seen[val] = struct{}{}
return val
Expand Down
16 changes: 11 additions & 5 deletions pkg/schemadsl/lexer/lex_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ const (
)

// keywords contains the full set of keywords supported.
var keywords = map[string]bool{
"definition": true,
"relation": true,
"permission": true,
"nil": true,
var keywords = map[string]struct{}{
"definition": {},
"relation": {},
"permission": {},
"nil": {},
}

// IsKeyword returns whether the specified input string is a reserved keyword.
func IsKeyword(candidate string) bool {
_, ok := keywords[candidate]
return ok
}

// syntheticPredecessors contains the full set of token types after which, if a newline is found,
Expand Down

0 comments on commit a3cfd42

Please sign in to comment.