Skip to content

Commit

Permalink
Do not require the last type declaration to have a new line. (#3926)
Browse files Browse the repository at this point in the history
Currently, one has to add a new line to the type declarations, even if
it's the last thing in the schema update. This PR changes the parser so
that the a type declaration does not require a new line if it's the last
thing in the schema update.
  • Loading branch information
martinmr authored Sep 6, 2019
1 parent 07da8f3 commit 7f493e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 4 additions & 3 deletions schema/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ func parseTypeDeclaration(it *lex.ItemIterator) (*pb.TypeUpdate, error) {
switch item.Typ {
case itemRightCurl:
it.Next()
if it.Item().Typ != itemNewLine {
return nil, it.Item().Errorf("Expected new line after type declaration. Got %v",
it.Item().Val)
if it.Item().Typ != itemNewLine && it.Item().Typ != lex.ItemEOF {
return nil, it.Item().Errorf(
"Expected new line or EOF after type declaration. Got %v", it.Item())
}
it.Prev()

typeUpdate.Fields = fields
return typeUpdate, nil
Expand Down
15 changes: 14 additions & 1 deletion schema/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,19 @@ func TestParseEmptyType(t *testing.T) {

}

func TestParseTypeEOF(t *testing.T) {
reset()
result, err := Parse(`
type Person {
}`)
require.NoError(t, err)
require.Equal(t, 1, len(result.Types))
require.Equal(t, &pb.TypeUpdate{
TypeName: "Person",
}, result.Types[0])

}

func TestParseSingleType(t *testing.T) {
reset()
result, err := Parse(`
Expand Down Expand Up @@ -666,7 +679,7 @@ func TestParseTypeErrMissingNewLine(t *testing.T) {
}type Animal {}
`)
require.Error(t, err)
require.Contains(t, err.Error(), "Expected new line after type declaration")
require.Contains(t, err.Error(), "Expected new line or EOF after type declaration")
}

func TestParseTypeErrMissingColon(t *testing.T) {
Expand Down

0 comments on commit 7f493e9

Please sign in to comment.