Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import Foundationimport ParcelConfigimport Testing
@testable import ParcelUI
@MainActorstruct MouseControlSettingsTests { @Test func everyFieldMatchesItsConfigKey() throws { let document = try TOMLDocument(parsing: "") let expectedKeys: [SettingsMouseField: String] = [ .enabled: "enabled", .swapModifiers: "swap-modifiers", .stackModifiers: "stack-modifiers", .moveModifiers: "move-modifiers", .resizeModifiers: "resize-modifiers", .edgeSnapping: "edge-snapping", .dropToRatio: "drop-to-ratio", .focusFollowsMouse: "focus-follows-mouse", .focusDelay: "focus-delay", .typingCooldown: "typing-cooldown", ] #expect(expectedKeys.count == SettingsMouseField.allCases.count) for field in SettingsMouseField.allCases { let key = try #require(expectedKeys[field]) #expect(field.rawValue == key) #expect(SettingsField.mouse(field).path(in: document) == ["mouse", key]) } }
@Test func mouseEditsPreserveCommentsAndOtherSettings() async throws { let directory = FileManager.default.temporaryDirectory.appendingPathComponent("mouse-settings-\(UUID())") try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false) let file = directory.appendingPathComponent("parcel.toml") let model = SettingsModel(store: ConfigStore(fileURL: file)) do { try Data("# Keep\n[mouse]\nfocus-follows-mouse = false # pointer\n[motion]\nsound = true\n".utf8).write( to: file) await model.start() try await model.setValue(.bool(true), for: .mouse(.focusFollowsMouse)) try await model.setValue(.float(0.7), for: .mouse(.focusDelay)) try await model.setValue(.float(2), for: .mouse(.typingCooldown)) try await model.setValue(.string("ctrl-cmd"), for: .mouse(.moveModifiers)) let saved = try String(contentsOf: file, encoding: .utf8) #expect(saved.hasPrefix("# Keep\n")) #expect(saved.contains("focus-follows-mouse = true # pointer")) #expect(saved.contains("\"focus-delay\" = 0.7")) #expect(saved.contains("\"typing-cooldown\" = 2.0")) #expect(saved.contains("\"move-modifiers\" = \"ctrl-cmd\"")) #expect(!saved.contains("_")) #expect(saved.contains("sound = true")) #expect(model.configuration.mouse.focusFollowsMouse) #expect(model.configuration.mouse.focusDelay == 0.7) #expect(model.configuration.mouse.moveModifiers == [.control, .command]) await #expect(throws: SettingsFailure.self) { try await model.setValue(.string("cmd"), for: .mouse(.resizeModifiers)) } #expect(try String(contentsOf: file, encoding: .utf8) == saved) } catch { await model.stop() try FileManager.default.removeItem(at: directory) throw error } await model.stop() try FileManager.default.removeItem(at: directory) }}