Extracted from gtk-swift monorepo. Previous history contains 38 commits across the full Phase 1 development including GIR XML parsing, IR model, analysis engine, code generation, CLI, plugins, and documentation.
86 lines
3.3 KiB
Swift
86 lines
3.3 KiB
Swift
import Testing
|
|
import SwiftGtkGenCore
|
|
|
|
@Test("Namespace can hold types")
|
|
func testNamespaceHoldsTypes() {
|
|
let ns = Namespace(name: "Gtk", version: "4.0")
|
|
#expect(ns.name == "Gtk")
|
|
#expect(ns.version == "4.0")
|
|
#expect(ns.classes.isEmpty)
|
|
#expect(ns.interfaces.isEmpty)
|
|
#expect(ns.enumerations.isEmpty)
|
|
#expect(ns.records.isEmpty)
|
|
}
|
|
|
|
@Test("Class has properties and methods")
|
|
func testClassHasProperties() {
|
|
let cls = Class(name: "Widget", cType: "GtkWidget", parent: nil, isAbstract: false)
|
|
#expect(cls.name == "Widget")
|
|
#expect(cls.properties.isEmpty)
|
|
#expect(cls.methods.isEmpty)
|
|
#expect(cls.signals.isEmpty)
|
|
}
|
|
|
|
@Test("Method stores parameters and return type")
|
|
func testMethodStoresParameters() {
|
|
let param = Parameter(name: "label", type: .string, isNullable: false, transferOwnership: .none)
|
|
let method = Method(name: "set_label", cIdentifier: "gtk_label_set_text", parameters: [param], returnType: .void)
|
|
#expect(method.name == "set_label")
|
|
#expect(method.parameters.count == 1)
|
|
#expect(method.returnType == .void)
|
|
}
|
|
|
|
@Test("Enumeration stores members")
|
|
func testEnumerationStoresMembers() {
|
|
let member = EnumMember(name: "GTK_ALIGN_FILL", value: "1", cIdentifier: "GTK_ALIGN_FILL")
|
|
let enumeration = Enumeration(name: "GtkAlign", cType: "GtkAlign", members: [member])
|
|
#expect(enumeration.name == "GtkAlign")
|
|
#expect(enumeration.members.count == 1)
|
|
#expect(enumeration.members[0].value == "1")
|
|
}
|
|
|
|
@Test("Signal stores parameters and return type")
|
|
func testSignalStoresParameters() {
|
|
let signal = Signal(name: "clicked", parameters: [], returnType: .void, isDetailed: false)
|
|
#expect(signal.name == "clicked")
|
|
#expect(signal.returnType == .void)
|
|
#expect(signal.isDetailed == false)
|
|
}
|
|
|
|
@Test("Property stores type and flags")
|
|
func testPropertyStoresTypeAndFlags() {
|
|
let prop = Property(name: "label", type: .string, isReadable: true, isWritable: true, isConstructOnly: false)
|
|
#expect(prop.name == "label")
|
|
#expect(prop.type == .string)
|
|
#expect(prop.isReadable == true)
|
|
#expect(prop.isWritable == true)
|
|
}
|
|
|
|
@Test("Repository holds multiple namespaces")
|
|
func testRepositoryHoldsMultipleNamespaces() {
|
|
let gtk = Namespace(name: "Gtk", version: "4.0")
|
|
let gdk = Namespace(name: "Gdk", version: "4.0")
|
|
let repo = Repository(namespaces: [gtk, gdk])
|
|
#expect(repo.namespaces.count == 2)
|
|
#expect(repo.namespaces[0].name == "Gtk")
|
|
#expect(repo.namespaces[1].name == "Gdk")
|
|
}
|
|
|
|
@Test("GIRType equality works")
|
|
func testGIRTypeEquality() {
|
|
#expect(GIRType.void == GIRType.void)
|
|
#expect(GIRType.string == GIRType.string)
|
|
#expect(GIRType.typeRef("GtkWidget") == GIRType.typeRef("GtkWidget"))
|
|
#expect(GIRType.typeRef("GtkWidget") != GIRType.typeRef("GtkLabel"))
|
|
#expect(GIRType.array(.string) == GIRType.array(.string))
|
|
#expect(GIRType.array(.string) != GIRType.array(.int32))
|
|
#expect(GIRType.optional(.string) == GIRType.optional(.string))
|
|
#expect(GIRType.optional(.string) != GIRType.string)
|
|
}
|
|
|
|
@Test("Interface stores methods, properties, signals, and prereqs")
|
|
func testInterfaceStoresMembers() {
|
|
let iface = Interface(name: "GtkBuildable", cType: "GtkBuildable", prereqs: ["GtkWidget"])
|
|
#expect(iface.name == "GtkBuildable")
|
|
#expect(iface.prereqs.count == 1)
|
|
}
|