Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 13, 2023
1 parent 53d4cf8 commit 1efde32
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
25 changes: 25 additions & 0 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,31 @@ function complete_path(path::AbstractString;
return matches, dir, !isempty(matches)
end

function complete_path(path::AbstractString,
pos::Int;
use_envpath=false,
shell_escape=false,
string_escape=false)
Base.depwarn("complete_path with pos argument is deprecated because the return value [2] is incorrect to use", :complete_path)
paths, dir, success = complete_path(path; use_envpath, shell_escape, string_escape)
if success
if Base.Sys.isunix() && occursin(r"^~(?:/|$)", path)
# if the path is just "~", don't consider the expanded username as a prefix
if path == "~"
dir, prefix = homedir(), ""
else
dir, prefix = splitdir(homedir() * path[2:end])
end
else
dir, prefix = splitdir(path)
end
startpos = pos - lastindex(prefix) + 1
else
startpos = pos + 1
end
return paths, startpos:pos, success
end

function complete_expanduser(path::AbstractString, r)
expanded =
try expanduser(path)
Expand Down
22 changes: 16 additions & 6 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ let current_dir, forbidden
catch e
e isa Base.IOError && occursin("ELOOP", e.msg)
end
c, r = test_complete("\""*escape_string(joinpath(path, "selfsym")))
c, r = test_complete("\"$(escape_string(path))/selfsym")
@test c == ["selfsymlink"]
end
end
Expand Down Expand Up @@ -1244,7 +1244,7 @@ mktempdir() do path

# For normal strings the string should be properly escaped according to
# the usual rules for Julia strings.
s = "cd(\"" * julia_esc(joinpath(path, space_folder, "space"))
s = "cd(\"" * julia_esc(joinpath(path, space_folder) * "/space")
c, r = test_complete(s)
@test s[r] == "space"
@test "space .file\"" in c
Expand All @@ -1253,7 +1253,7 @@ mktempdir() do path
# which needs to be escaped in Julia strings (on unix we could do this
# test with all sorts of special chars)
touch(joinpath(space_folder, "needs_escape\$.file"))
escpath = julia_esc(joinpath(path, space_folder, "needs_escape\$"))
escpath = julia_esc(joinpath(path, space_folder) * "/needs_escape\$")
s = "cd(\"$escpath"
c, r = test_complete(s)
@test s[r] == "needs_escape\\\$"
Expand Down Expand Up @@ -1290,7 +1290,7 @@ mktempdir() do path
# in shell commands the shell path completion cannot complete
# paths with these characters
c, r, res = test_scomplete(test_dir)
@test c[1] == '\''*test_dir*(Sys.iswindows() ? "\\\\" : "/")*'\''
@test c[1] == '\''*test_dir*(Sys.iswindows() ? "\\" : "/")*'\''
@test res
end
escdir = julia_esc(test_dir)
Expand Down Expand Up @@ -1331,8 +1331,13 @@ if Sys.iswindows()
cd(path) do
s = "cd ..\\\\"
c,r = test_scomplete(s)
@test r == lastindex(s)-3:lastindex(s)
@test "../'$temp_name\\'" in c

s = "cd ../"
c,r = test_scomplete(s)
@test r == lastindex(s)+1:lastindex(s)
@test temp_name * "\\\\" in c
@test "'$temp_name\\'" in c

s = "ls $(file[1:2])"
c,r = test_scomplete(s)
Expand All @@ -1342,7 +1347,12 @@ if Sys.iswindows()
s = "cd(\"..\\\\"
c,r = test_complete(s)
@test r == lastindex(s)+1:lastindex(s)
@test temp_name * "\\\\" in c
@test "../$temp_name\\\\" in c

s = "cd(\"../"
c,r = test_complete(s)
@test r == lastindex(s)-3:lastindex(s)
@test "$temp_name\\\\" in c

s = "cd(\"$(file[1:2])"
c,r = test_complete(s)
Expand Down

0 comments on commit 1efde32

Please sign in to comment.