Example #1
0
        public void AssociatesElseCorrectly()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                                               new IfStmnt(
                                                   new LiteralExpr <bool>(true),
                                                   new IfElseStmnt(
                                                       new LiteralExpr <bool>(false),
                                                       new TextExprStmnt("\"Question 1:\"",
                                                                         new LiteralExpr <int>(7)
                                                                         ),
                                                       new TextExprStmnt("\"Question 2:\"",
                                                                         new LiteralExpr <int>(13)
                                                                         )
                                                       )
                                                   )
                                               );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse(new StringBuilder().AppendLine("form Form1 {")
                                        .AppendLine("if (true)")
                                        .AppendLine("if (false)")
                                        .AppendLine("\"Question 1:\" << 7;")
                                        .AppendLine("else")
                                        .AppendLine("\"Question 2:\" << 13;")
                                        .AppendLine("}").ToString());

            Assert.True(parseOk);
        }
Example #2
0
        public void CompStmntFlattened()
        {
            QLParser<IExprNode, IStmntNode> parser = InitParser();

            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new CompStmnt(
                        new QuestionStmnt("\"Question 1:\"", false,
                            new LiteralExprNode(new IntValue(5))
                        ),
                        new QuestionStmnt("\"Question 1:\"", false,
                            new LiteralExprNode(new IntValue(5))
                        ),
                        new QuestionStmnt("\"Question 1:\"", false,
                            new LiteralExprNode(new IntValue(5))
                        ),
                        new QuestionStmnt("\"Question 1:\"", false,
                            new LiteralExprNode(new IntValue(5))
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 5; \"Question 1:\" << 5; \"Question 1:\" << 5; \"Question 1:\" << 5; }");
            Assert.True(parseOk);
        }
Example #3
0
        public void MultiplicationPrecedence()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                                               new TextExprStmnt("\"Question 1:\"",
                                                                 new BinaryExpr(
                                                                     new BinaryExpr(
                                                                         new LiteralExpr <int>(2),
                                                                         new LiteralExpr <int>(5)
                                                                         ),
                                                                     new BinaryExpr(
                                                                         new LiteralExpr <int>(2),
                                                                         new LiteralExpr <int>(4)
                                                                         )
                                                                     )
                                                                 )
                                               );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 2 * 5 + 2 * 4; }");

            Assert.True(parseOk);
        }
        public void AssociatesElseCorrectly()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new IfStmnt(
                        new LiteralExpr<bool>(true),
                        new IfElseStmnt(
                            new LiteralExpr<bool>(false),
                            new TextExprStmnt("\"Question 1:\"",
                                new LiteralExpr<int>(7)
                            ),
                            new TextExprStmnt("\"Question 2:\"",
                                new LiteralExpr<int>(13)
                            )
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse(new StringBuilder().AppendLine("form Form1 {")
                .AppendLine("if (true)")
                .AppendLine("if (false)")
                .AppendLine("\"Question 1:\" << 7;")
                .AppendLine("else")
                .AppendLine("\"Question 2:\" << 13;")
                .AppendLine("}").ToString());

            Assert.True(parseOk);
        }
        public void InstantiatesDate()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new TextExprStmnt("\"Question 1:\"",
                        new LiteralExpr<DateTime>(DateTime.Parse("2014-02-20T22:00:00Z", CultureInfo.InvariantCulture))
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 2014-02-20T22:00:00Z; }");
            Assert.True(parseOk);
        }
Example #6
0
        public void InstantiatesDate()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                                               new TextExprStmnt("\"Question 1:\"",
                                                                 new LiteralExpr <DateTime>(DateTime.Parse("2014-02-20T22:00:00Z", CultureInfo.InvariantCulture))
                                                                 )
                                               );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 2014-02-20T22:00:00Z; }");

            Assert.True(parseOk);
        }
        public void InstantiatesDateType()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new TextExprStmnt("\"Question 1:\"",
                        new VarInitExpr("myDate",
                            new BaseType<DateTime>(),
                            new LiteralExpr<object>(0)
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" >> myDate:date; }");
            Assert.True(parseOk);
        }
Example #8
0
        public void InstantiatesDateType()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                                               new TextExprStmnt("\"Question 1:\"",
                                                                 new VarInitExpr("myDate",
                                                                                 new BaseType <DateTime>(),
                                                                                 new LiteralExpr <object>(0)
                                                                                 )
                                                                 )
                                               );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" >> myDate:date; }");

            Assert.True(parseOk);
        }
