Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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");
        }
Ejemplo n.º 10
0
        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);
        }