Add qualifiedTypeToSwift and reexport umbrella unit tests
This commit is contained in:
parent
7ce28c0ba8
commit
173ad4bd65
1 changed files with 64 additions and 0 deletions
|
|
@ -657,3 +657,67 @@ func testCrossNamespaceChildDoesNotForceOpen() throws {
|
|||
// Base has a child (Derived) but in a different namespace, so it stays final
|
||||
#expect(baseOutput.contains("final class Base"))
|
||||
}
|
||||
|
||||
@Test func qualifiedTypeQualifiesCrossNamespaceRef() {
|
||||
let nsMap = ["Gdk": "Gdk", "Gsk": "Gsk", "GObject": "GObject"]
|
||||
let rect = GIRType.typeRef("Rectangle", namespace: "Gdk")
|
||||
let result = CodeGenerator.qualifiedTypeToSwift(rect, currentModule: "Gtk", nsToModule: nsMap)
|
||||
#expect(result == "Gdk.Rectangle")
|
||||
}
|
||||
|
||||
@Test func qualifiedTypeKeepsBareNameForSameModule() {
|
||||
let nsMap = ["Gtk": "Gtk"]
|
||||
let widget = GIRType.typeRef("Widget", namespace: "Gtk")
|
||||
let result = CodeGenerator.qualifiedTypeToSwift(widget, currentModule: "Gtk", nsToModule: nsMap)
|
||||
#expect(result == "Widget")
|
||||
}
|
||||
|
||||
@Test func qualifiedTypeUnqualifiedRefStaysBare() {
|
||||
let nsMap = ["Gdk": "Gdk"]
|
||||
let widget = GIRType.typeRef("Widget", namespace: nil)
|
||||
let result = CodeGenerator.qualifiedTypeToSwift(widget, currentModule: "Gtk", nsToModule: nsMap)
|
||||
#expect(result == "Widget")
|
||||
}
|
||||
|
||||
@Test func qualifiedTypeNestsWithOptional() {
|
||||
let nsMap = ["Gdk": "Gdk"]
|
||||
let optRect = GIRType.optional(.typeRef("Rectangle", namespace: "Gdk"))
|
||||
let result = CodeGenerator.qualifiedTypeToSwift(optRect, currentModule: "Gtk", nsToModule: nsMap)
|
||||
#expect(result == "Gdk.Rectangle?")
|
||||
}
|
||||
|
||||
@Test func generateReexportUmbrellasExportsTransitiveDeps() {
|
||||
var repos: [String: Repository] = [:]
|
||||
repos["GLib"] = Repository()
|
||||
repos["GObject"] = Repository()
|
||||
repos["Gtk"] = Repository()
|
||||
let analysis = MultiPackageAnalysis(
|
||||
repositories: repos,
|
||||
directDependencies: [
|
||||
"GLib": [],
|
||||
"GObject": ["GLib"],
|
||||
"Gtk": ["GObject"],
|
||||
],
|
||||
transitiveDependencies: [
|
||||
"GLib": [],
|
||||
"GObject": ["GLib"],
|
||||
"Gtk": ["GLib", "GObject"],
|
||||
],
|
||||
implicitImports: ["GLib": [], "GObject": [], "Gtk": []],
|
||||
packageConfigs: [:]
|
||||
)
|
||||
|
||||
let umbrellas = CodeGenerator.generateReexportUmbrellas(analysis: analysis)
|
||||
|
||||
let glibUmbrella = umbrellas["Sources/GLib/GLib.swift"]
|
||||
#expect(glibUmbrella != nil)
|
||||
#expect(!(glibUmbrella?.contains("@_exported import") ?? false),
|
||||
"GLib is root, no re-exports expected")
|
||||
|
||||
let gobjUmbrella = umbrellas["Sources/GObject/GObject.swift"]
|
||||
#expect(gobjUmbrella?.contains("@_exported import GLib") == true)
|
||||
|
||||
let gtkUmbrella = umbrellas["Sources/Gtk/Gtk.swift"]
|
||||
#expect(gtkUmbrella?.contains("@_exported import GObject") == true)
|
||||
#expect(gtkUmbrella?.contains("@_exported import GLib") == true)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue