Skip to content

Commit

Permalink
Don't assume that SubString has pointer and copy instead
Browse files Browse the repository at this point in the history
Still assume `Substring{String}` has `pointer`

Add tests
  • Loading branch information
LilithHafner committed Sep 16, 2024
1 parent f21fb80 commit b2ab29e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/parse_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function ParseStream(text::String, index::Integer=1; version=VERSION)
ParseStream(unsafe_wrap(Vector{UInt8}, text),
text, index, version)
end
function ParseStream(text::SubString, index::Integer=1; version=VERSION)
function ParseStream(text::SubString{String}, index::Integer=1; version=VERSION)
# See also IOBuffer(SubString("x"))
ParseStream(unsafe_wrap(Vector{UInt8}, pointer(text), sizeof(text)),
text, index, version)
Expand Down
12 changes: 11 additions & 1 deletion test/parse_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ using JuliaSyntax: ParseStream,
peek, peek_token,
bump, bump_trivia, bump_invisible,
emit, emit_diagnostic, TRIVIA_FLAG, INFIX_FLAG,
ParseStreamPosition, first_child_position, last_child_position
ParseStreamPosition, first_child_position, last_child_position,
parsestmt

import InlineStrings

# Here we manually issue parse events in the order the Julia parser would issue
# them
Expand Down Expand Up @@ -147,3 +150,10 @@ end
@test first_child_position(st, position(st)) == ParseStreamPosition(4, 1)
@test last_child_position(st, position(st)) == ParseStreamPosition(7, 2)
end

@testset "SubString{String3} (issue #505)" begin
x = split(InlineStrings.InlineString("1 2"))[1]
@test x == "1"
@test ParseStream(x) isa ParseStream
@test parsestmt(Expr, x) == parsestmt(Expr, "1")
end

0 comments on commit b2ab29e

Please sign in to comment.