Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788import Foundationimport ParcelConfigimport Testing
@Suitestruct MemoryConfigurationTests { @Test func defaultsRememberSettingsAndPlacements() throws { let result = ConfigValidator.validate(try TOMLDocument(parsing: "version = 1")) #expect(result.diagnostics.isEmpty) #expect(result.configuration?.memory == MemoryConfiguration(enabled: true, restoreWindows: true)) }
@Test(arguments: [true, false]) func switchesValidateIndependently(enabled: Bool) throws { let source = "[memory]\nenabled = \(enabled)\nrestore-windows = \(!enabled)\n" let result = ConfigValidator.validate(try TOMLDocument(parsing: source)) #expect(result.diagnostics.isEmpty) #expect(result.configuration?.memory == MemoryConfiguration(enabled: enabled, restoreWindows: !enabled)) }
@Test(arguments: ["enabled", "restore-windows"]) func nonBooleanValuesHaveLocatedErrors(key: String) throws { let result = ConfigValidator.validate(try TOMLDocument(parsing: "[memory]\n\(key) = 1\n")) #expect(result.configuration == nil) let diagnostic = try #require(result.diagnostics.first) #expect(diagnostic.location.line == 2) #expect(diagnostic.message.contains("memory.\(key)")) }
@Test func unknownMemoryKeyIsVisible() throws { let result = ConfigValidator.validate(try TOMLDocument(parsing: "[memory]\nrestore-window = false\n")) #expect(result.configuration == .defaults) #expect(result.diagnostics.count == 1) let diagnostic = try #require(result.diagnostics.first) #expect(diagnostic.severity == .warning) #expect(diagnostic.location.line == 2) #expect(diagnostic.location.column == 1) #expect(diagnostic.message.contains("Unknown key “memory.restore-window”")) #expect(diagnostic.message.contains("Did you mean “memory.restore-windows”")) }
@Test(arguments: ["false", "'false'", "[]"]) func underscoreSpellingIsUnknownAndDoesNotChangeRestoration(value: String) throws { let source = "[general]\nprefix = 'fn'\n[memory]\nenabled = false\n" let baseline = ConfigValidator.validate(try TOMLDocument(parsing: source)) #expect(baseline.diagnostics.isEmpty) let expected = try #require(baseline.configuration) let document = try TOMLDocument(parsing: source + " restore_windows = \(value)\n") let result = ConfigValidator.validate(document) let diagnostic = try #require(result.diagnostics.first) #expect(result.diagnostics.count == 1) #expect(diagnostic.severity == .warning) #expect(diagnostic.location == document.root["memory"]?["restore_windows"]?.keyRange?.start) #expect(diagnostic.location.line == 5) #expect(diagnostic.location.column == 3) #expect(diagnostic.message.contains("Unknown key “memory.restore_windows”")) #expect(diagnostic.message.contains("Did you mean “memory.restore-windows”")) #expect(try #require(result.configuration) == expected) #expect(result.configuration?.memory == MemoryConfiguration(enabled: false, restoreWindows: true)) #expect(result.configuration?.general.prefix == .fn) }
@Test func schemaMatchesMemoryDefaults() throws { let schema = try JSONSerialization.jsonObject(with: Data(ConfigJSONSchema.string.utf8)) let root = try #require(schema as? [String: Any]) let properties = try #require(root["properties"] as? [String: Any]) let memory = try #require(properties["memory"] as? [String: Any]) let fields = try #require(memory["properties"] as? [String: Any]) #expect(Set(fields.keys) == ["enabled", "restore-windows"]) for field in fields.values { let value = try #require(field as? [String: Any]) #expect(value["type"] as? String == "boolean") #expect(value["default"] as? Bool == true) } }
@Test func undoIsBoundConfigurableAndRemovable() throws { let inherited = try #require(DefaultKeybindings.bindings()[.undo]) #expect(inherited.key == .u) let rebound = ConfigValidator.validate(try TOMLDocument(parsing: "[keybindings]\nundo = 'cmd-f20'")) #expect(rebound.diagnostics.isEmpty) #expect(rebound.configuration?.keybindings[.undo] == KeyChord(modifiers: .cmd, key: .f20)) let removed = ConfigValidator.validate(try TOMLDocument(parsing: "[keybindings]\nundo = false")) #expect(removed.diagnostics.isEmpty) #expect(removed.configuration?.keybindings[.undo] == nil) }}