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)); }
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(), }); }
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"); }
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"); }
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>(); }
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(); }
private static T Xor <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return((T)ty.Xor(operand0, operand1)); }
/// <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());
public IEnumerable <IEnumArgumentType> GetTypes() { return(new[] { (IEnumArgumentType)ArgumentType.GetType(typeof(ExtraCommandsType)) }); }
public void Elements() { var type = (ArrayArgumentType)ArgumentType.GetType(typeof(int[])); type.Format(new[] { 0, 1, 2 }).Should().Be("0, 1, 2"); }
private static bool IsGreaterThan <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return(ty.IsGreaterThan(operand0, operand1)); }
public void TestThatCustomDisplayNameIsObserved() { var argType = ArgumentType.GetType(typeof(MyCustomType)); argType.DisplayName.Should().Be(CustomDisplayName); }
public static bool ShouldHaveResult(this ArgumentType type) { return(type.GetType().GetField(type.ToString())?.GetCustomAttribute <InnerReturnTypesAttribute>() == null); }
public static ArgumentReturnType ReturnType(this ArgumentType type) { return(type.GetType().GetField(type.ToString())?.GetCustomAttribute <ReturnTypeAttribute>() ?.ReturnType ?? ArgumentReturnType.Default); }
private static T MultiplyWithOverflowCheck <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return((T)ty.Multiply(operand0, operand1, true)); }
private static T Multiply <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return((T)ty.Multiply(operand0, operand1)); }
private static T SubtractWithOverflowCheck <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return((T)ty.Subtract(operand0, operand1, true)); }
private static T Subtract <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return((T)ty.Subtract(operand0, operand1)); }
private static bool IsNotEqualTo <T>(T operand0, T operand1) { var ty = (IntegerArgumentType)ArgumentType.GetType(operand0.GetType()); return(ty.IsNotEqualTo(operand0, operand1)); }
public void GetTypeThrowsOnNull() { Action getAction = () => ArgumentType.GetType(null); getAction.ShouldThrow <ArgumentNullException>(); }
public static ArgumentReturnType[] InnerReturnTypes(this ArgumentType type) { return(type.GetType().GetField(type.ToString())?.GetCustomAttribute <InnerReturnTypesAttribute>() ?.InnerReturnTypes); }