public void TestThatDependentTypesListIsCorrect()
        {
            var type = (TupleArgumentType)ArgumentType.GetType(typeof(Tuple <bool, int, bool>));

            type.DependentTypes.Should().BeEquivalentTo(
                new[] { typeof(bool), typeof(int) }.Select(ArgumentType.GetType));
        }
Example #2
0
        private ArgumentSummary Summarize(ArgumentDefinition arg)
        {
            var attrib      = arg.Attribute;
            var namedAttrib = arg.Attribute as NamedArgumentAttribute;
            var enumType    = arg.ArgumentType as IEnumArgumentType;

            var isCommand = false;
            var type      = arg.ArgumentType.Type;

            if (type.GetTypeInfo().IsGenericType&&
                type.GetGenericTypeDefinition().Name == "CommandGroup`1")
            {
                enumType  = ArgumentType.GetType(type.GetGenericArguments().First()) as IEnumArgumentType;
                isCommand = true;
            }

            return(new ArgumentSummary
            {
                name = attrib.LongName,
                short_name = namedAttrib?.ShortName,
                required = arg.IsRequired,
                command = isCommand,
                takes_rest_of_line = arg.TakesRestOfLine,
                type = arg.ArgumentType.DisplayName,
                description = attrib.Description,
                default_value = arg.HasDefaultValue ? attrib.DefaultValue : null,
                possible_values = enumType?.GetValues()
                                  .Where(value => !value.Hidden && !value.Disallowed)
                                  .Select(value => Summarize(arg, value))
                                  .ToArray(),
            });
        }
Example #3
0
        public void TestThatDependentTypesFromInnerTypeAreReturned()
        {
            var innerType    = typeof(List <string>);
            var innerArgType = ArgumentType.GetType(innerType);
            var type         = new ArgumentTypeExtension(innerType);

            type.DependentTypes.Should().Equal(innerArgType.DependentTypes);
        }
        public void InvalidUseOfGetCompletions()
        {
            var type = (TupleArgumentType)ArgumentType.GetType(typeof(Tuple <bool, bool>));
            var c    = new ArgumentCompletionContext {
                ParseContext = ArgumentParseContext.Default
            };

            type.Invoking(t => t.GetCompletions(null, "Tr")).Should().Throw <ArgumentNullException>();
            type.Invoking(t => t.GetCompletions(c, null)).Should().Throw <ArgumentNullException>();
        }
        public void GetCompletions()
        {
            var type = (TupleArgumentType)ArgumentType.GetType(typeof(Tuple <bool, int, bool>));
            var c    = new ArgumentCompletionContext {
                ParseContext = ArgumentParseContext.Default
            };

            type.GetCompletions(c, "Tr").Should().Equal("True");
            type.GetCompletions(c, string.Empty).Should().Equal("False", "True");
            type.GetCompletions(c, "False,3").Should().BeEmpty();
            type.GetCompletions(c, "False,3,").Should().Equal("False,3,False", "False,3,True");
        }
        public void GetCompletions()
        {
            var type = (KeyValuePairArgumentType)ArgumentType.GetType(typeof(KeyValuePair <bool, bool>));
            var c    = new ArgumentCompletionContext {
                ParseContext = ArgumentParseContext.Default
            };

            type.GetCompletions(c, "Tr").Should().Equal("True");
            type.GetCompletions(c, string.Empty).Should().Equal("False", "True");
            type.GetCompletions(c, "False=f").Should().Equal("False=False");
            type.GetCompletions(c, "33=f").Should().Equal("33=False");
            type.GetCompletions(c, "True=").Should().Equal("True=False", "True=True");
        }
Example #7
0
        public void GetCompletionsWithValidSeparators()
        {
            var type = (ArrayArgumentType)ArgumentType.GetType(typeof(bool[]));
            var c    = new ArgumentCompletionContext {
                ParseContext = ArgumentParseContext.Default
            };

            type.GetCompletions(c, "Tr").Should().Equal("True");
            type.GetCompletions(c, string.Empty).Should().Equal("False", "True");
            type.GetCompletions(c, "False,f").Should().Equal("False,False");
            type.GetCompletions(c, "33,f").Should().Equal("33,False");
            type.GetCompletions(c, "True,False,").Should().Equal("True,False,False", "True,False,True");
        }
