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:
@@ -35,7 +35,7 @@ struct FileServiceTests {
|
||||
// WHEN
|
||||
try await service.copyFile(from: source, to: destination)
|
||||
|
||||
// THENn
|
||||
// THEN
|
||||
#expect(spy.actions.count == 1)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
@@ -57,6 +57,37 @@ struct FileServiceTests {
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
@Test(arguments: zip([URL.someNewFile],
|
||||
[Data("some data goes here...".utf8)]))
|
||||
func createFile(with location: URL, and data: Data) async throws {
|
||||
// GIVEN
|
||||
let service = service(action: .createFile(location, data))
|
||||
|
||||
// WHEN
|
||||
try await service.createFile(at: location, with: data)
|
||||
|
||||
// THEN
|
||||
#expect(spy.actions.count == 1)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
|
||||
#expect(action == .fileCreated(location, data))
|
||||
}
|
||||
|
||||
@Test(arguments: [FileServiceError.itemAlreadyExists, .fileDataIsEmpty, .fileNotCreated])
|
||||
func createFile(throws error: FileServiceError) async throws {
|
||||
// GIVEN
|
||||
let service = service(action: .error(error))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await service.createFile(at: .someNewFile, with: .init())
|
||||
}
|
||||
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||
func createFolder(with location: URL) async throws {
|
||||
// GIVEN
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import ColibriLibrary
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
struct TemplateServiceTests {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let spy = TemplateServiceSpy()
|
||||
|
||||
// MARK: Functions tests
|
||||
|
||||
@Test(arguments: [String.content])
|
||||
func render(_ content: String) async throws {
|
||||
// GIVEN
|
||||
let service = TemplateServiceMock(action: .render(content), spy: spy)
|
||||
|
||||
// WHEN
|
||||
let result = try await service.render([:], on: .template)
|
||||
|
||||
// THEN
|
||||
#expect(result == content)
|
||||
|
||||
#expect(spy.actions.isEmpty == false)
|
||||
}
|
||||
|
||||
@Test(arguments: [TemplateServiceError.serviceNotInitialized, .resourcePathNotFound, .templateNotFound, .contentNotRendered])
|
||||
func render(throws error: TemplateServiceError) async throws {
|
||||
// GIVEN
|
||||
let service = TemplateServiceMock(action: .error(error), spy: spy)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await service.render([:], on: .template)
|
||||
}
|
||||
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
static let content = ""
|
||||
static let template = ""
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import ColibriLibrary
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
struct TerminalServiceTests {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let spy = TerminalServiceSpy()
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
@Test(arguments: [URL.someNewFile], [[], ["--example"], ["--example", "--more", "--etc"]])
|
||||
func run(with executableURL: URL, and arguments: [String]) async throws {
|
||||
// GIVEN
|
||||
let service = TerminalServiceMock(action: .run(executableURL, arguments), spy: spy)
|
||||
|
||||
// WHEN
|
||||
let result = try await service.run(executableURL, arguments: arguments)
|
||||
|
||||
// THEN
|
||||
#expect(result == .content)
|
||||
|
||||
#expect(spy.actions.isEmpty == false)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
|
||||
#expect(action == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [TerminalServiceError.unexpected, .captured("Some captured error"), .output("Some output error")])
|
||||
func run(throws error: TerminalServiceError) async throws {
|
||||
// GIVEN
|
||||
let service = TerminalServiceMock(action: .error(error), spy: spy)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await service.run(URL.someNewFile, arguments: [])
|
||||
}
|
||||
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
static let content = ""
|
||||
}
|
||||
Reference in New Issue
Block a user