public void DefaultValues()
        {
            var sut = new CastExpression();

            Assert.AreEqual(new VariableReference(), sut.Reference);
            Assert.AreEqual(Names.UnknownType, sut.TargetType);
            Assert.AreEqual(CastOperator.Unknown, sut.Operator);
            Assert.AreNotEqual(0, sut.GetHashCode());
            Assert.AreNotEqual(1, sut.GetHashCode());
        }
예제 #2
0
        public void TestCastExpressionEquals()
        {
            CastExpression first = new CastExpression()
            {
                ScalarExpression = new StringLiteral()
                {
                    Value = "test"
                },
                ToType = "t"
            };

            CastExpression firstClone = new CastExpression()
            {
                ScalarExpression = new StringLiteral()
                {
                    Value = "test"
                },
                ToType = "t"
            };

            CastExpression second = new CastExpression()
            {
                ScalarExpression = new StringLiteral()
                {
                    Value = "test2"
                },
                ToType = "t"
            };

            CastExpression third = new CastExpression()
            {
                ScalarExpression = new StringLiteral()
                {
                    Value = "test"
                },
                ToType = "t2"
            };

            //Equals
            Assert.IsTrue(Equals(first, firstClone));
            Assert.IsFalse(Equals(first, null));
            Assert.IsFalse(Equals(first, second));
            Assert.IsFalse(Equals(first, third));
            Assert.IsFalse(Equals(first, "other type"));

            //Hash code
            Assert.AreEqual(first.GetHashCode(), firstClone.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), third.GetHashCode());
        }
        public void Equality_Default()
        {
            var a = new CastExpression();
            var b = new CastExpression();

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void Equality_DifferentTargetType()
        {
            var a = new CastExpression
            {
                TargetType = Names.Type("T,P")
            };

            var b = new CastExpression();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void Equality_DifferentOperation()
        {
            var a = new CastExpression
            {
                Operator = CastOperator.SafeCast
            };

            var b = new CastExpression();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void Equality_DifferentVarRef()
        {
            var a = new CastExpression
            {
                Reference = SomeVarRef("i")
            };

            var b = new CastExpression();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void Equality_ReallyTheSame()
        {
            var a = new CastExpression
            {
                TargetType = Names.Type("T,P"),
                Reference  = SomeVarRef(),
                Operator   = CastOperator.SafeCast
            };

            var b = new CastExpression
            {
                TargetType = Names.Type("T,P"),
                Reference  = SomeVarRef(),
                Operator   = CastOperator.SafeCast
            };

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }