Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Add collectErrors tests for CommandParams
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonm23 committed Aug 31, 2023
1 parent 01e2cbc commit ef97905
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions cutbox_command/Tests/CutBoxCLITests/CommandParamsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,36 @@ class CommandParamsSpec: QuickSpec {
}

it("should return nil if option is not present") {
subject.arguments = ["programName", "-otherOpt", "value"]
subject.arguments = ["--otherOpt", "value"]

let result: String? = subject.hasOpt("-opt")
let result: String? = subject.hasOpt("--opt")
expect(result).to(beNil())
}

it("should return nil if option value starts with '-'") {
subject.arguments = ["programName", "-opt", "-invalidValue"]
it("should return nil if option value starts with '--'") {
subject.arguments = ["--opt", "--invalidValue"]

let result: String? = subject.hasOpt("-opt")
let result: String? = subject.hasOpt("--opt")
expect(result).to(beNil())
}
}

context("after parsing, arguments left over are errors") {
describe("collectErrors") {
it("collects remaining arguments") {
let arguments = ["-o0", "value1",
"-o1", "value2",
"--opt2",
"--opt3", "value2"]
subject.collectErrors(arguments)

expect(subject.errors.count) == 4
expect(subject.errors[0]) == ("-o0", "value1")
expect(subject.errors[1]) == ("-o1", "value2")
expect(subject.errors[2]) == ("--opt3", "")
expect(subject.errors[3]) == ("--opt4", "value2")
}
}
}
}
}

0 comments on commit ef97905

Please sign in to comment.