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:
James Strachan
2012-10-09 08:36:51 +01:00
parent 4b5da9dc17
commit 6a59820de3
2 changed files with 21 additions and 8 deletions
+4 -1
View File
@@ -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
}