Skip to content

Commit

Permalink
Fsdk,Fsdk.Tests(ArgsParsing): error case
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Aug 23, 2023
1 parent 3d087c0 commit f10fe94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Fsdk.Tests/ArgsParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,19 @@ type ArgsParsing() =
Assert.That(Seq.item 0 postFlags, Is.EqualTo "--someLongPostFlag3")
Assert.That(Seq.item 1 postFlags, Is.EqualTo "-f4")
| _ -> Assert.Fail "res was not ArgsParsing.BothFlags subtype"

[<Test>]
member __.errors() =
let commandLine = "someProgramThatDoesNotMatchPredicate".Split(' ')

let res =
Misc.ParseArgs
commandLine
(fun arg ->
arg = "someProgramArgThatDoesNotMatchProgramUsedInCommandLine"
)

match res with
| Misc.ArgsParsed.ErrorDetectingProgram -> Assert.Pass()
| _ ->
Assert.Fail "res was not ArgsParsing.ErrorDetectingProgram subtype"
3 changes: 2 additions & 1 deletion Fsdk/Misc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module Misc =
#endif

type ArgsParsed =
| ErrorDetectingProgram
| NoArgsWhatsoever
| ArgWithoutFlags of string
| OnlyFlags of List<string>
Expand All @@ -109,7 +110,7 @@ module Misc =
(acc: ArgsParsed)
: ArgsParsed =
match theArgs with
| [] -> acc
| [] -> ErrorDetectingProgram
| head :: tail ->
if predicateToRecognizeProgram head then
acc
Expand Down

0 comments on commit f10fe94

Please sign in to comment.