Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Argu/PreCompute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ let primitiveParsers = lazy(
mkParser "char" Char.Parse string
mkParser "string" id id

mkParser "float" Single.Parse string
mkParser "double" Double.Parse string
mkParser "decimal" Decimal.Parse string
mkParser "float" float32 string
mkParser "double" float string
mkParser "decimal" decimal string
mkParser "bigint" System.Numerics.BigInteger.Parse string
mkParser "guid" Guid string
mkParser "base64" Convert.FromBase64String Convert.ToBase64String
Expand Down
23 changes: 23 additions & 0 deletions tests/Argu.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

open System
open System.IO
open System.Globalization
open Xunit
open Swensen.Unquote

Expand Down Expand Up @@ -72,6 +73,9 @@ module ``Argu Tests Main List`` =
| [<MainCommand; Last; Unique>] Main of chars:char list
| [<Inherit>] Data of int * byte []
| Log_Level of int
| Float32_Arg of float32
| Float64_Arg of float
| Decimal_Arg of decimal
| [<AltCommandLine("/D", "-D", "-z")>] Detach
| [<CustomAppSettings "Foo">] CustomAppConfig of string * int
| [<ColonAssignment>] Assignment of string
Expand Down Expand Up @@ -110,6 +114,9 @@ module ``Argu Tests Main List`` =
| Flex_Equals_Assignment_With_Option _ -> "Flex_Equals_Assignment but with optional parameter type"
| Flex_Colon_Assignment _ -> "A colon assignment which can also be used with a space separator"
| Log_Level _ -> "set the log level."
| Float32_Arg _ -> "Some float32"
| Float64_Arg _ -> "Some float64"
| Decimal_Arg _ -> "Some decimal"
| Detach _ -> "detach daemon from console."
| Assignment _ -> "assign with colon operation."
| Enum _ -> "assign from three possible values."
Expand All @@ -131,6 +138,22 @@ module ``Argu Tests Main List`` =
let parser = ArgumentParser.Create<Argument> (programName = "gadget")
let parseFunc ignoreMissing f = parser.ParseConfiguration(ConfigurationReader.FromFunction f, ignoreMissing)

[<Fact>]
let ``Numberic decimal separators parsing is culture invariant``() =
CultureInfo.CurrentUICulture <- CultureInfo.CurrentUICulture.Clone() :?> CultureInfo
CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator <- ","

let args =
[| "--float32-arg"; "1.2"
"--float64-arg"; "2.3"
"--decimal-arg"; "3.4"
"--mandatory-arg"; "true" |]

let expected = [ Float32_Arg 1.2f; Float64_Arg 2.3; Decimal_Arg 3.4m; Mandatory_Arg true ]
let results = parser.ParseCommandLine args

test <@ results.GetAllResults() = expected @>

[<Fact>]
let ``Simple command line parsing`` () =
let args =
Expand Down