Add MonorepoConfig TOML parsing tests
This commit is contained in:
parent
58aef1a5d4
commit
f61a63f167
1 changed files with 88 additions and 0 deletions
88
Tests/SwiftGtkGenCoreTests/MonorepoConfigTests.swift
Normal file
88
Tests/SwiftGtkGenCoreTests/MonorepoConfigTests.swift
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
|
||||
@Suite("MonorepoConfig")
|
||||
struct MonorepoConfigTests {
|
||||
|
||||
@Test func parsesValidMonorepoConfig() throws {
|
||||
let toml = """
|
||||
output_dir = "."
|
||||
packages = [{ name = "Gtk", gir = "/usr/share/gir-1.0/Gtk-4.0.gir" },{ name = "Gdk", gir = "/usr/share/gir-1.0/Gdk-4.0.gir", concurrency = "mainActor" },{ name = "GObject", gir = "/usr/share/gir-1.0/GObject-2.0.gir" }]
|
||||
"""
|
||||
|
||||
let dict = try TOMLReader.parse(toml)
|
||||
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
||||
|
||||
#expect(config.outputDir == ".")
|
||||
#expect(config.packages.count == 3)
|
||||
#expect(config.packages[0].name == "Gtk")
|
||||
#expect(config.packages[0].girPath == "/usr/share/gir-1.0/Gtk-4.0.gir")
|
||||
#expect(config.packages[0].concurrency == nil)
|
||||
#expect(config.packages[1].name == "Gdk")
|
||||
#expect(config.packages[1].concurrency == .mainActor)
|
||||
#expect(config.packages[2].name == "GObject")
|
||||
#expect(config.packages[2].concurrency == nil)
|
||||
}
|
||||
|
||||
@Test func parsesPackagesWithObjectOverrides() throws {
|
||||
let dict: [String: Any] = [
|
||||
"output_dir": "Sources",
|
||||
"packages": [
|
||||
[
|
||||
"name": "Gtk",
|
||||
"gir": "/usr/share/gir-1.0/Gtk-4.0.gir",
|
||||
"object": [
|
||||
"Gtk.Widget": ["status": "generate", "concurrency": "mainActor"],
|
||||
"Gtk.Legacy": ["status": "ignore"],
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
|
||||
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
||||
|
||||
#expect(config.packages.count == 1)
|
||||
#expect(config.packages[0].objects.count == 2)
|
||||
|
||||
if case .object(let name, let overrides) = config.packages[0].objects[0] {
|
||||
#expect(name == "Gtk.Legacy")
|
||||
#expect(overrides.status == .ignore)
|
||||
} else {
|
||||
Issue.record("Expected .object config for first entry")
|
||||
}
|
||||
|
||||
if case .object(let name, let overrides) = config.packages[0].objects[1] {
|
||||
#expect(name == "Gtk.Widget")
|
||||
#expect(overrides.concurrency == .mainActor)
|
||||
} else {
|
||||
Issue.record("Expected .object config for second entry")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func rejectsMissingName() {
|
||||
let dict: [String: Any] = [
|
||||
"packages": [
|
||||
["gir": "/usr/share/gir-1.0/Gtk-4.0.gir"],
|
||||
],
|
||||
]
|
||||
do {
|
||||
_ = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
||||
Issue.record("Expected error for missing name")
|
||||
} catch {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test func usesDefaultOutputDirWhenNotSpecified() throws {
|
||||
let dict: [String: Any] = [
|
||||
"packages": [
|
||||
["name": "Gtk", "gir": "/usr/share/gir-1.0/Gtk-4.0.gir"],
|
||||
],
|
||||
]
|
||||
|
||||
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: "/custom/output")
|
||||
|
||||
#expect(config.outputDir == "/custom/output")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue