Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import Foundationimport ParcelConfigimport Testing
struct CallbackConfigurationTests { @Test func callbacksDefaultToDisabled() throws { #expect(ParcelConfiguration.defaults.callbacks.commands.isEmpty) try ParcelConfiguration.defaults.callbacks.validate() }
@Test(arguments: CallbackEvent.allCases) func callbackArraysParse(event: CallbackEvent) throws { let source = "[callbacks]\n\(event.rawValue) = [\"/usr/bin/printf\", \"%s\", \"hello world\"]" let result = ConfigValidator.validate(try TOMLParser.parse(source)) #expect(result.diagnostics.isEmpty) #expect(result.configuration?.callbacks.commands[event] == ["/usr/bin/printf", "%s", "hello world"]) }
@Test func emptyArraysDisableAndOmittedEventsStayDisabled() throws { let result = ConfigValidator.validate(try TOMLParser.parse("[callbacks]\nexec-on-window-opened = []")) #expect(result.configuration?.callbacks.commands == [.windowOpened: []]) }
@Test(arguments: ["\"/bin/true\"", "[3]", "[\"relative\"]", "[\"\"]", "[\"/bin/true\", false]"]) func malformedArraysAreRejected(value: String) throws { let result = ConfigValidator.validate(try TOMLParser.parse("[callbacks]\nexec-on-window-opened = \(value)")) #expect(result.configuration == nil) #expect(result.diagnostics.contains { $0.severity == .error && $0.location.line == 2 }) }
@Test func limitsApplyToProgrammaticConfigurations() throws { for argv in [ Array(repeating: "/bin/true", count: 65), ["/bin/true", String(repeating: "a", count: 4097)], ["/bin/true"] + Array(repeating: String(repeating: "a", count: 4096), count: 4), ["/bin/true", "\0"], ] { #expect(throws: CallbackConfigurationError.invalidArguments(.windowOpened)) { try CallbackConfiguration(commands: [.windowOpened: argv]).validate() } } try CallbackConfiguration(commands: [.windowOpened: ["/bin/true", "", "quoted \"value\""]]).validate() }
@Test func schemaPublishesEveryCallbackAsAnArgumentArray() throws { let schema = try JSONDecoder().decode(Envelope.self, from: Data(ConfigJSONSchema.string.utf8)) let events = schema.properties.callbacks.properties #expect(Set(events.keys) == Set(CallbackEvent.allCases.map(\.rawValue))) for event in CallbackEvent.allCases { let property = try #require(events[event.rawValue]) #expect(property.type == "array") #expect(property.maxItems == 64) } }
private struct Envelope: Decodable { let properties: Properties struct Properties: Decodable { let callbacks: Callbacks } struct Callbacks: Decodable { let properties: [String: Command] } struct Command: Decodable { let type: String let maxItems: Int } }}