Skip to content

Commit

Permalink
splitdrive under windows (JuliaLang#19695)
Browse files Browse the repository at this point in the history
* splitdrive under windows

* splitdrive under windows tests

* more test

* move tests outside loop over S

* changed test cases to S("...")
  • Loading branch information
augustinyiptong authored and Andy Ferris committed Jan 4, 2017
1 parent 02ad926 commit a9b114c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ elseif is_windows()
const path_ext_splitter = r"^((?:.*[/\\])?(?:\.|[^/\\\.])[^/\\]*?)(\.[^/\\\.]*|)$"

function splitdrive(path::String)
m = match(r"^(\w+:|\\\\\w+\\\w+|\\\\\?\\UNC\\\w+\\\w+|\\\\\?\\\w+:|)(.*)$", path)
m = match(r"^([^\\]+:|\\\\[^\\]+\\[^\\]+|\\\\\?\\UNC\\[^\\]+\\[^\\]+|\\\\\?\\[^\\]+:|)(.*)$", path)
String(m.captures[1]), String(m.captures[2])
end
else
Expand Down
9 changes: 9 additions & 0 deletions test/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ for S in (String, GenericString)
@test joinpath(splitdir(S(homedir()))...) == homedir()
@test string(splitdrive(S(homedir()))...) == homedir()

if is_windows()
@test splitdrive(S("\\\\servername\\hello.world\\filename.ext")) ==
("\\\\servername\\hello.world","\\filename.ext")
@test splitdrive(S("\\\\servername.com\\hello.world\\filename.ext")) ==
("\\\\servername.com\\hello.world","\\filename.ext")
@test splitdrive(S("C:\\foo\\bar")) ==
("C:","\\foo\\bar")
end

@test splitext(S("")) == ("", "")
@test splitext(S(".")) == (".", "")
@test_broken splitext(S("..")) == ("..", "")
Expand Down

0 comments on commit a9b114c

Please sign in to comment.