Skip to content

Commit

Permalink
Add support for block strings into parser
Browse files Browse the repository at this point in the history
Signed-off-by: James Phillips <jamesdphillips@gmail.com>
  • Loading branch information
jamesdphillips committed Dec 12, 2017
1 parent 089c28d commit 0629778
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions language/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,53 @@ func TestLexer_LexesBlockStrings(t *testing.T) {
}
}

func TestLexer_ReportsUsefulBlockStringErrors(t *testing.T) {
tests := []Test{
{
Body: `"""`,
Expected: `Syntax Error GraphQL (1:4) Unterminated string.
1: """
^
`,
},
{
Body: `"""no end quote`,
Expected: `Syntax Error GraphQL (1:16) Unterminated string.
1: """no end quote
^
`,
},
{
Body: "\"\"\"contains unescaped \u0007 control char\"\"\"",
Expected: `Syntax Error GraphQL (1:23) Invalid character within String: "\\u0007".
1: """contains unescaped \u0007 control char"""
^
`,
},
{
Body: "\"\"\"null-byte is not \u0000 end of file\"\"\"",
Expected: `Syntax Error GraphQL (1:21) Invalid character within String: "\\u0000".
1: """null-byte is not \u0000 end of file"""
^
`,
},
}
for _, test := range tests {
_, err := Lex(createSource(test.Body))(0)
if err == nil {
t.Errorf("unexpected nil error\nexpected:\n%v\n\ngot:\n%v", test.Expected, err)
}

if err.Error() != test.Expected {
t.Errorf("unexpected error.\nexpected:\n%v\n\ngot:\n%v", test.Expected, err.Error())
}
}
}

func TestLexer_LexesNumbers(t *testing.T) {
tests := []Test{
{
Expand Down
2 changes: 2 additions & 0 deletions language/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ func parseValueLiteral(parser *Parser, isConst bool) (ast.Value, error) {
Value: token.Value,
Loc: loc(parser, token.Start),
}), nil
case lexer.TokenKind[lexer.BLOCK_STRING]:
fallthrough
case lexer.TokenKind[lexer.STRING]:
if err := advance(parser); err != nil {
return nil, err
Expand Down

0 comments on commit 0629778

Please # to comment.