Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require the last type declaration to have a new line. #3926

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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