BadScript 2
Loading...
Searching...
No Matches
SequenceParsingTests.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using System;
4using Xunit;
7using FluentAssertions;
9using System.Reflection;
10using CSharpx;
12
14{
15 // Reference: PR #684
17 {
18 // Issue #91
19 [Theory]
20 [InlineData(false)]
21 [InlineData(true)]
23 {
24 var args = "--exclude=a,b InputFile.txt".Split();
25 var expected = new Options_For_Issue_91 {
26 Excluded = new[] { "a", "b" },
27 Included = Enumerable.Empty<string>(),
28 InputFileName = "InputFile.txt",
29 };
30 var sut = new Parser(parserSettings => { parserSettings.GetoptMode = useGetoptMode; });
31 var result = sut.ParseArguments<Options_For_Issue_91>(args);
32 result.Should().BeOfType<Parsed<Options_For_Issue_91>>();
33 result.As<Parsed<Options_For_Issue_91>>().Value.Should().BeEquivalentTo(expected);
34 }
35
36 // Issue #396
37 [Theory]
38 [InlineData(false)]
39 [InlineData(true)]
40 public static void Options_with_similar_names_are_not_ambiguous(bool useGetoptMode)
41 {
42 var args = new[] { "--configure-profile", "deploy", "--profile", "local" };
43 var expected = new Options_With_Similar_Names { ConfigureProfile = "deploy", Profile = "local", Deploys = Enumerable.Empty<string>() };
44 var sut = new Parser(parserSettings => { parserSettings.GetoptMode = useGetoptMode; });
45 var result = sut.ParseArguments<Options_With_Similar_Names>(args);
46 result.Should().BeOfType<Parsed<Options_With_Similar_Names>>();
47 result.As<Parsed<Options_With_Similar_Names>>().Value.Should().BeEquivalentTo(expected);
48 }
49
50 // Issue #420
51 [Fact]
52
54 {
55 var args = new[] { "c", "x,y" };
56 var tokensExpected = new[] { Token.Value("c"), Token.Value("x,y") };
57 var typeInfo = typeof(Options_With_Similar_Names_And_Separator);
58
59 var specProps = typeInfo.GetSpecifications(pi => SpecificationProperty.Create(
60 Specification.FromProperty(pi), pi, Maybe.Nothing<object>()))
61 .Select(sp => sp.Specification)
62 .OfType<OptionSpecification>();
63
64 var tokenizerResult = Tokenizer.ConfigureTokenizer(StringComparer.InvariantCulture, false, false)(args, specProps);
65 var tokens = tokenizerResult.SucceededWith();
66 tokens.Should().BeEquivalentTo(tokensExpected);
67 }
68
69 // Issue #454
70 [Theory]
71 [InlineData(false)]
72 [InlineData(true)]
73
75 {
76 var args = "-c chanA:chanB file.hdf5".Split();
77 var expected = new Options_For_Issue_454 {
78 Channels = new[] { "chanA", "chanB" },
79 ArchivePath = "file.hdf5",
80 };
81 var sut = new Parser(parserSettings => { parserSettings.GetoptMode = useGetoptMode; });
82 var result = sut.ParseArguments<Options_For_Issue_454>(args);
83 result.Should().BeOfType<Parsed<Options_For_Issue_454>>();
84 result.As<Parsed<Options_For_Issue_454>>().Value.Should().BeEquivalentTo(expected);
85 }
86
87 // Issue #510
88 [Theory]
89 [InlineData(false)]
90 [InlineData(true)]
91
92 public static void Enumerable_before_values_does_not_try_to_parse_too_much(bool useGetoptMode)
93 {
94 var args = new[] { "-a", "1,2", "c" };
95 var expected = new Options_For_Issue_510 { A = new[] { "1", "2" }, C = "c" };
96 var sut = new Parser(parserSettings => { parserSettings.GetoptMode = useGetoptMode; });
97 var result = sut.ParseArguments<Options_For_Issue_510>(args);
98 result.Should().BeOfType<Parsed<Options_For_Issue_510>>();
99 result.As<Parsed<Options_For_Issue_510>>().Value.Should().BeEquivalentTo(expected);
100 }
101
102 // Issue #617
103 [Theory]
104 [InlineData(false)]
105 [InlineData(true)]
106
108 {
109 var args = "--fm D,C a.txt".Split();
110 var expected = new Options_For_Issue_617 {
111 Mode = new[] { FMode.D, FMode.C },
112 Files = new[] { "a.txt" },
113 };
114 var sut = new Parser(parserSettings => { parserSettings.GetoptMode = useGetoptMode; });
115 var result = sut.ParseArguments<Options_For_Issue_617>(args);
116 result.Should().BeOfType<Parsed<Options_For_Issue_617>>();
117 result.As<Parsed<Options_For_Issue_617>>().Value.Should().BeEquivalentTo(expected);
118 }
119
120 // Issue #619
121 [Theory]
122 [InlineData(false)]
123 [InlineData(true)]
124
126 {
127 var args = "--outdir ./x64/Debug --modules ../utilities/x64/Debug,../auxtool/x64/Debug m_xfunit.f03 m_xfunit_assertion.f03".Split();
128 var expected = new Options_For_Issue_619 {
129 OutDir = "./x64/Debug",
130 ModuleDirs = new[] { "../utilities/x64/Debug", "../auxtool/x64/Debug" },
131 Ignores = Enumerable.Empty<string>(),
132 Srcs = new[] { "m_xfunit.f03", "m_xfunit_assertion.f03" },
133 };
134 var sut = new Parser(parserSettings => { parserSettings.GetoptMode = useGetoptMode; });
135 var result = sut.ParseArguments<Options_For_Issue_619>(args);
136 result.Should().BeOfType<Parsed<Options_For_Issue_619>>();
137 result.As<Parsed<Options_For_Issue_619>>().Value.Should().BeEquivalentTo(expected);
138 }
139 }
140}
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
static Specification FromProperty(PropertyInfo property)
static SpecificationProperty Create(Specification specification, PropertyInfo property, Maybe< object > value)
static Token Value(string text)
Definition Token.cs:30
static Func< IEnumerable< string >, IEnumerable< OptionSpecification >, Result< IEnumerable< Token >, Error > > ConfigureTokenizer(StringComparer nameComparer, bool ignoreUnknownArguments, bool enableDashDash)
Definition Tokenizer.cs:166
It contains an instance of type T with parsed values.
Provides methods to parse command line arguments.
Definition Parser.cs:21
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
Definition Parser.cs:216
static void Enumerable_with_separator_before_values_does_not_try_to_parse_too_much(bool useGetoptMode)
static void Values_with_same_name_as_sequence_option_do_not_cause_later_values_to_split_on_separators()
static void Enumerable_with_colon_separator_before_values_does_not_try_to_parse_too_much(bool useGetoptMode)
static void Enumerable_before_values_does_not_try_to_parse_too_much(bool useGetoptMode)
static void Separator_just_before_values_does_not_try_to_parse_values(bool useGetoptMode)
static void Options_with_similar_names_are_not_ambiguous(bool useGetoptMode)
static void Enumerable_with_enum_before_values_does_not_try_to_parse_too_much(bool useGetoptMode)