👀 Reading hidden code
using PlutoTest
👀 Reading hidden code
using PlutoUI
ends_with_semicolon_original (generic function with 1 method)
👀 Reading hidden code
ends_with_semicolon2 (generic function with 2 methods)
👀 Reading hidden code
begin
let matchend = Dict("\"" => r"\"", "\"\"\"" => r"\"\"\"", "'" => r"'",
"`" => r"`", "```" => r"```", "#" => r"$"m, "#=" => r"=#|#=")
buf = IOBuffer(sizehint = sizeof(code))
pos = 1
while true
nested = 1
end
end
end
else
end
end
end
end
ends_with_semicolon2(code::Union{String,SubString{String}}) =
end
ends_with_semicolon_new (generic function with 1 method)
function ends_with_semicolon_new(line::AbstractString)
stripped_line = _remove_strings_and_comments(line)
match = findlast(isequal(';'), stripped_line)::Union{Nothing,Int}
return match !== nothing && all(isspace, stripped_line[(match + 1):end])
end
👀 Reading hidden code
_remove_strings_and_comments (generic function with 1 method)
function _remove_strings_and_comments(s)
# remove string literals
# """hello"""
s = replace(s, r"\"\"\".*?[^\\]\"\"\""s => "julia")
# "hello"
s = replace(s, r"\"(\\\\\"|[^\"])*\"" => "philip")
# ```hello```
s = replace(s, r"```.*?```"s => "the")
# `hello`
s = replace(s, r"`(\\`|[^`])*`" => "corgi")
# remove multiline #= comments =#
# s = replace(s, r"\#=(?:[^(\#=)(=\#)]+|(?R))*+=\#" => "")
s = replace(s, r"\#=(?:([^\#\=]|\=(?!\#)|\#(?!\=))+|(?R))*+=\#" => "")
# remove single line # comments
s = replace(s, r"#.*" => "")
end
👀 Reading hidden code
r"\"(\\\\\"|[^\"])*\""
rr = r"\"(\\\\\"|[^\"])*\""
👀 Reading hidden code
"(\\"|[^"])*"
r"\"(\\\\\"|[^\"])*\"".pattern |> Text
👀 Reading hidden code
RegexMatch("\"asfd\"", 1="d")
RegexMatch("\" a\\\"b \"", 1=" ")
RegexMatch("\"\"", 1=nothing)
RegexMatch("\"wow \"", 1=" ")
RegexMatch("\"\"", 1=nothing)
RegexMatch("\"\n(e\"", 1="e")
RegexMatch("\" + \"", 1=" ")
RegexMatch("\" eee)\n r\"", 1="r")
RegexMatch("\" ff\"", 1="f")
eachmatch(rr, ss) |> collect
👀 Reading hidden code
"asfd" ee " a\"b " c
"""wow "asdf """
(e"f()= 1; # a " + " no" eee)
r" \" ff"f
r` \` `f e``e
Text(ss)
👀 Reading hidden code
" \"asfd\" ee \" a\\\"b \" c\n\t\n\"\"\"wow \"asdf \"\"\"\n(e\"f()= 1; # a \" + \" no\" eee)\n r\" \\\" ff\"f\n r` \\` `f e``e\n\t"
ss = """
"asfd" ee " a\\"b " c
\"\"\"wow "asdf \"\"\"
(e"f()= 1; # a " + " no" eee)
r" \\" ff"f
r` \\` `f e``e
"""
👀 Reading hidden code
philip ee philip c
julia
(ephilip + philip eee)
rphilipf
rcorgif ecorgie
👀 Reading hidden code
julia
_remove_strings_and_comments("""
""\"
asdf
""\"
""") |> Text
👀 Reading hidden code
_remove_strings_and_comments("""
#=#= #
asdf
=#b=#
""") |> Text
👀 Reading hidden code
a;
_remove_strings_and_comments("""
a; #=#=#
=#b=#
# test
#=
foobar
=##bazbax
""") |> Text
👀 Reading hidden code
philip dont remove me!
leave me
fons juju
_remove_strings_and_comments("""
" # " dont remove me!
leave me # im gone
fons #= van #= der =# plas =# juju
""") |> Text
👀 Reading hidden code
" asd ` "
`\``
" asd ` " , ` ""\` `
👀 Reading hidden code
Before / after
Use function:
👀 Reading hidden code
New test cases
👀 Reading hidden code
" \"asfd\" ee \" a\\\"b \" c\n\t\n\"\"\"wow \"asdf \"\"\"\n(e\"f()= 1; # a \" + \" no\" eee)\n r\" \\\" ff\"f\n r` \\` `f e``e\n\t"
begin
ss # """
ss; # """
end
👀 Reading hidden code
foo # """
bar; # """
let
"foo # \"\"\"\n bar; # \"\"\" " |> Text
end
👀 Reading hidden code
true
@test ends_with_semicolon("""
ss # ""\"
ss; # ""\"
""")
👀 Reading hidden code
false
@test ends_with_semicolon("f()= 1; # a ; 2")
👀 Reading hidden code
Test Failed at /home/runner/work/disorganised-mess/disorganised-mess/ends_with_semicolon.jl#==#94187d97-12c0-4cb4-8dcd-8494f0a99b27:1 Expression: ends_with_semicolon("f()= 1; # a ; 2") Evaluated:
false
@test !ends_with_semicolon("f()= 1; \"asdf\"")
👀 Reading hidden code
false
@test !ends_with_semicolon("""
";"
""")
👀 Reading hidden code
false
@test !ends_with_semicolon("""
";" # asdf
""")
👀 Reading hidden code
true
@test ends_with_semicolon(
"f()= 1; # a"
)
👀 Reading hidden code
true
@test !ends_with_semicolon(
"""
("f()= 1; # a")
"""
)
👀 Reading hidden code
Test Failed at /home/runner/work/disorganised-mess/disorganised-mess/ends_with_semicolon.jl#==#7b51546f-1b95-4f9f-ba6e-b054df5bcb85:1 Expression: !(ends_with_semicolon("(\"f()= 1; # a\")\n")) Evaluated:
true
@test !ends_with_semicolon(
"""
"f()= 1; # a"
"""
)
👀 Reading hidden code
Test Failed at /home/runner/work/disorganised-mess/disorganised-mess/ends_with_semicolon.jl#==#546bf639-efb0-4d7e-8e5c-dcf29b09de43:1 Expression: !(ends_with_semicolon("\"f()= 1; # a\"\n")) Evaluated:
true
@test ends_with_semicolon("f()= 1;")
👀 Reading hidden code
false
@test !ends_with_semicolon(
"1;" * " #= =# 2"
)
👀 Reading hidden code
true
@test_nowarn ends_with_semicolon(
"1;" * " #=# 2"
)
👀 Reading hidden code
true
@test !ends_with_semicolon("a # asdf ;")
👀 Reading hidden code
Test Failed at /home/runner/work/disorganised-mess/disorganised-mess/ends_with_semicolon.jl#==#adf3404a-c691-4a0a-8c42-25cab39da17a:1 Expression: !(ends_with_semicolon("a # asdf ;")) Evaluated:
true
@test !ends_with_semicolon("a # asdf ;")
👀 Reading hidden code
Test Failed at /home/runner/work/disorganised-mess/disorganised-mess/ends_with_semicolon.jl#==#d192bf86-bb28-42f9-970c-7b7bd634cd67:1 Expression: !(ends_with_semicolon("a # asdf ;")) Evaluated:
true
@test ends_with_semicolon("""a * "#" ;""")
👀 Reading hidden code
false
@test !ends_with_semicolon("\"\\\";\"#\"")
👀 Reading hidden code
"\";"
"\";"#"
👀 Reading hidden code
"\";"#"
Text(
"\"\\\";\"#\""
)
👀 Reading hidden code
true
@test ends_with_semicolon(
"\"\\\\\";#\""
)
👀 Reading hidden code
true
@test ends_with_semicolon(
"é; #é \"é\""
)
👀 Reading hidden code
👀 Reading hidden code
true
begin
@test ends_with_semicolon("""1;\n#text\n""")
end
👀 Reading hidden code
true
@test ends_with_semicolon("a; #=#=# =# =#\n")
👀 Reading hidden code
false
@test !ends_with_semicolon("begin\na;\nb;\nend")
👀 Reading hidden code
false
@test !ends_with_semicolon("begin\na; #=#=#\n=#b=#\nend")
👀 Reading hidden code
true
@test ends_with_semicolon("\na; #=#=#\n=#b=#\n# test\n#=\nfoobar\n=##bazbax\n")
👀 Reading hidden code
Old test cases
👀 Reading hidden code
false
@test !ends_with_semicolon("")
👀 Reading hidden code
true
@test ends_with_semicolon(";")
👀 Reading hidden code
false
@test !ends_with_semicolon("a")
👀 Reading hidden code
true
@test ends_with_semicolon("1;")
👀 Reading hidden code
true
@test ends_with_semicolon("1;\n")
👀 Reading hidden code
true
@test ends_with_semicolon("1;\r")
👀 Reading hidden code
true
@test ends_with_semicolon("1;\r\n \t\f")
👀 Reading hidden code
@test ends_with_semicolon("1;#text\n")
👀 Reading hidden code
true
@test ends_with_semicolon("a; #=#=# =# =#\n")
👀 Reading hidden code
false
@test !ends_with_semicolon("begin\na;\nb;\nend")
👀 Reading hidden code
false
@test !ends_with_semicolon("begin\na; #=#=#\n=#b=#\nend")
👀 Reading hidden code
true
@test ends_with_semicolon("\na; #=#=#\n=#b=#\n# test\n#=\nfoobar\n=##bazbax\n")
👀 Reading hidden code