Skip to content

Commit dce81da

Browse files
Improve range handling (#18)
1 parent 3223f43 commit dce81da

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/UniqueFileGenerator.Console/Arguments/ArgumentTypes.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module ArgTypes =
1515
let private tryParseIntInRange (floor, ceiling) text =
1616
text
1717
|> parseInRange (floor, ceiling)
18-
|> Result.mapError (fun _ -> ParseNumberFailure (text, floor, ceiling))
18+
|> Result.mapError (fun _ -> ParseNumberFailure (text, (floor, ceiling)))
1919

2020
type FileCount = private FileCount of int with
2121
static member val AllowedRange = 1, Int32.MaxValue
@@ -24,9 +24,8 @@ module ArgTypes =
2424
text
2525
|> stripSeparators
2626
|> parseInRange FileCount.AllowedRange
27-
|> Result.mapError (fun _ ->
28-
ParseNumberFailure (text, fst FileCount.AllowedRange, snd FileCount.AllowedRange))
2927
|> Result.map FileCount
28+
|> Result.mapError (fun _ -> ParseNumberFailure (text, FileCount.AllowedRange))
3029

3130
member this.Value = let (FileCount count) = this in count
3231

src/UniqueFileGenerator.Console/Errors.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Errors =
99
| MalformedFlags
1010
| UnsupportedFlags
1111
| DuplicateFlags
12-
| ParseNumberFailure of Arg: string * Floor: int * Ceiling: int
12+
| ParseNumberFailure of Arg: string * AllowedRange: (int * int)
1313
| DirectoryMissing of string
1414
| DriveSpaceConfirmationFailure
1515
| DriveSpaceInsufficient of Needed: string * Actual: string
@@ -23,7 +23,7 @@ module Errors =
2323
| MalformedFlags -> "Malformed flag(s) found."
2424
| UnsupportedFlags -> "Unsupported flag(s) found."
2525
| DuplicateFlags -> "Duplicate option flag(s) found. Each can only be used once."
26-
| ParseNumberFailure (x, f, c) ->
26+
| ParseNumberFailure (x, (f, c)) ->
2727
$"Could not parse \"%s{x}\" to an integer between %s{formatInt f} and %s{formatInt c}, inclusive."
2828
| DirectoryMissing e -> $"Directory \"%s{e}\" was not found."
2929
| DriveSpaceConfirmationFailure -> "Could not confirm available drive space."

src/UniqueFileGenerator.Tests/ArgParserTests.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ let ``Appropriate error when invalid arg count (second pair incomplete)`` () =
6464
[<Fact>]
6565
let ``Appropriate error when invalid file count`` () =
6666
let args = [| "notNumeric" |]
67-
let expected = Error <| ParseNumberFailure(args[0], 1, Int32.MaxValue)
67+
let expected = Error (ParseNumberFailure(args[0], (1, Int32.MaxValue)))
6868
let actual = validate args
6969
Assert.Equal(expected, actual)
7070

7171
[<Fact>]
7272
let ``Appropriate error when negative file count`` () =
7373
let args = [| "-1" |]
74-
let expected = Error <| ParseNumberFailure(args[0], 1, Int32.MaxValue)
74+
let expected = Error (ParseNumberFailure(args[0], (1, Int32.MaxValue)))
7575
let actual = validate args
7676
Assert.Equal(expected, actual)
7777

7878
[<Fact>]
7979
let ``Appropriate error when zero file count`` () =
8080
let args = [| "0" |]
81-
let expected = Error <| ParseNumberFailure(args[0], 1, Int32.MaxValue)
81+
let expected = Error (ParseNumberFailure(args[0], (1, Int32.MaxValue)))
8282
let actual = validate args
8383
Assert.Equal(expected, actual)
8484

0 commit comments

Comments
 (0)