Beispiel #1
0
        public void Equals()
        {
            IList <IExpression> keyexprs1   = new IExpression[] { new ConstantExpression(new Symbol("one")), new ConstantExpression(new Symbol("three")) };
            IList <IExpression> valueexprs1 = new IExpression[] { new ConstantExpression("one"), new ConstantExpression("three") };
            IList <IExpression> keyexprs2   = new IExpression[] { new ConstantExpression(new Symbol("one")), new ConstantExpression(new Symbol("two")) };
            IList <IExpression> valueexprs2 = new IExpression[] { new ConstantExpression("one"), new ConstantExpression("two") };

            HashExpression expr1 = new HashExpression(keyexprs1, valueexprs1);
            HashExpression expr2 = new HashExpression(keyexprs1, valueexprs2);
            HashExpression expr3 = new HashExpression(keyexprs2, valueexprs1);
            HashExpression expr4 = new HashExpression(keyexprs2, valueexprs2);
            HashExpression expr5 = new HashExpression(keyexprs1, valueexprs1);

            Assert.IsFalse(expr1.Equals(null));
            Assert.IsFalse(expr1.Equals("foo"));
            Assert.IsFalse(expr1.Equals(123));

            Assert.IsTrue(expr1.Equals(expr1));
            Assert.IsTrue(expr1.Equals(expr5));
            Assert.IsTrue(expr5.Equals(expr1));

            Assert.AreEqual(expr1.GetHashCode(), expr5.GetHashCode());

            Assert.IsFalse(expr1.Equals(expr2));
            Assert.IsFalse(expr2.Equals(expr1));
            Assert.IsFalse(expr1.Equals(expr3));
            Assert.IsFalse(expr3.Equals(expr1));
            Assert.IsFalse(expr1.Equals(expr4));
            Assert.IsFalse(expr4.Equals(expr1));
        }
Beispiel #2
0
        private IExpression ParseHashExpression()
        {
            var hash = new HashExpression {
                Token = CurToken
            };

            hash.Data = ParseHashPairs();

            return(hash);
        }
Beispiel #3
0
        public void ParseEmptyHash()
        {
            Parser parser   = new Parser("{  }");
            var    expected = new HashExpression(new IExpression[0], new IExpression[0]);
            var    result   = parser.ParseExpression();

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);

            Assert.IsNull(parser.ParseCommand());
        }
Beispiel #4
0
        public void ParseSimpleHash()
        {
            Parser parser   = new Parser("{ :one=>1, :two => 2 }");
            var    expected = new HashExpression(new IExpression[] { new ConstantExpression(new Symbol("one")), new ConstantExpression(new Symbol("two")) }, new IExpression[] { new ConstantExpression(1), new ConstantExpression(2) });
            var    result   = parser.ParseExpression();

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);

            Assert.IsNull(parser.ParseCommand());
        }
Beispiel #5
0
        public void EvaluateWithSymbolKeys()
        {
            IList <IExpression> keyexprs   = new IExpression[] { new ConstantExpression(new Symbol("one")), new ConstantExpression(new Symbol("three")) };
            IList <IExpression> valueexprs = new IExpression[] { new ConstantExpression("one"), new ConstantExpression("three") };

            HashExpression expr = new HashExpression(keyexprs, valueexprs);

            var result = expr.Evaluate(null);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IDictionary));

            var dict = (IDictionary)result;

            Assert.AreEqual("one", dict[new Symbol("one")]);
            Assert.AreEqual("three", dict[new Symbol("three")]);
        }
Beispiel #6
0
 public override void Accept(HashExpression hash)
 {
     hash.VisitChildren(this);
 }
Beispiel #7
0
 public override void Accept(HashExpression hash)
 {
     hash.VisitChildren(this);
     methodBuilder.EmitInstruction(hash.Location, Opcode.BuildHash, hash.Children.Count / 2);
 }
Beispiel #8
0
 public override void Accept(HashExpression hash)
 {
     hash.Visit(functionCompiler);
 }
Beispiel #9
0
 public virtual void Accept(HashExpression hash)
 {
 }
Beispiel #10
0
 public override void Accept(HashExpression hash)
 {
     hash.Visit(parentVisitor);
 }