public static void ExtractingNestedNamedArguments_ShouldNotWork() { var args = new[] { "-b", "-a", "1", "2" }; IArgumentExtractor extractor = new ArgumentExtractor(args); var successA = extractor.TryExtractNamedArgument("-a", out var extractedValueA, out extractor); var successB = extractor.TryExtractNamedArgument("-b", out var extractedValueB, out _); successA.Should().BeTrue(); successB.Should().BeFalse(); extractedValueA.Should().Be("1"); }
public static void ExtractingArgumentsWithDifferentAssignmentsOperators_ShouldWork() { var args = new[] { "-a=1", "-b:2" }; var assignmentOperators = new[] { "=", ":" }; IArgumentExtractor extractor = new ArgumentExtractor(args); var successA = extractor.TryExtractNamedArgument("-a", out var argA, out extractor, assignmentOperators); var successB = extractor.TryExtractNamedArgument("-b", out var argB, out _, assignmentOperators); successA.Should().BeTrue(); successB.Should().BeTrue(); argA.Should().Be("1"); argB.Should().Be("2"); }
public static void ExtractingMultipleSerialNamedArguments_ShouldWork() { var args = new[] { "-a", "1", "-b", "2", "-c", "3", "dummy", "-d", "4" }; IArgumentExtractor extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-a", out var valueA, out extractor); success = extractor.TryExtractNamedArgument("-b", out var valueB, out extractor) && success; success = extractor.TryExtractNamedArgument("-d", out var valueD, out extractor) && success; success = extractor.TryExtractNamedArgument("-c", out var valueC, out _) && success; success.Should().BeTrue(); valueA.Should().Be("1"); valueB.Should().Be("2"); valueC.Should().Be("3"); valueD.Should().Be("4"); }
public static void ExtractingNamedArgumentsWithoutAValue_ShouldNotWork() { var args = new[] { "-a" }; IArgumentExtractor extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-a", out var value, out _); success.Should().BeFalse(); }
public static void ExtractingNamedArgumentWithMultipleButOnlyOneValidCandidate_ShouldWork() { var args = new[] { "-c", "-k", "-a", "1", "-b", "2", "3", "-c" }; IArgumentExtractor extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-c", out var value, out _); success.Should().BeTrue(); value.Should().Be("-k"); }
public static void ExtractingArgumentsWithMultipleOverlappingCandidates_ShouldReturnTheFirst() { var args = new[] { "-a", "-a", "2" }; IArgumentExtractor extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-a", out var extractedArgument, out _); success.Should().BeTrue(); extractedArgument.Should().Be("-a"); }
public static void WhitespaceAssignmentOperators_ShouldBeValid(string assignmentOperator) { var args = new[] { $"-a{assignmentOperator}xyz" }; var extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-a", out var argA, out _, new[] { assignmentOperator }); success.Should().BeTrue(); argA.Should().Be("xyz"); }
public static void DespiteDefiningAssignemtnOperatorsExtractionWithout_ShouldWork() { var args = new[] { "-a", "1" }; var extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-a", out var argA, out _, new[] { "=" }); success.Should().BeTrue(); argA.Should().Be("1"); }
public static void ExtractingArgumentsWithEqualSign_ShouldWork() { var args = new[] { "-a=1" }; var extractor = new ArgumentExtractor(args); var success = extractor.TryExtractNamedArgument("-a", out var value, out _, new[] { "=" }); success.Should().BeTrue(); value.Should().Be("1"); }
public static void ExtractingNamedArgumentWithFollowingArguments_ShouldWork( string argument, string[] allArguments, string expectedValue) { var extractor = new ArgumentExtractor(allArguments); var success = extractor.TryExtractNamedArgument(argument, out var value, out _); success.Should().BeTrue(); value.Should().Be(expectedValue); }