Skip to content

Commit 1efde32

Browse files
committed
more test fixes
1 parent 53d4cf8 commit 1efde32

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,31 @@ function complete_path(path::AbstractString;
363363
return matches, dir, !isempty(matches)
364364
end
365365

366+
function complete_path(path::AbstractString,
367+
pos::Int;
368+
use_envpath=false,
369+
shell_escape=false,
370+
string_escape=false)
371+
Base.depwarn("complete_path with pos argument is deprecated because the return value [2] is incorrect to use", :complete_path)
372+
paths, dir, success = complete_path(path; use_envpath, shell_escape, string_escape)
373+
if success
374+
if Base.Sys.isunix() && occursin(r"^~(?:/|$)", path)
375+
# if the path is just "~", don't consider the expanded username as a prefix
376+
if path == "~"
377+
dir, prefix = homedir(), ""
378+
else
379+
dir, prefix = splitdir(homedir() * path[2:end])
380+
end
381+
else
382+
dir, prefix = splitdir(path)
383+
end
384+
startpos = pos - lastindex(prefix) + 1
385+
else
386+
startpos = pos + 1
387+
end
388+
return paths, startpos:pos, success
389+
end
390+
366391
function complete_expanduser(path::AbstractString, r)
367392
expanded =
368393
try expanduser(path)

stdlib/REPL/test/replcompletions.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ let current_dir, forbidden
11941194
catch e
11951195
e isa Base.IOError && occursin("ELOOP", e.msg)
11961196
end
1197-
c, r = test_complete("\""*escape_string(joinpath(path, "selfsym")))
1197+
c, r = test_complete("\"$(escape_string(path))/selfsym")
11981198
@test c == ["selfsymlink"]
11991199
end
12001200
end
@@ -1244,7 +1244,7 @@ mktempdir() do path
12441244

12451245
# For normal strings the string should be properly escaped according to
12461246
# the usual rules for Julia strings.
1247-
s = "cd(\"" * julia_esc(joinpath(path, space_folder, "space"))
1247+
s = "cd(\"" * julia_esc(joinpath(path, space_folder) * "/space")
12481248
c, r = test_complete(s)
12491249
@test s[r] == "space"
12501250
@test "space .file\"" in c
@@ -1253,7 +1253,7 @@ mktempdir() do path
12531253
# which needs to be escaped in Julia strings (on unix we could do this
12541254
# test with all sorts of special chars)
12551255
touch(joinpath(space_folder, "needs_escape\$.file"))
1256-
escpath = julia_esc(joinpath(path, space_folder, "needs_escape\$"))
1256+
escpath = julia_esc(joinpath(path, space_folder) * "/needs_escape\$")
12571257
s = "cd(\"$escpath"
12581258
c, r = test_complete(s)
12591259
@test s[r] == "needs_escape\\\$"
@@ -1290,7 +1290,7 @@ mktempdir() do path
12901290
# in shell commands the shell path completion cannot complete
12911291
# paths with these characters
12921292
c, r, res = test_scomplete(test_dir)
1293-
@test c[1] == '\''*test_dir*(Sys.iswindows() ? "\\\\" : "/")*'\''
1293+
@test c[1] == '\''*test_dir*(Sys.iswindows() ? "\\" : "/")*'\''
12941294
@test res
12951295
end
12961296
escdir = julia_esc(test_dir)
@@ -1331,8 +1331,13 @@ if Sys.iswindows()
13311331
cd(path) do
13321332
s = "cd ..\\\\"
13331333
c,r = test_scomplete(s)
1334+
@test r == lastindex(s)-3:lastindex(s)
1335+
@test "../'$temp_name\\'" in c
1336+
1337+
s = "cd ../"
1338+
c,r = test_scomplete(s)
13341339
@test r == lastindex(s)+1:lastindex(s)
1335-
@test temp_name * "\\\\" in c
1340+
@test "'$temp_name\\'" in c
13361341

13371342
s = "ls $(file[1:2])"
13381343
c,r = test_scomplete(s)
@@ -1342,7 +1347,12 @@ if Sys.iswindows()
13421347
s = "cd(\"..\\\\"
13431348
c,r = test_complete(s)
13441349
@test r == lastindex(s)+1:lastindex(s)
1345-
@test temp_name * "\\\\" in c
1350+
@test "../$temp_name\\\\" in c
1351+
1352+
s = "cd(\"../"
1353+
c,r = test_complete(s)
1354+
@test r == lastindex(s)-3:lastindex(s)
1355+
@test "$temp_name\\\\" in c
13461356

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

0 commit comments

Comments
 (0)