172 lines
6.2 KiB
Swift
172 lines
6.2 KiB
Swift
// CLICommandTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable import LyrebirdCLI
|
|
|
|
@Suite("CLICommand parsing")
|
|
struct CLICommandTests {
|
|
|
|
@Test func replSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "repl"]) == .repl)
|
|
}
|
|
|
|
@Test func noArgsParsesToInteractive() {
|
|
// `lyrebird` with no subcommand enters the LineNoise interactive shell.
|
|
#expect(CLICommand.parse(["lyrebird"]) == .interactive)
|
|
}
|
|
|
|
@Test func helpFlagParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "--help"]) == .help)
|
|
}
|
|
|
|
@Test func helpSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "help"]) == .help)
|
|
}
|
|
|
|
@Test func versionFlagParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "--version"]) == .version)
|
|
}
|
|
|
|
@Test func versionSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "version"]) == .version)
|
|
}
|
|
|
|
@Test func unknownSubcommandParsesToHelp() {
|
|
#expect(CLICommand.parse(["lyrebird", "unknowncommand"]) == .help)
|
|
}
|
|
|
|
@Test func emptyArgsParsesToInteractive() {
|
|
// Edge case: called with empty args array (should not crash).
|
|
#expect(CLICommand.parse([]) == .interactive)
|
|
}
|
|
|
|
// MARK: - new
|
|
|
|
@Test func newSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "new", "MySynth"]) == .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
|
|
}
|
|
|
|
@Test func newWithTemplateDemoParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "demo"])
|
|
== .new(name: "MySynth", template: .demo, lyrebirdPath: nil))
|
|
}
|
|
|
|
@Test func newWithTemplateUIDemoParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "ui-demo"])
|
|
== .new(name: "MySynth", template: .uiDemo, lyrebirdPath: nil))
|
|
}
|
|
|
|
@Test func newWithTemplateNRTParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "nrt"])
|
|
== .new(name: "MySynth", template: .nrt, lyrebirdPath: nil))
|
|
}
|
|
|
|
@Test func newWithUnknownTemplateFallsBackToBasic() {
|
|
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "bogus"])
|
|
== .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
|
|
}
|
|
|
|
@Test func newWithoutNameParsesToHelp() {
|
|
#expect(CLICommand.parse(["lyrebird", "new"]) == .help)
|
|
}
|
|
|
|
@Test func newWithEmptyNameParsesToHelp() {
|
|
#expect(CLICommand.parse(["lyrebird", "new", ""]) == .help)
|
|
}
|
|
|
|
@Test func newWithFlagInsteadOfNameParsesToHelp() {
|
|
// Flag token in name position — user omitted the project name.
|
|
#expect(CLICommand.parse(["lyrebird", "new", "--flag"]) == .help)
|
|
}
|
|
|
|
@Test func newWithLyrebirdPathParsed() {
|
|
#expect(CLICommand.parse([
|
|
"lyrebird", "new", "MyPiece",
|
|
"--lyrebird-path", "/Users/josh/Documents/LyrebirdII"
|
|
]) == .new(name: "MyPiece",
|
|
template: .basic,
|
|
lyrebirdPath: "/Users/josh/Documents/LyrebirdII"))
|
|
}
|
|
|
|
@Test func newWithTemplateAndLyrebirdPathParsed() {
|
|
#expect(CLICommand.parse([
|
|
"lyrebird", "new", "MyApp",
|
|
"--template", "macos-ui-xcode",
|
|
"--lyrebird-path", "/abs/path"
|
|
]) == .new(name: "MyApp",
|
|
template: .macosUIXcode,
|
|
lyrebirdPath: "/abs/path"))
|
|
}
|
|
|
|
@Test func newWithoutLyrebirdPathReportsNil() {
|
|
#expect(CLICommand.parse([
|
|
"lyrebird", "new", "MyPiece"
|
|
]) == .new(name: "MyPiece", template: .basic, lyrebirdPath: nil))
|
|
}
|
|
|
|
// MARK: - run
|
|
|
|
@Test func runSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "run"]) == .run(release: false))
|
|
}
|
|
|
|
@Test func runWithReleaseFlagParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "run", "--release"]) == .run(release: true))
|
|
}
|
|
|
|
// MARK: - export
|
|
|
|
@Test func exportSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "export", "MySynth"]) == .export(name: "MySynth", to: nil, overwrite: false))
|
|
}
|
|
|
|
@Test func exportWithToPathParsed() {
|
|
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--to", "/tmp/MySynth.swift"])
|
|
#expect(cmd == .export(name: "MySynth", to: "/tmp/MySynth.swift", overwrite: false))
|
|
}
|
|
|
|
@Test func exportWithOverwriteFlagParsed() {
|
|
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--overwrite"])
|
|
#expect(cmd == .export(name: "MySynth", to: nil, overwrite: true))
|
|
}
|
|
|
|
@Test func exportWithToAndOverwriteParsed() {
|
|
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--to", "/tmp/x.swift", "--overwrite"])
|
|
#expect(cmd == .export(name: "MySynth", to: "/tmp/x.swift", overwrite: true))
|
|
}
|
|
|
|
@Test func exportWithoutNameParsesToHelp() {
|
|
#expect(CLICommand.parse(["lyrebird", "export"]) == .help)
|
|
}
|
|
|
|
@Test func exportWithFlagInsteadOfNameParsesToHelp() {
|
|
// `lyrebird export --to foo.swift` — name slot is a flag, should fall back to help.
|
|
#expect(CLICommand.parse(["lyrebird", "export", "--to", "foo.swift"]) == .help)
|
|
}
|
|
|
|
@Test func exportToValueIsNotConsumedAsFlagWhenFlagToken() {
|
|
// `lyrebird export MySynth --to --overwrite` — "--overwrite" starts with "-",
|
|
// so --to has no valid path value and toPath must be nil (not "--overwrite").
|
|
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--to", "--overwrite"])
|
|
#expect(cmd == .export(name: "MySynth", to: nil, overwrite: true))
|
|
}
|
|
|
|
// MARK: - install-templates / uninstall-templates
|
|
|
|
@Test func installTemplatesSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "install-templates"]) == .installTemplates(force: false))
|
|
}
|
|
|
|
@Test func installTemplatesWithForceFlag() {
|
|
#expect(CLICommand.parse(["lyrebird", "install-templates", "--force"]) == .installTemplates(force: true))
|
|
}
|
|
|
|
@Test func uninstallTemplatesSubcommandParsed() {
|
|
#expect(CLICommand.parse(["lyrebird", "uninstall-templates"]) == .uninstallTemplates)
|
|
}
|
|
}
|