BadScript 2
Loading...
Searching...
No Matches
InstanceChooserTests.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Globalization;
6using System.Linq;
7using Xunit;
8using FluentAssertions;
11
13{
15 {
17 IEnumerable<Type> types,
18 IEnumerable<string> arguments,
19 bool multiInstance = false)
20 {
22 (args, optionSpecs) => Tokenizer.ConfigureTokenizer(StringComparer.Ordinal, false, false)(args, optionSpecs),
23 types,
24 arguments,
25 StringComparer.Ordinal,
26 false,
27 CultureInfo.InvariantCulture,
28 true,
29 true,
30 multiInstance,
31 Enumerable.Empty<ErrorType>());
32 }
33
34 [Fact]
36 {
37 // Fixture setup
38 var expectedErrors = new[] { new NoVerbSelectedError() };
39
40 // Exercize system
41 var result = InvokeChoose(
42 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb) },
43 new string[] { });
44
45 // Verify outcome
46 ((NotParsed<object>)result).Errors.Should().BeEquivalentTo(expectedErrors);
47
48 // Teardown
49 }
50
51 [Fact]
53 {
54 // Fixture setup
55 var expectedErrors = new[] { new HelpVerbRequestedError(null, null, false) };
56
57 // Exercize system
58 var result = InvokeChoose(
59 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb) },
60 new[] { "help" });
61
62 // Verify outcome
63 ((NotParsed<object>)result).Errors.Should().BeEquivalentTo(expectedErrors);
64
65 // Teardown
66 }
67
68 [Fact]
70 {
71 // Fixture setup
72 var expectedErrors = new[] { new HelpVerbRequestedError("commit", typeof(Commit_Verb), true) };
73
74 // Exercize system
75 var result = InvokeChoose(
76 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb) },
77 new[] { "help", "commit" });
78
79 // Verify outcome
80 ((NotParsed<object>)result).Errors.Should().BeEquivalentTo(expectedErrors);
81
82 // Teardown
83 }
84
85 [Fact]
87 {
88 // Fixture setup
89 var expectedErrors = new[] { new HelpVerbRequestedError(null, null, false) };
90
91 // Exercize system
92 var result = InvokeChoose(
93 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb) },
94 new[] { "help", "earthunderalienattack" });
95
96 // Verify outcome
97 ((NotParsed<object>)result).Errors.Should().BeEquivalentTo(expectedErrors);
98
99 // Teardown
100 }
101
102 [Fact]
104 {
105 // Fixture setup
106 var expected = new Add_Verb { Patch = true, FileName = "dummy.bin"};
107
108 // Exercize system
109 var result = InvokeChoose(
110 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb) },
111 new[] { "add", "--patch", "dummy.bin" });
112
113 // Verify outcome
114 Assert.IsType<Add_Verb>(((Parsed<object>)result).Value);
115 expected.Should().BeEquivalentTo(((Parsed<object>)result).Value);
116 // Teardown
117 }
118
119 [Fact]
121 {
122 // Fixture setup
123 var expected = new Immutable_Add_Verb(true, default(bool), "dummy.bin");
124
125 // Exercize system
126 var result = InvokeChoose(
127 new[] { typeof(Immutable_Add_Verb), typeof(Immutable_Commit_Verb), typeof(Immutable_Clone_Verb) },
128 new[] { "add", "--patch", "dummy.bin" });
129
130 // Verify outcome
131 Assert.IsType<Immutable_Add_Verb>(((Parsed<object>)result).Value);
132 expected.Should().BeEquivalentTo(((Parsed<object>)result).Value);
133 // Teardown
134 }
135
136 [Fact]
138 {
139 // Fixture setup
140 var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = new[] { "aa", "b" } };
141
142 // Exercize system
143 var result = InvokeChoose(
144 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb), typeof(SequenceOptions) },
145 new[] { "sequence", "-s", "aa", "b" });
146
147 // Verify outcome
148 Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
149 expected.Should().BeEquivalentTo(((Parsed<object>)result).Value);
150 // Teardown
151 }
152
153 [Theory]
154 [InlineData(new[] { "sequence", "-s", "here-one-elem-but-no-sep" }, new[] { "here-one-elem-but-no-sep" })]
155 [InlineData(new[] { "sequence", "-shere-one-elem-but-no-sep" }, new[] { "here-one-elem-but-no-sep" })]
156 [InlineData(new[] { "sequence", "-s", "eml1@xyz.com,test@unit.org,xyz@srv.it" }, new[] { "eml1@xyz.com", "test@unit.org", "xyz@srv.it" })]
157 [InlineData(new[] { "sequence", "-sInlineData@iscool.org,test@unit.org,xyz@srv.it,another,the-last-one" }, new[] { "InlineData@iscool.org", "test@unit.org", "xyz@srv.it", "another", "the-last-one" })]
158 public void Parse_sequence_verb_with_separator_returns_verb_instance(string[] arguments, string[] expectedString)
159 {
160 // Fixture setup
161 var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = expectedString };
162
163 // Exercize system
164 var result = InvokeChoose(
165 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb), typeof(SequenceOptions) },
166 arguments);
167
168 // Verify outcome
169 Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
170 expected.Should().BeEquivalentTo(((Parsed<object>)result).Value);
171 // Teardown
172 }
173
174 [Fact]
176 {
177 var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = new[] { "s1", "s2" } };
178 var result = InvokeChoose(
179 new[] { typeof(Add_Verb), typeof(Commit_Verb), typeof(Clone_Verb), typeof(SequenceOptions) },
180 new[] { "sequence", "-s", "s1", "-s", "s2" },
181 true);
182
183 Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
184 expected.Should().BeEquivalentTo(((Parsed<object>)result).Value);
185 }
186 }
187}
static ParserResult< object > Choose(Func< IEnumerable< string >, IEnumerable< OptionSpecification >, Result< IEnumerable< Token >, Error > > tokenizer, IEnumerable< Type > types, IEnumerable< string > arguments, StringComparer nameComparer, bool ignoreValueCase, CultureInfo parsingCulture, bool autoHelp, bool autoVersion, IEnumerable< ErrorType > nonFatalErrors)
static Func< IEnumerable< string >, IEnumerable< OptionSpecification >, Result< IEnumerable< Token >, Error > > ConfigureTokenizer(StringComparer nameComparer, bool ignoreUnknownArguments, bool enableDashDash)
Definition Tokenizer.cs:166
Models an error generated when a user explicitly requests help in verb commands scenario.
Definition Error.cs:463
Models an error generated when no verb is selected.
Definition Error.cs:495
It contains a sequence of CommandLine.Error.
It contains an instance of type T with parsed values.
Models a parser result. When inherited by CommandLine.Parsed<T>, it contains an instance of type T w...
void Parse_sequence_verb_with_separator_returns_verb_instance(string[] arguments, string[] expectedString)
void Explicit_help_request_for_an_invalid_verb_generates_HelpVerbRequestedError_with_Matched_set_to_false()
static ParserResult< object > InvokeChoose(IEnumerable< Type > types, IEnumerable< string > arguments, bool multiInstance=false)
ErrorType
Discriminator enumeration of CommandLine.Error derivates.
Definition Error.cs:13