Esempio n. 1
0
        public void CharIteration()
        {
            IArgumentEnumerator e = new OneCharStringEnumerator("abcd");
            e.MoveNext();

            Assert.AreEqual("a", e.Current);
            Assert.AreEqual("b", e.Next);
            Assert.AreEqual("bcd", e.GetRemainingFromNext());
            Assert.IsFalse(e.IsLast);

            e.MoveNext();

            Assert.AreEqual("b", e.Current);
            Assert.AreEqual("c", e.Next);
            Assert.AreEqual("cd", e.GetRemainingFromNext());
            Assert.IsFalse(e.IsLast);

            e.MoveNext();

            Assert.AreEqual("c", e.Current);
            Assert.AreEqual("d", e.Next);
            Assert.AreEqual("d", e.GetRemainingFromNext());
            Assert.IsFalse(e.IsLast);

            e.MoveNext();

            Assert.AreEqual("d", e.Current);
            Assert.IsTrue(e.IsLast);
        }
        public void CharIteration()
        {
            IArgumentEnumerator e = new OneCharStringEnumerator("abcd");

            e.MoveNext();

            Assert.AreEqual("a", e.Current);
            Assert.AreEqual("b", e.Next);
            Assert.AreEqual("bcd", e.GetRemainingFromNext());
            Assert.IsFalse(e.IsLast);

            e.MoveNext();

            Assert.AreEqual("b", e.Current);
            Assert.AreEqual("c", e.Next);
            Assert.AreEqual("cd", e.GetRemainingFromNext());
            Assert.IsFalse(e.IsLast);

            e.MoveNext();

            Assert.AreEqual("c", e.Current);
            Assert.AreEqual("d", e.Next);
            Assert.AreEqual("d", e.GetRemainingFromNext());
            Assert.IsFalse(e.IsLast);

            e.MoveNext();

            Assert.AreEqual("d", e.Current);
            Assert.IsTrue(e.IsLast);
        }
Esempio n. 3
0
        public void Char_iteration()
        {
            IArgumentEnumerator e = new OneCharStringEnumerator("abcd");
            e.MoveNext();

            e.Current.Should().Be("a");
            e.Next.Should().Be("b");
            e.GetRemainingFromNext().Should().Be("bcd");
            e.IsLast.Should().BeFalse();

            e.MoveNext();

            e.Current.Should().Be("b");
            e.Next.Should().Be("c");
            e.GetRemainingFromNext().Should().Be("cd");
            e.IsLast.Should().BeFalse();

            e.MoveNext();

            e.Current.Should().Be("c");
            e.Next.Should().Be("d");
            e.GetRemainingFromNext().Should().Be("d");
            e.IsLast.Should().BeFalse();

            e.MoveNext();

            e.Current.Should().Be("d");
            e.IsLast.Should().BeTrue();
        }
Esempio n. 4
0
        public void Char_iteration()
        {
            IArgumentEnumerator e = new OneCharStringEnumerator("abcd");

            e.MoveNext();

            e.Current.Should().Be("a");
            e.Next.Should().Be("b");
            e.GetRemainingFromNext().Should().Be("bcd");
            e.IsLast.Should().BeFalse();

            e.MoveNext();

            e.Current.Should().Be("b");
            e.Next.Should().Be("c");
            e.GetRemainingFromNext().Should().Be("cd");
            e.IsLast.Should().BeFalse();

            e.MoveNext();

            e.Current.Should().Be("c");
            e.Next.Should().Be("d");
            e.GetRemainingFromNext().Should().Be("d");
            e.IsLast.Should().BeFalse();

            e.MoveNext();

            e.Current.Should().Be("d");
            e.IsLast.Should().BeTrue();
        }
        public override sealed ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            IArgumentEnumerator group = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1));
            while (group.MoveNext())
            {
                var option = map[group.Current];
                if (option == null)
                    return ParserState.Failure;

                option.IsDefined = true;

                ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && group.IsLast)
                        return ParserState.Failure;

                    if (!group.IsLast)
                    {
                        if (!option.IsArray)
                            return ArgumentParser.BooleanToParserState(option.SetValue(group.GetRemainingFromNext(), options));
                        else
                        {
                            ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                            var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                            items.Insert(0, group.GetRemainingFromNext());
                            return ArgumentParser.BooleanToParserState(option.SetValue(items, options), true);
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                        return ParserState.Failure;
                    else
                    {
                        if (!option.IsArray)
                            return ArgumentParser.BooleanToParserState(option.SetValue(argumentEnumerator.Next, options), true);
                        else
                        {
                            ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                            var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                            return ArgumentParser.BooleanToParserState(option.SetValue(items, options));
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                        return ParserState.Failure;

                    if (!option.SetValue(true, options))
                        return ParserState.Failure;
                }
            }

            return ParserState.Success;
        }
Esempio n. 6
0
        public override PresentParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            var optionGroup = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1));

            while (optionGroup.MoveNext())
            {
                var option = map[optionGroup.Current];
                if (option == null)
                {
                    return _ignoreUnkwnownArguments ? PresentParserState.MoveOnNextElement : PresentParserState.Failure;
                }

                option.IsDefined = true;

                ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && optionGroup.IsLast)
                    {
                        return PresentParserState.Failure;
                    }

                    bool valueSetting;
                    if (!optionGroup.IsLast)
                    {
                        if (!option.IsArray)
                        {
                            valueSetting = option.SetValue(optionGroup.GetRemainingFromNext(), options);
                            if (!valueSetting)
                            {
                                DefineOptionThatViolatesFormat(option);
                            }

                            return ArgumentParser.BooleanToParserState(valueSetting);
                        }

                        ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                        var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                        items.Insert(0, optionGroup.GetRemainingFromNext());

                        valueSetting = option.SetValue(items, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return ArgumentParser.BooleanToParserState(valueSetting, true);
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return PresentParserState.Failure;
                    }

                    if (!option.IsArray)
                    {
                        valueSetting = option.SetValue(argumentEnumerator.Next, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return ArgumentParser.BooleanToParserState(valueSetting, true);
                    }

                    ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                    var moreItems = ArgumentParser.GetNextInputValues(argumentEnumerator);

                    valueSetting = option.SetValue(moreItems, options);
                    if (!valueSetting)
                    {
                        DefineOptionThatViolatesFormat(option);
                    }

                    return ArgumentParser.BooleanToParserState(valueSetting);
                }

                if (!optionGroup.IsLast && map[optionGroup.Next] == null)
                {
                    return PresentParserState.Failure;
                }

                if (!argumentEnumerator.IsLast)
                {
                    string value = argumentEnumerator.Next;
                    bool result;
                    if (bool.TryParse(value, out result))
                    {
                        if (!option.SetValue(value, options))
                        {
                            return PresentParserState.Failure;
                        }
                        argumentEnumerator.MoveNext();
                    }
                    else if (!option.SetValue(true, options))
                    {
                        return PresentParserState.Failure;
                    }
                }
                else
                {
                    if (!option.SetValue(true, options))
                    {
                        return PresentParserState.Failure;
                    }
                }
            }

            return PresentParserState.Success;
        }
