public void DetectsNonBoolConditions()
        {
            ITypeCheckExpr expr = tcFactory.IfElse(tcFactory.Int(5), tcFactory.String("True"), tcFactory.String("False"));

            ErrorManager errMngr = new ErrorManager();
            expr.TypeCheck(new TypeEnvironment(errMngr));

            Assert.True(errMngr.HasErrors);
        }
        public void DetectsIncompatibleOperandsInOperation()
        {
            ITypeCheckExpr expr = tcFactory.Add(tcFactory.Bool(true), tcFactory.Int(100));

            ErrorManager errMngr = new ErrorManager();
            expr.TypeCheck(new TypeEnvironment(errMngr));

            Assert.True(errMngr.HasErrors);
        }
        public void DetectsAssignmentOfInvalidType()
        {
            string varName = "someVar";

            ITypeCheckStmnt stmnt = tcFactory.Label("Test",
                tcFactory.VarAssign(varName, tcFactory.RealType(), tcFactory.Bool(true))
            );

            ErrorManager errMngr = new ErrorManager();
            TypeEnvironment te = new TypeEnvironment(errMngr);
            stmnt.TypeCheck(te);

            Assert.True(te.IsDeclared(varName));
            Assert.True(errMngr.HasErrors);
        }
        private void OnCompletion(object root)
        {
            ErrorManager errMngr = new ErrorManager();
            errMngr.ErrorReported += (msg, sPos, ePos) => PrintMsg(sPos, ePos, msg, Colors.Red);
            errMngr.WarningReported += (msg, sPos, ePos) => PrintMsg(sPos, ePos, msg, Colors.Yellow);

            IPair<IPair<ITypeCheckStmnt, IPrintStmnt>, IFormStmnt> combItem = (IPair<IPair<ITypeCheckStmnt, IPrintStmnt>, IFormStmnt>)root;
            combItem.Item1.Item1.TypeCheck(new TypeEnvironment(errMngr));

            if (!errMngr.HasErrors)
            {
                printOutputTextBox.Document = new FlowDocument(combItem.Item1.Item2.BuildDocument(0));
                questionaireContainer.Content = combItem.Item2.BuildForm(new Algebra.QL.Extensions.Eval.Environment.ValueEnvironment(),
                    new Algebra.QL.Extensions.Form.Environment.TypeEnvironment());
                tabControl.SelectedIndex = 1;
            }
        }
        public void CyclicDependencyNotPossible()
        {
            string varName1 = "var1";
            string varName2 = "var2";
            ITypeCheckType type1 = tcFactory.RealType();
            ITypeCheckType type2 = tcFactory.BoolType();

            ITypeCheckStmnt stmnt = tcFactory.Statements(
                tcFactory.Label("Test", tcFactory.VarAssign(varName1, type1, tcFactory.Variable(varName2))),
                tcFactory.Label("Test", tcFactory.VarAssign(varName2, type2, tcFactory.Variable(varName1)))
            );

            ErrorManager errMngr = new ErrorManager();
            TypeEnvironment te = new TypeEnvironment(errMngr);
            stmnt.TypeCheck(te);

            Assert.True(te.IsDeclared(varName1));
            Assert.True(te.IsDeclared(varName2));
            Assert.True(errMngr.HasErrors);
        }
        public void DetectsRedefinedQuestions()
        {
            string varName = "someVar";
            ITypeCheckType type1 = tcFactory.RealType();
            ITypeCheckType type2 = tcFactory.BoolType();

            ITypeCheckStmnt stmnt = tcFactory.Statements(
                tcFactory.Question("Test", tcFactory.VarDecl(varName, type1)),
                tcFactory.Question("Test", tcFactory.VarDecl(varName, type2))
            );

            ErrorManager errMngr = new ErrorManager();
            TypeEnvironment te = new TypeEnvironment(errMngr);
            stmnt.TypeCheck(te);

            Assert.True(te.IsDeclared(varName));
            Assert.True(errMngr.HasErrors);
        }
        public void DuplicateLabelsWarning()
        {
            string varName = "someVar";
            ITypeCheckType varType = tcFactory.IntType();

            ITypeCheckStmnt stmnt = tcFactory.Statements(
                tcFactory.Question("Test", tcFactory.VarDecl(varName, varType)),
                tcFactory.Question("Test", tcFactory.VarDecl(varName, varType))
            );

            ErrorManager errMngr = new ErrorManager();
            TypeEnvironment te = new TypeEnvironment(errMngr);
            stmnt.TypeCheck(te);

            Assert.True(te.IsDeclared(varName));
            Assert.True(errMngr.HasWarnings);
            Assert.False(errMngr.HasErrors);
        }
        public void DetectsUndefinedQuestionUse()
        {
            string varName = "someVar";
            ITypeCheckStmnt stmnt = tcFactory.Label("Test", tcFactory.Variable(varName));

            ErrorManager errMngr = new ErrorManager();
            TypeEnvironment te = new TypeEnvironment(errMngr);
            stmnt.TypeCheck(te);

            Assert.False(te.IsDeclared(varName));
            Assert.True(errMngr.HasErrors);
        }