Template support for input parameters (#4)

This PR contains the work done to support input parameters for the `create` command of the executable target, and to render content dynamically for the newly-generated project.

Reviewed-on: #4
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #4.
This commit is contained in:
2025-02-17 22:11:05 +00:00
committed by Javier Cicchelli
parent 9be8fa4a31
commit 212ca52279
33 changed files with 812 additions and 202 deletions
@@ -0,0 +1,30 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct InitGitInFolderTaskTests {
// MARK: Functions tests
@Test(arguments: [URL.someCurrentFolder, .someNewFolder, .someDotFolder, .someTildeFolder])
func task(at rootFolder: URL) async throws {
// GIVEN
let terminalService = TerminalServiceSpy()
let initGitInFolder = InitGitInFolderTask(terminalService: terminalService)
// WHEN
try await initGitInFolder(at: rootFolder)
// THEN
let executableURL = URL(at: "/usr/bin/git")
let pathFolder = rootFolder.pathString
#expect(terminalService.actions.count == 3)
#expect(terminalService.actions[0] == .ran(executableURL, ["init", pathFolder]))
#expect(terminalService.actions[1] == .ran(executableURL, ["-C", pathFolder, "add", "."]))
#expect(terminalService.actions[2] == .ran(executableURL, ["-C", pathFolder, "commit", "-m", "Initial commit"]))
}
}
@@ -0,0 +1,41 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct RenderFilesTaskTests {
@Test(arguments: [URL.someCurrentFolder], [Project(name: "Some name goes here...")])
func task(at rootFolder: URL, with project: Project) async throws {
// GIVEN
let fileService = FileServiceSpy()
let templateService = TemplateServiceSpy()
let renderFiles = RenderFilesTask(fileService: fileService,
templateService: templateService)
// WHEN
try await renderFiles(at: rootFolder, with: project)
// THEN
let fileData = Data()
let templates = Template.allCases
#expect(fileService.actions.count == 3)
#expect(templateService.actions.count == 3)
fileService.actions.enumerated().forEach { index, action in
#expect(action == .fileCreated(rootFolder.appendingPath(templates[index].filePath), fileData))
}
templateService.actions.enumerated().forEach { index, action in
if case let .rendered(object, template) = action {
#expect(object as? Project == project)
#expect(template == templates[index].rawValue)
} else {
Issue.record("Action should have been a case of the `TemplateServiceSpy.Action` enumeration.")
}
}
}
}