Esempio n. 7
0
        public sealed override ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            IArgumentEnumerator group = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1));

            while (group.MoveNext())
            {
                var option = map[group.Current];
                if (option == null)
                {
                    return(ParserState.Failure);
                }

                option.IsDefined = true;

                ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && group.IsLast)
                    {
                        return(ParserState.Failure);
                    }

                    if (!group.IsLast)
                    {
                        if (!option.IsArray)
                        {
                            return(ArgumentParser.BooleanToParserState(option.SetValue(group.GetRemainingFromNext(), options)));
                        }
                        else
                        {
                            ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                            var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                            items.Insert(0, group.GetRemainingFromNext());
                            return(ArgumentParser.BooleanToParserState(option.SetValue(items, options), true));
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(ParserState.Failure);
                    }
                    else
                    {
                        if (!option.IsArray)
                        {
                            return(ArgumentParser.BooleanToParserState(option.SetValue(argumentEnumerator.Next, options), true));
                        }
                        else
                        {
                            ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                            var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                            return(ArgumentParser.BooleanToParserState(option.SetValue(items, options)));
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                    {
                        return(ParserState.Failure);
                    }

                    if (!option.SetValue(true, options))
                    {
                        return(ParserState.Failure);
                    }
                }
            }

            return(ParserState.Success);
        }
Esempio n. 8
0
        public override PresentParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            var optionGroup = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1));

            while (optionGroup.MoveNext())
            {
                var option = map[optionGroup.Current];
                if (option == null)
                {
                    return(_ignoreUnkwnownArguments ? PresentParserState.MoveOnNextElement : PresentParserState.Failure);
                }

                option.IsDefined = true;

                ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && optionGroup.IsLast)
                    {
                        return(PresentParserState.Failure);
                    }

                    bool valueSetting;
                    if (!optionGroup.IsLast)
                    {
                        if (!option.IsArray)
                        {
                            valueSetting = option.SetValue(optionGroup.GetRemainingFromNext(), options);
                            if (!valueSetting)
                            {
                                DefineOptionThatViolatesFormat(option);
                            }

                            return(ArgumentParser.BooleanToParserState(valueSetting));
                        }

                        ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                        var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                        items.Insert(0, optionGroup.GetRemainingFromNext());

                        valueSetting = option.SetValue(items, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return(ArgumentParser.BooleanToParserState(valueSetting, true));
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(PresentParserState.Failure);
                    }

                    if (!option.IsArray)
                    {
                        valueSetting = option.SetValue(argumentEnumerator.Next, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return(ArgumentParser.BooleanToParserState(valueSetting, true));
                    }

                    ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                    var moreItems = ArgumentParser.GetNextInputValues(argumentEnumerator);

                    valueSetting = option.SetValue(moreItems, options);
                    if (!valueSetting)
                    {
                        DefineOptionThatViolatesFormat(option);
                    }

                    return(ArgumentParser.BooleanToParserState(valueSetting));
                }

                if (!optionGroup.IsLast && map[optionGroup.Next] == null)
                {
                    return(PresentParserState.Failure);
                }

                if (!option.SetValue(true, options))
                {
                    return(PresentParserState.Failure);
                }
            }

            return(PresentParserState.Success);
        }