Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import Foundationimport ParcelConfigimport Testing
@Suite struct HoverBarConfigurationTests { @Test func omittedValuesKeepDefaults() throws { let result = ConfigValidator.validate(try TOMLDocument(parsing: "")) #expect(result.configuration?.hoverBar == HoverBarConfiguration(enabled: true, delay: 0.6)) #expect(result.diagnostics.isEmpty) }
@Test(arguments: [0.1, 0.6, 3.0]) func delayAndEnabledParse(delay: Double) throws { let result = ConfigValidator.validate( try TOMLDocument(parsing: "[hover-bar]\nenabled = false\ndelay = \(delay)\n")) #expect(result.configuration?.hoverBar == HoverBarConfiguration(enabled: false, delay: delay)) #expect(result.diagnostics.isEmpty) }
@Test(arguments: ["0", "0.09", "3.01", "inf", "nan", "'slow'", "true"]) func invalidDelaysAreRejectedWithLocation(value: String) throws { let result = ConfigValidator.validate(try TOMLDocument(parsing: "[hover-bar]\ndelay = \(value)\n")) #expect(result.configuration == nil) let failure = try #require(result.diagnostics.first) #expect(failure.severity == .error) #expect(failure.location.line == 2) #expect(failure.message.contains("hover-bar.delay")) }
@Test func invalidEnabledAndUnknownKeysSurfaceDiagnostics() throws { let invalid = ConfigValidator.validate(try TOMLDocument(parsing: "[hover-bar]\nenabled = 'yes'\n")) #expect(invalid.configuration == nil) let unknown = ConfigValidator.validate(try TOMLDocument(parsing: "[hover-bar]\ndelai = 1\n")) #expect(unknown.configuration?.hoverBar.delay == 0.6) #expect(unknown.diagnostics.first?.severity == .warning) }
@Test func schemaPublishesMatchingDefaultsAndBounds() throws { let schema = try JSONDecoder().decode(Schema.self, from: Data(ConfigJSONSchema.string.utf8)) let hover = try #require(schema.properties["hover-bar"]) let enabled = try #require(hover.properties?["enabled"]) let delay = try #require(hover.properties?["delay"]) #expect(enabled.type == "boolean") #expect(enabled.defaultBool == true) #expect(delay.type == "number") #expect(delay.minimum == 0.1) #expect(delay.maximum == 3) #expect(delay.defaultNumber == 0.6) }
private struct Schema: Decodable { let properties: [String: Property] }
private struct Property: Decodable { let type: String? let properties: [String: Property]? let minimum: Double? let maximum: Double? let defaultBool: Bool? let defaultNumber: Double?
enum CodingKeys: String, CodingKey { case type, properties, minimum, maximum case defaultValue = "default" }
init(from decoder: any Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) type = try values.decodeIfPresent(String.self, forKey: .type) properties = try values.decodeIfPresent([String: Property].self, forKey: .properties) minimum = try values.decodeIfPresent(Double.self, forKey: .minimum) maximum = try values.decodeIfPresent(Double.self, forKey: .maximum) defaultBool = type == "boolean" ? try values.decodeIfPresent(Bool.self, forKey: .defaultValue) : nil defaultNumber = type == "number" ? try values.decodeIfPresent(Double.self, forKey: .defaultValue) : nil } }}