public void IntParserShouldConvertAStringValueToAnInteger()
        {
            var parser = new IntArgumentParser();
            var result = parser.Parse("3");

            Assert.AreEqual(3, result);
        }
        public void IntParserShouldConvertADoubleToAnInteger()
        {
            var parser = new IntArgumentParser();
            var result = parser.Parse(3d);

            Assert.AreEqual(3, result);
        }
        public void CanParseIntTest()
        {
            ArgumentPack pack = new ArgumentPack("1000");

            var parser = new IntArgumentParser();

            Assert.True(parser.CanParse(pack, typeof(int)));

            var result = (int)parser.Parse(pack, typeof(int));

            Assert.Equal(1000, result);
        }
Example #4
0
        public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);
            var items = new List<object>();
            for (int x = 0; x < arguments.Count(); x++)
            {
                items.Add(arguments.ElementAt(x).ValueFirst);
            }

            var chooseIndeces = arguments.ElementAt(0).ValueFirst as IEnumerable<FunctionArgument>;
            if (chooseIndeces != null && chooseIndeces.Count() > 1)
            {
                IntArgumentParser intParser = new IntArgumentParser();
                object[] values = chooseIndeces.Select(chosenIndex => items[(int)intParser.Parse(chosenIndex.ValueFirst)]).ToArray();
                return CreateResult(values, DataType.Enumerable);
            }
            else
            {
                var index = ArgToInt(arguments, 0);
                return CreateResult(items[index].ToString(), DataType.String);
            }
        }
Example #5
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);
            var items = new List <object>();

            for (int x = 0; x < arguments.Count(); x++)
            {
                items.Add(arguments.ElementAt(x).ValueFirst);
            }

            var chooseIndeces = arguments.ElementAt(0).ValueFirst as IEnumerable <FunctionArgument>;

            if (chooseIndeces != null && chooseIndeces.Count() > 1)
            {
                IntArgumentParser intParser = new IntArgumentParser();
                object[]          values    = chooseIndeces.Select(chosenIndex => items[(int)intParser.Parse(chosenIndex.ValueFirst)]).ToArray();
                return(CreateResult(values, DataType.Enumerable));
            }
            else
            {
                var index = ArgToInt(arguments, 0);
                return(CreateResult(items[index].ToString(), DataType.String));
            }
        }
        public void IntParserShouldThrowIfArgumentIsNull()
        {
            var parser = new IntArgumentParser();

            parser.Parse(null);
        }