import Testing @testable import GObjectGeneratorCore @Test("TOML reader parses simple key-value pairs") func testSimpleKeyValue() throws { let input = """ library = "Gtk" version = "4.0" output_dir = "Sources/Gtk" """ let result = try TOMLReader.parse(input) #expect(result["library"] as? String == "Gtk") #expect(result["version"] as? String == "4.0") #expect(result["output_dir"] as? String == "Sources/Gtk") } @Test("TOML reader parses integer and boolean values") func testIntAndBool() throws { let input = """ count = 42 enabled = true disabled = false """ let result = try TOMLReader.parse(input) #expect(result["count"] as? Int == 42) #expect(result["enabled"] as? Bool == true) #expect(result["disabled"] as? Bool == false) } @Test("TOML reader parses array values") func testArrays() throws { let input = """ girs_directories = ["/usr/share/gir-1.0", "/vendor"] generate = ["Gtk.Widget", "Gtk.Window"] """ let result = try TOMLReader.parse(input) let dirs = result["girs_directories"] as? [String] #expect(dirs?.count == 2) #expect(dirs?[0] == "/usr/share/gir-1.0") let gen = result["generate"] as? [String] #expect(gen?.count == 2) #expect(gen?.contains("Gtk.Widget") == true) } @Test("TOML reader parses nested tables [section]") func testNestedTables() throws { let input = """ [object."Gtk.Widget"] final_type = false concurrency = "mainActor" [object."Gtk.Window"] final_type = true """ let result = try TOMLReader.parse(input) guard let objects = result["object"] as? [String: [String: Any]] else { Issue.record("Expected nested table dict") return } #expect(objects.keys.contains("Gtk.Widget")) guard let widget = objects["Gtk.Widget"] else { return } #expect(widget["final_type"] as? Bool == false) #expect(widget["concurrency"] as? String == "mainActor") } @Test("TOML reader parses quoted keys and dotted keys") func testQuotedKeys() throws { let input = """ [object] "Gtk.Widget".final_type = false "Gtk.Button".concurrency = "mainActor" """ let result = try TOMLReader.parse(input) let objects = result["object"] as? [String: [String: Any]] let widget = objects?["Gtk.Widget"] #expect(widget?["final_type"] as? Bool == false) let button = objects?["Gtk.Button"] #expect(button?["concurrency"] as? String == "mainActor") } @Test("TOML reader handles comments and blank lines") func testComments() throws { let input = """ # This is a comment library = "Gtk" # inline comment # more comments version = "4.0" """ let result = try TOMLReader.parse(input) #expect(result["library"] as? String == "Gtk") #expect(result["version"] as? String == "4.0") } @Test("TOML reader handles inline tables") func testInlineTables() throws { let input = """ [function."Gtk.Widget"."show"] ignore = true rename = { regex = "^gtk_", replacement = "" } constructor = true """ let result = try TOMLReader.parse(input) guard let funcs = result["function"] as? [String: [String: [String: Any]]] else { Issue.record("Expected nested function dict") return } guard let show = funcs["Gtk.Widget"]?["show"] else { return } #expect(show["ignore"] as? Bool == true) #expect(show["constructor"] as? Bool == true) if let rename = show["rename"] as? [String: String] { #expect(rename["regex"] == "^gtk_") #expect(rename["replacement"] == "") } } @Test("TOML reader rejects invalid input") func testInvalidInput() { let input = "= invalid" #expect(throws: TOMLReaderError.self) { try TOMLReader.parse(input) } } @Test("TOML reader rejects unclosed string") func testUnclosedString() { let input = "key = \"start" #expect(throws: TOMLReaderError.self) { try TOMLReader.parse(input) } }