-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from jmkuhn/uri
Deprecate URIParser; use URIs
- Loading branch information
Showing
6 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using .URIs | ||
|
||
const absent = SubString("absent", 1, 0) | ||
|
||
function URIs.URI(p::AbstractPath; query=absent, fragment=absent) | ||
if isempty(p.root) | ||
throw(ArgumentError("$p is not an absolute path")) | ||
end | ||
|
||
b = IOBuffer() | ||
print(b, "file://") | ||
|
||
if !isempty(p.drive) | ||
print(b, "/") | ||
print(b, p.drive) | ||
end | ||
|
||
for s in p.segments | ||
print(b, "/") | ||
print(b, URIs.escapeuri(s)) | ||
end | ||
|
||
return URIs.URI(URIs.URI(String(take!(b))); query=query, fragment=fragment) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
using URIParser | ||
using URIs | ||
using FilePaths | ||
|
||
@testset "URI" begin | ||
@test string(URI(p"/foo/bar")) == "file:///foo/bar" | ||
@test string(URI(p"/foo foo/bar")) == "file:///foo%20foo/bar" | ||
@test_throws ArgumentError URI(p"foo/bar") | ||
@test string(URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar" | ||
@test string(URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart" | ||
@testset "URIParser" begin | ||
@test string(URIParser.URI(p"/foo/bar")) == "file:///foo/bar" | ||
@test string(URIParser.URI(p"/foo foo/bar")) == "file:///foo%20foo/bar" | ||
@test_throws ArgumentError URIParser.URI(p"foo/bar") | ||
@test string(URIParser.URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar" | ||
@test string(URIParser.URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart" | ||
end | ||
|
||
@testset "URIs" begin | ||
@test string(URIs.URI(p"/foo/bar")) == "file:///foo/bar" | ||
@test string(URIs.URI(p"/foo foo/bar")) == "file:///foo%20foo/bar" | ||
@test_throws ArgumentError URIs.URI(p"foo/bar") | ||
@test string(URIs.URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar" | ||
@test string(URIs.URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart" | ||
end |