Beispiel #1
0
        public override void VisitIfStatement(IIfStatement stmt, IList <IStatement> body)
        {
            if (IsTargetMatch(stmt, CompletionCase.EmptyCompletionBefore))
            {
                body.Add(EmptyCompletionExpression);
            }
            var ifElseBlock = new IfElseBlock
            {
                Condition = _exprVisitor.ToSimpleExpression(stmt.Condition, body) ?? new UnknownExpression()
            };

            if (IsTargetMatch(stmt, CompletionCase.InBody))
            {
                ifElseBlock.Then.Add(EmptyCompletionExpression);
            }
            if (IsTargetMatch(stmt, CompletionCase.InElse))
            {
                ifElseBlock.Else.Add(EmptyCompletionExpression);
            }
            if (stmt.Then != null)
            {
                stmt.Then.Accept(this, ifElseBlock.Then);
            }
            if (stmt.Else != null)
            {
                stmt.Else.Accept(this, ifElseBlock.Else);
            }

            body.Add(ifElseBlock);

            if (IsTargetMatch(stmt, CompletionCase.EmptyCompletionAfter))
            {
                body.Add(EmptyCompletionExpression);
            }
        }
Beispiel #2
0
        public void Equality_Default()
        {
            var a = new IfElseBlock();
            var b = new IfElseBlock();

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Beispiel #3
0
        public void DefaultValues()
        {
            var sut = new IfElseBlock();

            Assert.AreEqual(new UnknownExpression(), sut.Condition);
            Assert.AreEqual(Lists.NewList <IStatement>(), sut.Then);
            Assert.AreEqual(Lists.NewList <IStatement>(), sut.Else);
            Assert.AreNotEqual(0, sut.GetHashCode());
            Assert.AreNotEqual(1, sut.GetHashCode());
        }
Beispiel #4
0
        public void Equality_DifferentElse()
        {
            var a = new IfElseBlock();

            a.Else.Add(new ContinueStatement());
            var b = new IfElseBlock();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Beispiel #5
0
        public void Equality_DifferentThen()
        {
            var a = new IfElseBlock();

            a.Then.Add(new ReturnStatement());
            var b = new IfElseBlock();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Beispiel #6
0
        public void Equality_DifferentCondition()
        {
            var a = new IfElseBlock {
                Condition = new ConstantValueExpression()
            };
            var b = new IfElseBlock();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Beispiel #7
0
        public void ChildrenIdentity()
        {
            var sut = new IfElseBlock
            {
                Condition = new ConstantValueExpression(),
                Then      = { new ReturnStatement() },
                Else      = { new ContinueStatement() }
            };

            AssertChildren(sut, sut.Condition, sut.Then.First(), sut.Else.First());
        }
Beispiel #8
0
        public void SettingValues()
        {
            var sut = new IfElseBlock
            {
                Condition = new ConstantValueExpression(),
                Then      = { new ReturnStatement() },
                Else      = { new ContinueStatement() }
            };

            Assert.AreEqual(new ConstantValueExpression(), sut.Condition);
            Assert.AreEqual(Lists.NewList(new ReturnStatement()), sut.Then);
            Assert.AreEqual(Lists.NewList(new ContinueStatement()), sut.Else);
        }
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            DynamicInputOperator <int>[] inputs = new DynamicInputOperator <int> [4];
            for (int i = 0; i < 4; i++)
            {
                DynamicInputOperator <int> input = new DynamicInputOperator <int>();
                input.Value = i * 2;
                inputs[i]   = input;
            }

            ComparisonOperationCodeblock left = new ComparisonOperationCodeblock()
            {
                Left      = inputs[0],
                Right     = inputs[1],
                Operation = ComparisonOperation.SmallerOrEqual
            };
            ComparisonOperationCodeblock right = new ComparisonOperationCodeblock()
            {
                Left      = inputs[2],
                Right     = inputs[3],
                Operation = ComparisonOperation.Equal
            };

            LogicOperationCodeblock logic = new LogicOperationCodeblock()
            {
                Left      = left,
                Right     = right,
                Operation = LogicalOperation.OR
            };

            AssertTestBlock ifTrue = new AssertTestBlock();

            ifTrue.Condition = () => true;

            AssertTestBlock ifFalse = new AssertTestBlock();

            ifFalse.Condition = () => false;

            IfElseBlock ifElseBlock = new IfElseBlock();

            ifElseBlock.Condition = logic;

            ifElseBlock.Children.InsertItem(ifTrue, null);
            ifElseBlock.ElseChildren.InsertItem(ifFalse, null);

            system.Blocks.InsertItem(ifElseBlock, null);

            return(system);
        }
Beispiel #10
0
        public void IfElseBlock_NoElseBlock()
        {
            var sst = new IfElseBlock
            {
                Condition = new ConstantValueExpression {
                    Value = "true"
                },
                Then = { new ContinueStatement() }
            };

            AssertPrint(
                sst,
                "if (true)",
                "{",
                "    continue;",
                "}");
        }
Beispiel #11
0
        public void Equality_ReallyTheSame()
        {
            var a = new IfElseBlock
            {
                Condition = new ConstantValueExpression(),
                Then      = { new ReturnStatement() },
                Else      = { new ContinueStatement() }
            };
            var b = new IfElseBlock
            {
                Condition = new ConstantValueExpression(),
                Then      = { new ReturnStatement() },
                Else      = { new ContinueStatement() }
            };

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            AssertTestBlock ifTrue = new AssertTestBlock();

            ifTrue.Condition = () => true;

            AssertTestBlock ifFalse = new AssertTestBlock();

            ifFalse.Condition = () => false;

            var left = new DynamicInputOperator <float>();

            left.Value = 5;
            var right = new DynamicInputOperator <string>();

            right.Value = "1";

            ComparisonOperationCodeblock coc = new ComparisonOperationCodeblock();

            coc.Operation = ComparisonOperation.GreaterThan;
            coc.Left      = left;
            coc.Right     = right;

            IfElseBlock ifelse = new IfElseBlock();

            ifelse.Condition = coc;

            ifelse.Children.InsertItem(ifTrue, null);
            ifelse.ElseChildren.InsertItem(ifFalse, null);

            system.Blocks.InsertItem(ifelse, null);

            return(system);
        }
Beispiel #13
0
        public void VisitorWithReturnIsImplemented()
        {
            var sut = new IfElseBlock();

            sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23));
        }