// // FileOpenTests.swift // FileOtterTests // // Created by Sami Samhuri on 2025-08-19. // @testable import FileOtter import XCTest final class FileOpenTests: XCTestCase { var tempDir: URL! var testFile: URL! override func setUpWithError() throws { tempDir = URL.temporaryDirectory .appendingPathComponent("FileOpenTests-\(UUID().uuidString)") try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) testFile = tempDir.appendingPathComponent("test.txt") try "Initial content\nSecond line\n".write(to: testFile, atomically: true, encoding: .utf8) } override func tearDownWithError() throws { if FileManager.default.fileExists(atPath: tempDir.path) { try FileManager.default.removeItem(at: tempDir) } } // MARK: - Open Mode Tests func testOpenReadMode() throws { // TODO: Implement // File(url, mode: .read) opens for reading only } func testOpenWriteMode() throws { // TODO: Implement // File(url, mode: .write) truncates and opens for writing } func testOpenAppendMode() throws { // TODO: Implement // File(url, mode: .append) opens for appending } func testOpenReadWriteMode() throws { // TODO: Implement // File(url, mode: .readWrite) opens for read and write } func testOpenReadWriteNewMode() throws { // TODO: Implement // File(url, mode: .readWriteNew) truncates and opens for read/write } func testOpenReadAppendMode() throws { // TODO: Implement // File(url, mode: .readAppend) opens for read and append } func testOpenWriteExclusiveMode() throws { // TODO: Implement // File(url, mode: .writeExclusive) creates new file, fails if exists } // MARK: - Open Method Tests func testStaticOpen() throws { // TODO: Implement // File.open(url) returns File object } func testStaticOpenWithBlock() throws { // TODO: Implement // File.open(url) { file in ... } auto-closes file } func testStaticOpenWithBlockThrowingError() throws { // TODO: Implement // File.open with block closes file even on error } // MARK: - File Creation Tests func testOpenCreatesFileInWriteMode() throws { // TODO: Implement // Opening non-existent file in write mode creates it } func testOpenFailsInReadModeForNonExistent() throws { // TODO: Implement // Opening non-existent file in read mode throws error } func testOpenWithPermissions() throws { // TODO: Implement // File(url, mode: .write, permissions: 0o644) creates with permissions } // MARK: - Auto-close Tests func testDeinitClosesHandle() throws { // TODO: Implement // File handle is closed when File object is deallocated } func testExplicitClose() throws { // TODO: Implement // file.close() explicitly closes handle } func testDoubleCloseIsOK() throws { // TODO: Implement // Calling close() twice doesn't throw } // MARK: - Locking Tests func testFlockShared() throws { // TODO: Implement // file.flock(.shared) acquires shared lock } func testFlockExclusive() throws { // TODO: Implement // file.flock(.exclusive) acquires exclusive lock } func testFlockUnlock() throws { // TODO: Implement // file.flock(.unlock) releases lock } func testFlockNonBlocking() throws { // TODO: Implement // file.flock(.nonBlocking) returns immediately if can't lock } // MARK: - Description Tests func testDescription() throws { // TODO: Implement // file.description returns path } func testDebugDescription() throws { // TODO: Implement // file.debugDescription includes path and mode } }