Last active
February 3, 2024 20:55
-
-
Save inkydragon/7f708dd18f11b801ab7e61ee0912c0c5 to your computer and use it in GitHub Desktop.
Julialang/julia #parser issue tag; Maybe those tests could be add to JuliaSyntax.jl.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-License-Identifier: MIT | |
using Test | |
using Base.JuliaSyntax | |
using Base.JuliaSyntax: Diagnostic | |
# copy from: https://github.com/JuliaLang/JuliaSyntax.jl/blob/a6f2d1580f7bbad11822033e8c83e607aa31f100/test/diagnostics.jl#L1-L12 | |
function diagnostic(str; only_first=false, allow_multiple=false, rule=:all, version=v"1.6") | |
stream = JuliaSyntax.ParseStream(str; version=version) | |
JuliaSyntax.parse!(stream, rule=rule) | |
if allow_multiple | |
stream.diagnostics | |
else | |
if !only_first | |
@test length(stream.diagnostics) == 1 | |
end | |
return isempty(stream.diagnostics) ? nothing : stream.diagnostics[1] | |
end | |
end | |
@testset "Julialang/julia #parser issue tag" begin | |
@test :issues50228 == Symbol("issues50228") | |
@test_broken :50228 == Symbol("50228") | |
# Throw an error or not | |
@test diagnostic("issue9180() = false ? nothing : return(0)"; only_first=true) === nothing | |
@test diagnostic("issue9180() = false ? return(0) : nothing"; only_first=true) == | |
Diagnostic(42, 41, :error, "space required before `:` in `?` expression") | |
@test diagnostic("issue20844 = function(); () end"; only_first=true) === nothing | |
@test diagnostic("issue20844 = function() () end") == | |
Diagnostic(24, 25, :error, "whitespace is not allowed here") | |
@test diagnostic(raw":(issue31106(path) do x; end)"; only_first=true) === nothing | |
@test diagnostic(raw":(issue31106[path] do x; end)"; only_first=true) == | |
Diagnostic(20, 24, :error, "Expected `)`") | |
@test diagnostic(raw":(issue31432 $ xs)"; only_first=true) === nothing | |
@test diagnostic(raw":(issue31432 .$ xs)"; only_first=true) == | |
Diagnostic(13, 13, :error, "whitespace is not allowed here") | |
@test diagnostic("issue32182(@bar while i in x; end)"; only_first=true) === nothing | |
@test diagnostic("issue32182(@bar for i in x; end)"; only_first=true) == | |
Diagnostic(31, 30, :error, "Expected `)`") | |
@test diagnostic("issue34560[end 1]"; only_first=true) === nothing | |
@test diagnostic("issue34560[1 end]"; only_first=true) == | |
Diagnostic(14, 13, :error, "Expected `]`") | |
@test diagnostic("34457primitive type Issue 16 end"; only_first=true) === nothing | |
@test diagnostic("34457struct Issue end") == | |
Diagnostic(6, 21, :error, "extra tokens after end of expression") | |
@test diagnostic("(begin; () -> 49490; end)()"; only_first=true) === nothing | |
@test diagnostic(" begin; () -> 49490; end()"; only_first=true) == | |
Diagnostic(25, 26, :error, "extra tokens after end of expression") | |
@test diagnostic("Float64[ 50265 for _ in 1:3 ]"; only_first=true) === nothing | |
@test diagnostic(" [ begin 50265 end for _ in 1:3 ]"; only_first=true) === nothing | |
@test diagnostic("Float64[ begin 50265 end for _ in 1:3 ]"; only_first=true) == | |
Diagnostic(22, 21, :error, "Expected `]`") | |
# Should throw an error | |
@test_broken diagnostic("begin 34457end"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("33735issue = 0"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("issue50415 = continue"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("issue50415 = return"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("issue50415 = break"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("issue50415 = throw"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("issue50415 = @goto"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("function f(::T) where {T}_invalid_var; 51999; end"; only_first=true) isa Diagnostic | |
@test_broken diagnostic("if false println(); 52014; end"; only_first=true) isa Diagnostic | |
@test diagnostic("if false 1 2 true; 52014; end"; only_first=true) == | |
Diagnostic(12, 26, :error, "Expected `end`") | |
# Better error msg | |
@test diagnostic(":(issue26750 ? :(@simd) : :@identity)"; only_first=true) === nothing | |
@test diagnostic(":(issue26750 ? :@simd : :@identity)"; only_first=true) == | |
Diagnostic(26, 26, :error, "whitespace not allowed after `:` used for quoting") | |
@test diagnostic(" ( @async for i in 1:50446 end )"; only_first=true) === nothing | |
@test diagnostic("wait( @async for i in 1:50446 end )"; only_first=true) == | |
Diagnostic(31, 30, :error, "Expected `)`") | |
@test diagnostic("wait((@async for i in 1:50446 end))"; only_first=true) == | |
Diagnostic(31, 30, :error, "Expected `)`") | |
# Maybe: "SyntaxError: invalid syntax. Perhaps you forgot a comma?" | |
@test diagnostic("f(3,4 52285)"; only_first=true) == | |
Diagnostic(7, 11, :error, "Expected `)`") | |
# Features and enhancements | |
@test diagnostic("issue5903=1"; only_first=true) == | |
Diagnostic(10, 12, :error, "unknown unicode character '='") | |
@test diagnostic("export Issue14472.func"; only_first=true) == | |
Diagnostic(18, 22, :error, "extra tokens after end of expression") | |
@test diagnostic("@issue15730(2) do x; inv(x); end"; only_first=true) === nothing | |
@test diagnostic("@issue15730 2 do x; inv(x); end"; only_first=true) == | |
Diagnostic(16, 17, :error, "invalid `do` syntax") | |
@test diagnostic(".√(issue23814)"; only_first=true) === nothing | |
@test diagnostic("√.(issue23814)") == Diagnostic(4, 4, :error, "invalid identifier") | |
@test diagnostic("issue25512 !in []") == | |
Diagnostic(11, 17, :error, "extra tokens after end of expression") | |
@test diagnostic("⟨ issue35288 ⟩"; only_first=true) == | |
Diagnostic(1, 3, :error, "unknown unicode character '⟨'") | |
# Allow more Unicode characters: `Char.(0x2983:0x298A)` | |
@test diagnostic("⟦issue48885⟧ = 1"; only_first=true) == | |
Diagnostic(1, 3, :error, "unknown unicode character '⟦'") | |
# Allow variables to begin with subscripted numbers | |
@test diagnostic("₂F₁ = 50519"; only_first=true) == | |
Diagnostic(1, 3, :error, "unknown unicode character '₂'") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment