Skip to content

Commit ea0716e

Browse files
author
takeshi.nakata
committed
modify make token by byte position, not rune position at readName
1 parent 8a92e97 commit ea0716e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

language/lexer/lexer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func readName(source *source.Source, position, runePosition int) Token {
129129
break
130130
}
131131
}
132-
return makeToken(NAME, runePosition, endRune, string(body[position:endByte]))
132+
return makeToken(NAME, position, endByte, string(body[position:endByte]))
133133
}
134134

135135
// Reads a number token from the source file, either a float

language/lexer/lexer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ func TestLexer_AcceptsBOMHeader(t *testing.T) {
9191
Body: "\uFEFF foo",
9292
Expected: Token{
9393
Kind: NAME,
94-
Start: 2,
95-
End: 5,
94+
Start: 4,
95+
End: 7,
9696
Value: "foo",
9797
},
9898
},

language/parser/parser_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,19 @@ func TestParsesEnumValueDefinitionWithDescription(t *testing.T) {
498498
}
499499
}
500500

501+
func TestParsesTypeDefinitionWithMultiByteCharactersComment_UnicodeText(t *testing.T) {
502+
source := `
503+
# This comment has a фы世界 character.
504+
type Foo implements Bar {
505+
foo: String!
506+
}
507+
`
508+
_, err := Parse(ParseParams{Source: source})
509+
if err != nil {
510+
t.Fatalf("unexpected error: %v", err)
511+
}
512+
}
513+
501514
func TestDefinitionsWithDescriptions(t *testing.T) {
502515
testCases := []struct {
503516
name string

0 commit comments

Comments
 (0)