Beispiel #1
0
        public void CombineFilterAtSameLevelWithDifferentStatements()
        {
            // Two if statements with same "if", at the same level, and combine second with first.

            // Next, we will do the two common ones.
            var f1 = new StatementFilter(new ValSimple("f1", typeof(bool)));
            var f2 = new StatementFilter(new ValSimple("f1", typeof(bool)));

            var p1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var p2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var a1 = new StatementAssign(p1, new ValSimple("5", typeof(int)));
            var a2 = new StatementAssign(p2, new ValSimple("15", typeof(int)));

            f1.Add(a1);
            f1.Add(p1);
            f2.Add(a2);
            f2.Add(p2);


            Console.WriteLine("Before optimization:");
            foreach (var l in f1.CodeItUp())
            {
                Console.WriteLine(l);
            }

            Assert.IsTrue(f1.TryCombineStatement(f2, null), "Two of the same if statements, and the combine should have worked");

            Console.WriteLine("After optimization:");
            foreach (var l in f1.CodeItUp())
            {
                Console.WriteLine(l);
            }
            Assert.AreEqual(2, f1.Statements.Count());
        }
Beispiel #2
0
        public void TestExprNoStatements()
        {
            var val       = new Variables.ValSimple("true", typeof(bool));
            var statement = new StatementFilter(val);

            var result = statement.CodeItUp().ToArray();

            Assert.AreEqual(0, result.Length, "no statements, so wasn't expecting any sort of output at all");
        }
Beispiel #3
0
        public void TestFalseExpr()
        {
            var val       = new Variables.ValSimple("false", typeof(bool));
            var statement = new StatementFilter(val);

            statement.Add(new StatementSimpleStatement("dude"));

            var result = statement.CodeItUp().ToArray();

            Assert.AreEqual(0, result.Length, "Expect no statements for a false if statement");
        }
Beispiel #4
0
        public void TestTrueExpr()
        {
            var val       = new Variables.ValSimple("true", typeof(bool));
            var statement = new StatementFilter(val);

            statement.Add(new StatementSimpleStatement("dude"));

            var result = statement.CodeItUp().ToArray();

            Assert.AreEqual(3, result.Length, "true test means only the involved statements should be in here!");
            Assert.AreEqual("{", result[0], "open bracket");
            Assert.AreEqual("  dude;", result[1], "statement isn't in the proper spot");
            Assert.AreEqual("}", result[2], "end of block not right");
        }
Beispiel #5
0
        public void TestExprWithStatement()
        {
            var val       = new Variables.ValSimple("1 == 1", typeof(bool));
            var statement = new StatementFilter(val);

            statement.Add(new StatementSimpleStatement("dude"));

            var result = statement.CodeItUp().ToArray();

            Assert.AreEqual(4, result.Length, "no statements, so wasn't expecting any sort of output at all");
            Assert.AreEqual("if (1 == 1)", result[0], "if statement isn't correct");
            Assert.AreEqual("{", result[1], "open bracket");
            Assert.AreEqual("  dude;", result[2], "statement isn't in the proper spot");
            Assert.AreEqual("}", result[3], "end of block not right");
        }