Example #9
0
        public void InstantiatesPower()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                                               new TextExprStmnt("\"Question 1:\"",
                                                                 new BinaryExpr(
                                                                     new LiteralExpr <int>(5),
                                                                     new LiteralExpr <int>(2)
                                                                     )
                                                                 )
                                               );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 5 ^ 2; }");

            Assert.True(parseOk);
        }
        public void AddAssociation()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new TextExprStmnt("\"Question 1:\"",
                        new BinaryExpr(
                            new BinaryExpr(
                                new LiteralExpr<int>(5),
                                new LiteralExpr<int>(2)
                            ),
                            new LiteralExpr<int>(4)
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 5 + 2 + 4; }");
            Assert.True(parseOk);
        }
Example #11
0
        public void CompStmntNestingRightHand()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                                               new CompStmnt(
                                                   new TextExprStmnt("\"Question 1:\"",
                                                                     new LiteralExpr <int>(5)
                                                                     ),
                                                   new CompStmnt(
                                                       new TextExprStmnt("\"Question 1:\"",
                                                                         new LiteralExpr <int>(5)
                                                                         ),
                                                       new CompStmnt(
                                                           new TextExprStmnt("\"Question 1:\"",
                                                                             new LiteralExpr <int>(5)
                                                                             ),
                                                           new TextExprStmnt("\"Question 1:\"",
                                                                             new LiteralExpr <int>(5)
                                                                             )
                                                           )
                                                       )
                                                   )
                                               );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse(new StringBuilder().AppendLine("form Form1 {")
                                        .AppendLine("\"Question 1:\" << 5;")
                                        .AppendLine("\"Question 1:\" << 5;")
                                        .AppendLine("\"Question 1:\" << 5;")
                                        .AppendLine("\"Question 1:\" << 5;")
                                        .AppendLine("}").ToString());

            Assert.True(parseOk);
        }
Example #12
0
        public void MultiplicationPrecedence()
        {
            QLParser<IExprNode, IStmntNode> parser = InitParser();

            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new QuestionStmnt("\"Question 1:\"", false,
                        new AddExpr(
                            new LiteralExprNode(new IntValue(5)),
                            new MultiplyExpr(
                                new LiteralExprNode(new IntValue(2)),
                                new LiteralExprNode(new IntValue(4))
                            )
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 5 + 2 * 4; }");
            Assert.True(parseOk);
        }
        public void CompStmntFlattened()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new CompStmnt(
                        new TextExprStmnt("\"Question 1:\"",
                            new LiteralExpr<int>(5)
                        ),
                        new CompStmnt(
                            new TextExprStmnt("\"Question 1:\"",
                                new LiteralExpr<int>(5)
                            ),
                            new CompStmnt(
                                new TextExprStmnt("\"Question 1:\"",
                                    new LiteralExpr<int>(5)
                                ),
                                new TextExprStmnt("\"Question 1:\"",
                                    new LiteralExpr<int>(5)
                                )
                            )
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse(new StringBuilder().AppendLine("form Form1 {")
                .AppendLine("\"Question 1:\" << 5;")
                .AppendLine("\"Question 1:\" << 5;")
                .AppendLine("\"Question 1:\" << 5;")
                .AppendLine("\"Question 1:\" << 5;")
                .AppendLine("}").ToString());

            Assert.True(parseOk);
        }
        public void MultiplicationPrecedence()
        {
            parser.OnCompletion += (root) =>
            {
                FormStmnt tree = new FormStmnt("Form1",
                    new TextExprStmnt("\"Question 1:\"",
                        new BinaryExpr(
                            new BinaryExpr(
                                new LiteralExpr<int>(2),
                                new LiteralExpr<int>(5)
                            ),
                            new BinaryExpr(
                                new LiteralExpr<int>(2),
                                new LiteralExpr<int>(4)
                            )
                        )
                    )
                );
                Assert.NotNull(root);
                Assert.Equal(root, tree);
            };

            bool parseOk = parser.Parse("form Form1 { \"Question 1:\" << 2 * 5 + 2 * 4; }");
            Assert.True(parseOk);
        }