Example #8
0
        public void InvalidUseOfGetCompletions()
        {
            var type = (ArrayArgumentType)ArgumentType.GetType(typeof(bool[]));
            var c    = new ArgumentCompletionContext {
                ParseContext = ArgumentParseContext.Default
            };

            Action badContext = () => type.GetCompletions(null, "Tr");

            badContext.Should().Throw <ArgumentNullException>();

            Action badValue = () => type.GetCompletions(c, null);

            badValue.Should().Throw <ArgumentNullException>();
        }
Example #9
0
        public void GetCompletionsWithoutValidSeparators()
        {
            var type = (ArrayArgumentType)ArgumentType.GetType(typeof(bool[]));
            var c    = new ArgumentCompletionContext
            {
                ParseContext = new ArgumentParseContext
                {
                    ElementSeparators = Array.Empty <string>()
                }
            };

            type.GetCompletions(c, "Tr").Should().Equal("True");
            type.GetCompletions(c, string.Empty).Should().Equal("False", "True");
            type.GetCompletions(c, "False,f").Should().BeEmpty();
            type.GetCompletions(c, "33,f").Should().BeEmpty();
            type.GetCompletions(c, "True,False,").Should().BeEmpty();
        }
Example #10
0
        private static T Xor <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return((T)ty.Xor(operand0, operand1));
        }
Example #11
0
 /// <summary>
 /// Retrieves the the argument type associated with the provided integer
 /// value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>The argument type.</returns>
 internal static IntegerArgumentType GetArgumentType(object value) =>
 (IntegerArgumentType)ArgumentType.GetType(value.GetType());
Example #12
0
 public IEnumerable <IEnumArgumentType> GetTypes()
 {
     return(new[] { (IEnumArgumentType)ArgumentType.GetType(typeof(ExtraCommandsType)) });
 }
Example #13
0
        public void Elements()
        {
            var type = (ArrayArgumentType)ArgumentType.GetType(typeof(int[]));

            type.Format(new[] { 0, 1, 2 }).Should().Be("0, 1, 2");
        }
Example #14
0
        private static bool IsGreaterThan <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return(ty.IsGreaterThan(operand0, operand1));
        }
Example #15
0
        public void TestThatCustomDisplayNameIsObserved()
        {
            var argType = ArgumentType.GetType(typeof(MyCustomType));

            argType.DisplayName.Should().Be(CustomDisplayName);
        }
Example #16
0
 public static bool ShouldHaveResult(this ArgumentType type)
 {
     return(type.GetType().GetField(type.ToString())?.GetCustomAttribute <InnerReturnTypesAttribute>() == null);
 }
Example #17
0
 public static ArgumentReturnType ReturnType(this ArgumentType type)
 {
     return(type.GetType().GetField(type.ToString())?.GetCustomAttribute <ReturnTypeAttribute>()
            ?.ReturnType ?? ArgumentReturnType.Default);
 }
Example #18
0
        private static T MultiplyWithOverflowCheck <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return((T)ty.Multiply(operand0, operand1, true));
        }
Example #19
0
        private static T Multiply <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return((T)ty.Multiply(operand0, operand1));
        }
Example #20
0
        private static T SubtractWithOverflowCheck <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return((T)ty.Subtract(operand0, operand1, true));
        }
Example #21
0
        private static T Subtract <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return((T)ty.Subtract(operand0, operand1));
        }
Example #22
0
        private static bool IsNotEqualTo <T>(T operand0, T operand1)
        {
            var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType());

            return(ty.IsNotEqualTo(operand0, operand1));
        }
Example #23
0
        public void GetTypeThrowsOnNull()
        {
            Action getAction = () => ArgumentType.GetType(null);

            getAction.ShouldThrow <ArgumentNullException>();
        }
Example #24
0
 public static ArgumentReturnType[] InnerReturnTypes(this ArgumentType type)
 {
     return(type.GetType().GetField(type.ToString())?.GetCustomAttribute <InnerReturnTypesAttribute>()
            ?.InnerReturnTypes);
 }