Implemented the "currentFolder" property for the FileService service in the Library target.
This commit is contained in:
parent
ecbec1f4c8
commit
6938b358e1
9
Sources/Library/Protocols/FileServicing.swift
Normal file
9
Sources/Library/Protocols/FileServicing.swift
Normal file
@ -0,0 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
protocol FileServicing {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
var currentFolder: URL { get async }
|
||||
|
||||
}
|
27
Sources/Library/Services/FileService.swift
Normal file
27
Sources/Library/Services/FileService.swift
Normal file
@ -0,0 +1,27 @@
|
||||
import Foundation
|
||||
|
||||
struct FileService: FileServicing {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let fileManager: FileManager
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
init(fileManager: FileManager = .default) {
|
||||
self.fileManager = fileManager
|
||||
}
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
var currentFolder: URL {
|
||||
get async {
|
||||
if #available(macOS 13.0, *) {
|
||||
.init(filePath: fileManager.currentDirectoryPath)
|
||||
} else {
|
||||
.init(fileURLWithPath: fileManager.currentDirectoryPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
22
Tests/Library/Services/FileServiceTests.swift
Normal file
22
Tests/Library/Services/FileServiceTests.swift
Normal file
@ -0,0 +1,22 @@
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct FileServiceTests {
|
||||
|
||||
// MARK: Properties tests
|
||||
|
||||
@Test("Test the file service provides a current folder URL")
|
||||
func currentFolder() async {
|
||||
// GIVEN
|
||||
let service = FileService()
|
||||
|
||||
// WHEN
|
||||
let url = await service.currentFolder
|
||||
|
||||
// THEN
|
||||
#expect(url.path() == "/private/tmp")
|
||||
#expect(url.isFileURL == true)
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user