public void GetIndexedStringOutOfBound()
        {
            Machine machine = new Machine();

            IndexedExpression expression = new IndexedExpression(new ConstantExpression("foo"), new ConstantExpression(10));

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNull(result);
        }
        public void GetIndexedStringNegativeIndexAsNil()
        {
            Machine machine = new Machine();

            IndexedExpression expression = new IndexedExpression(new ConstantExpression("bar"), new ConstantExpression(-10));

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNull(result);
        }
        public void EvaluateIndexedExpressionListInteger()
        {
            var list = new List <int>()
            {
                1, 2, 3
            };
            IndexedExpression expr = new IndexedExpression(new ConstantExpression(list), new ConstantExpression(1));

            Assert.AreEqual(2, expr.Evaluate(null));
        }
        public void GetIndexedString()
        {
            Machine machine = new Machine();

            IndexedExpression expression = new IndexedExpression(new ConstantExpression("foo"), new ConstantExpression(0));

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNotNull(result);
            Assert.AreEqual("f", result);
        }
        public void GetIndexedOutOfBandValue()
        {
            Machine machine = new Machine();

            machine.ExecuteText("a = [1,2,3]");

            IndexedExpression expression = new IndexedExpression(new NameExpression("a"), new ConstantExpression(10));

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNull(result);
        }
        public void GetIndexedNegativeValue()
        {
            Machine machine = new Machine();

            machine.ExecuteText("a = [1,2,3]");

            IndexedExpression expression = new IndexedExpression(new NameExpression("a"), new ConstantExpression(-1));

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result);
        }
        public void GetIndexedDictionaryEntryAsNil()
        {
            Machine machine = new Machine();
            var     hash    = new DynamicHash();

            hash[new Symbol("one")] = 1;
            hash[new Symbol("two")] = 2;

            IndexedExpression expression = new IndexedExpression(new ConstantExpression(hash), new ConstantExpression(new Symbol("three")));

            var result = expression.Evaluate(machine.RootContext);

            Assert.IsNull(result);
        }
        public void EvaluateIndexedExpressionStringInteger()
        {
            IndexedExpression expr = new IndexedExpression(new ConstantExpression("foo"), new ConstantExpression(0));

            Assert.AreEqual("f", expr.Evaluate(null));
        }