-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscriminatedUnionsTests.fs
61 lines (51 loc) · 1.97 KB
/
DiscriminatedUnionsTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module ArguExamples.DiscriminatedUnionsTests
open Microsoft.VisualStudio.TestPlatform.Utilities
open System
open Xunit
open Argu
open Xunit.Abstractions
type ComplexOutputArguments =
| [<Unique>] StdOut
| [<Unique>] File of file:string
with
interface IArgParserTemplate with
member this.Usage =
match this with
| StdOut -> "Output as text to standard out."
| File _ -> "Output to the specified file."
and ComplexCliArguments =
| [<Unique>] Output of ComplexOutputArguments
with
interface IArgParserTemplate with
member this.Usage =
match this with
| Output _ -> "Specify where to send the output"
type PrimitiveCliArguments =
| [<Unique>] StdOut
| [<Unique>] File of file:string
with
interface IArgParserTemplate with
member this.Usage =
match this with
| StdOut -> "Primitively send output to stdout"
| File _ -> "Primitively send output to a file"
type ``Nested Enums only work with primitive types`` (output:ITestOutputHelper) =
[<Fact>]
let ``cannot parse output as complex type`` () =
let createParser () =
let parser = ArgumentParser.Create<ComplexCliArguments>()
ignore()
Assert.Throws<ArguException>(createParser)
[<Fact>]
let ``can parse output as primitive union type to stdout`` () =
let parser = ArgumentParser.Create<PrimitiveCliArguments>()
let results = parser.Parse [|"--stdout"|]
let actual = results.GetResult (<@ StdOut @>)
output.WriteLine("Parsed {0}", (sprintf "%A" actual))
Assert.Equal(StdOut, actual)
[<Fact>]
let ``can parse output as primitive union type file with path`` () =
let parser = ArgumentParser.Create<PrimitiveCliArguments>()
let results = parser.Parse [|"--file"; "foo.txt"|]
let filePath = results.GetResult (<@ File @>)
Assert.Equal(filePath, "foo.txt")