Skip to content

Commit

Permalink
Fix bug that could cause nameExcludingExtension to be incorrect for l…
Browse files Browse the repository at this point in the history
…ong file names
  • Loading branch information
JohnSundell committed Jan 21, 2017
1 parent 1aa3bfc commit 9c5bfc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class FileSystem {
return name
}

let startIndex = name.index(name.startIndex, offsetBy: `extension`.characters.count + 1)
let startIndex = name.index(name.endIndex, offsetBy: -`extension`.characters.count - 1)
return name.replacingCharacters(in: startIndex..<name.endIndex, with: "")
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/FilesTests/FilesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ class FilesTests: XCTestCase {
XCTAssertNotNil(FileSystem().homeFolder)
}

func testNameExcludingExtensionWithLongFileName() {
performTest {
let file = try folder.createFile(named: "AVeryLongFileName.png")
XCTAssertEqual(file.nameExcludingExtension, "AVeryLongFileName")
}
}

func testUsingCustomFileManager() {
class FileManagerMock: FileManager {
var noFilesExist = false
Expand Down

0 comments on commit 9c5bfc8

Please sign in to comment.