added a test case for File.relativePath() along with fixing a bug if you pass the same file as the argument; it should have returned the empty string
This commit is contained in:
@@ -73,7 +73,10 @@ public fun File.relativePath(descendant: File): String {
|
||||
val prefix = this.directory.canonicalPath
|
||||
val answer = descendant.canonicalPath
|
||||
return if (answer.startsWith(prefix)) {
|
||||
answer.substring(prefix.size + 1)
|
||||
val prefixSize = prefix.size
|
||||
if (answer.size > prefixSize) {
|
||||
answer.substring(prefixSize + 1)
|
||||
} else ""
|
||||
} else {
|
||||
answer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user