Skip to content
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
53 changes: 51 additions & 2 deletions test/doctests/doctestapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,56 @@ Stacktrace:
[...]
```
"""
module ParseErrorSuccess end
module ParseErrorSuccess_1x00 end

"""
```jldoctest
julia> map(tuple, 1/(i+j) for i=1:2, j=1:2, [1:4;])
ERROR: ParseError:
# Error @ none:1:44
map(tuple, 1/(i+j) for i=1:2, j=1:2, [1:4;])
# └ ── invalid iteration spec: expected one of `=` `in` or `∈`
Stacktrace:
[...]
```
```jldoctest
julia> 1.2.3
ERROR: ParseError:
# Error @ none:1:1
1.2.3
└──┘ ── invalid numeric constant
# Error @ none:1:5
1.2.3
# ╙ ── extra tokens after end of expression
Stacktrace:
[...]
```
```jldoctest
println(9.8.7)
# output
ERROR: ParseError:
# Error @ none:1:9
println(9.8.7)
# └──┘ ── invalid numeric constant
# Error @ none:1:13
println(9.8.7)
# ╙ ── Expected `)`
Stacktrace:
[...]
```
```jldoctest
julia> Meta.ParseError("foo")
Base.Meta.ParseError("foo", nothing)

julia> Meta.ParseError("foo") |> throw
ERROR: ParseError("foo")
Stacktrace:
[...]
```
"""
module ParseErrorSuccess_1x10 end
# The JuliaSyntax swap in 1.10 changed the printing of parse errors quite considerably
ParseErrorSuccess() = (VERSION >= v"1.10.0-DEV.1520") ? ParseErrorSuccess_1x10 : ParseErrorSuccess_1x00

"""
```jldoctest
Expand Down Expand Up @@ -254,7 +303,7 @@ module BadDocTestKwargs3 end
end

# Parse errors in doctests (https://github.com/JuliaDocs/Documenter.jl/issues/1046)
run_doctest(nothing, [ParseErrorSuccess]) do result, success, backtrace, output
run_doctest(nothing, [ParseErrorSuccess()]) do result, success, backtrace, output
@test success
@test result isa Test.DefaultTestSet
end
Expand Down
34 changes: 28 additions & 6 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ end
@test exprs[2][2] == "γγγ_γγγ\n"

@test exprs[3][1] === :γγγ
@test exprs[3][2] == "γγγ\n"
if VERSION >= v"1.10.0-DEV.1520" # JuliaSyntax merge
@test exprs[3][2] == "γγγ\n\n"
else
@test exprs[3][2] == "γγγ\n"
end
end

@testset "TextDiff" begin
Expand All @@ -317,9 +321,14 @@ end
for LE in ("\r\n", "\n")
l1, l2 = parse("x = Int[]$(LE)$(LE)push!(x, 1)$(LE)")
@test l1[1] == :(x = Int[])
@test l1[2] == "x = Int[]$(LE)"
@test l2[1] == :(push!(x, 1))
@test l2[2] == "push!(x, 1)$(LE)"
if VERSION >= v"1.10.0-DEV.1520" # JuliaSyntax merge
@test l1[2] == "x = Int[]$(LE)$(LE)"
@test l2[2] == "push!(x, 1)$(LE)\n"
else
@test l1[2] == "x = Int[]$(LE)"
@test l2[2] == "push!(x, 1)$(LE)"
end
end
end
end
Expand All @@ -338,7 +347,11 @@ end
@test exs[1][1].head == :toplevel
@test exs[1][1].args[1] == LineNumberNode(124, "testfile.jl")
@test exs[1][1].args[2] == Expr(:call, :+, 1, 1)
@test exs[2][2] == "2 + 2\n"
if VERSION >= v"1.10.0-DEV.1520" # JuliaSyntax merge
@test exs[2][2] == "2 + 2\n\n"
else
@test exs[2][2] == "2 + 2\n"
end
@test exs[2][1].head == :toplevel
@test exs[2][1].args[1] == LineNumberNode(125, "testfile.jl")
@test exs[2][1].args[2] == Expr(:call, :+, 2, 2)
Expand All @@ -356,7 +369,15 @@ end
for code in (code1, code2)
exs = parse(code)
@test length(exs) == 1
@test exs[1][2] == "1 + 1\n"
if VERSION >= v"1.10.0-DEV.1520" # JuliaSyntax merge
if code == code1
@test exs[1][2] == "1 + 1\n\n\n"
else
@test exs[1][2] == "1 + 1\n# comment\n\n"
end
else
@test exs[1][2] == "1 + 1\n"
end
@test exs[1][1].head == :toplevel
@test exs[1][1].args[1] == LineNumberNode(124, "testfile.jl")
@test exs[1][1].args[2] == Expr(:call, :+, 1, 1)
Expand Down Expand Up @@ -493,7 +514,8 @@ end
# Ref: #639
@test jsescape("\u2028") == "\\u2028"
@test jsescape("\u2029") == "\\u2029"
@test jsescape("policy to
 delete.") == "policy to\\u2028 delete."
include("utilities.sample.jl")
@test jsescape(U2028_STRING) == "policy to\\u2028 delete."
end

@testset "json_jsescape" begin
Expand Down
4 changes: 4 additions & 0 deletions test/utilities.sample.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This string is defined in a separate file so that VS Code would not
# complain (or even accidentally "fix") the weird character we want
# to have present every time you open utilities.jl.
const U2028_STRING = "policy to
 delete."