mirror of https://github.com/sbt/sbt.git
Merge pull request #1230 from dansanduleac/uri-tests
Fix URITests to work under Windows
This commit is contained in:
commit
e40372d241
|
|
@ -8,14 +8,23 @@ import java.net.URI
|
|||
|
||||
object URITests extends Properties("URI Tests")
|
||||
{
|
||||
// Need a platform-specific root, otherwise URI will not be absolute (e.g. if we use a "/a/b/c" path in Windows)
|
||||
// Note:
|
||||
// If I use "C:" instead of "/C:", then isAbsolute == true for the resulting URI, but resolve is broken:
|
||||
// e.g. scala> new URI("file", "c:/a/b'/has spaces", null).resolve("a") broken
|
||||
// res0: java.net.URI = a
|
||||
// scala> new URI("file", "/c:/a/b'/has spaces", null).resolve("a") working
|
||||
// res1: java.net.URI = file:/c:/a/b'/a
|
||||
val Root = if (xsbt.boot.Pre.isWindows) "/C:/" else "/"
|
||||
|
||||
val FileProtocol = "file"
|
||||
property("directoryURI adds trailing slash") = secure {
|
||||
val dirURI = directoryURI(new File("/a/b/c"))
|
||||
val directURI = filePathURI("/a/b/c/")
|
||||
val dirURI = directoryURI(new File(Root + "a/b/c"))
|
||||
val directURI = filePathURI(Root + "a/b/c/")
|
||||
dirURI == directURI
|
||||
}
|
||||
property("directoryURI preserves trailing slash") = secure {
|
||||
directoryURI(new File("/a/b/c/")) == filePathURI("/a/b/c/")
|
||||
directoryURI(new File(Root + "a/b/c/")) == filePathURI(Root + "a/b/c/")
|
||||
}
|
||||
|
||||
property("filePathURI encodes spaces") = secure {
|
||||
|
|
@ -33,18 +42,18 @@ object URITests extends Properties("URI Tests")
|
|||
}
|
||||
|
||||
property("filePathURI and File.toURI agree for absolute file") = secure {
|
||||
val s = "/a/b'/has spaces"
|
||||
val s = Root + "a/b'/has spaces"
|
||||
val viaPath = filePathURI(s)
|
||||
val viaFile = (new File(s)).toURI
|
||||
val viaFile = new File(s).toURI
|
||||
s"via path: $viaPath" |:
|
||||
s"via file: $viaFile" |:
|
||||
(viaPath == viaFile)
|
||||
}
|
||||
|
||||
property("filePathURI supports URIs") = secure {
|
||||
val s = "file:///is/a/uri/with%20spaces"
|
||||
val decoded = "/is/a/uri/with spaces"
|
||||
val encoded = "/is/a/uri/with%20spaces"
|
||||
val s = s"file://${Root}is/a/uri/with%20spaces"
|
||||
val decoded = Root + "is/a/uri/with spaces"
|
||||
val encoded = Root + "is/a/uri/with%20spaces"
|
||||
val fpURI = filePathURI(s)
|
||||
val directURI = new URI(s)
|
||||
s"filePathURI: $fpURI" |:
|
||||
|
|
|
|||
Loading…
Reference in New Issue