protected QuestionDeclarationChecker(IEnumerable<string> declaredQuestions, ValidationReport report)
     : this()
 {
     // Call ToList so we get our own instance of the list.
     _declaredQuestions = declaredQuestions.ToList();
     Report = report;
 }
        internal override void Validate(StyleSheet styleSheet, ValidationReport report)
        {
            base.Validate(styleSheet, report);

            foreach (var unrefferedQuestion in _unrefferedQuestions)
            {
                Report.AddError(TextPosition.None, "The QL question '{0}' is not referred in the QLS.", unrefferedQuestion);
            }
        }
예제 #3
0
        public void TestStringConcationation()
        {
            // Arrange
            var controller = new QLController();
            var form = controller.ParseQLString("name = \"What's your name?\" string = \"Piet\" + \"Jansen\"");
            var typeChecker = new TypeChecker();
            var report = new ValidationReport();

            // Act
            typeChecker.Validate(form, report);

            // Assert
            Assert.AreEqual<int>(0, report.NrOfErrors);
        }
예제 #4
0
        public void TestInvalidInteger()
        {
            // Arrange
            var ql = new StringBuilder();
            ql.AppendLine("int someInt = 8374398748349837489274"); // An integer value that well surpasses the 32-bit range.

            var controller = new QLController();
            var form = controller.ParseQLString(ql.ToString());

            var checker = new LiteralChecker();
            var report = new ValidationReport();

            // Act
            checker.Validate(form, report);

            // Assert
            Assert.AreEqual<int>(1, report.NrOfErrors);
        }
예제 #5
0
        public void TestNegatedIfStatement()
        {
            // Arrange
            var ql = new StringBuilder();
            ql.AppendLine("isHappy \"Are you happy?\" bool");
            ql.AppendLine("if(!isHappy)");
            ql.AppendLine("{ }");

            var controller = new QLController();
            var form = controller.ParseQLString(ql.ToString());
            var typeChecker = new TypeChecker();
            var report = new ValidationReport();

            // Act
            typeChecker.Validate(form, report);

            // Assert
            Assert.AreEqual<int>(0, report.NrOfErrors);
        }
예제 #6
0
        public void TestInvalidDates()
        {
            // Arrange
            var ql = new StringBuilder();
            ql.AppendLine("date someDateA = [1-31-2015]");
            ql.AppendLine("date someDateB = [30-02-2015]");

            var controller = new QLController();
            var form = controller.ParseQLString(ql.ToString());

            var checker = new LiteralChecker();
            var report = new ValidationReport();

            // Act
            checker.Validate(form, report);

            // Assert
            Assert.AreEqual<int>(2, report.NrOfErrors);
        }
예제 #7
0
        public ValidationReport Validate(StyleSheet styleSheet, QuestionForm form)
        {
            if (styleSheet == null) { throw new ArgumentNullException("styleSheet"); }
            if (form == null) { throw new ArgumentNullException("form"); }

            var validators = new List<ASTChecker>
            {
                new QuestionReferencingChecker(form.GetAllQuestions()),
                new StyleAttributeChecker(),
                new WidgetTypeChecker(form.GetAllQuestions())
            };

            var report = new ValidationReport();

            foreach (var validator in validators)
            {
                validator.Validate(styleSheet, report);
            }

            return report;
        }
예제 #8
0
        public ValidationReport Validate(QuestionForm form)
        {
            if (form == null) { throw new ArgumentNullException("form"); }

            var validators = new List<ASTChecker>
            {
                new DuplicateLabelChecker(),
                new QuestionDeclarationChecker(),
                new TypeChecker(),
                new LiteralChecker(),
            };

            var report = new ValidationReport();

            foreach (var validator in validators)
            {
                validator.Validate(form, report);
            }

            return report;
        }
예제 #9
0
        public void TestValidDates()
        {
            // Arrange
            var ql = new StringBuilder();
            ql.AppendLine("date someDateA = [31-1-2015]");
            ql.AppendLine("date someDateB = [01-01-2015]");
            ql.AppendLine("date someDateC = [5-06-1920]");
            ql.AppendLine("date someDateD = [today]");
            ql.AppendLine("date someDateE = [yesterday]");
            ql.AppendLine("date someDateF = [tomorrow]");

            var controller = new QLController();
            var form = controller.ParseQLString(ql.ToString());

            var checker = new LiteralChecker();
            var report = new ValidationReport();

            // Act
            checker.Validate(form, report);

            // Assert
            Assert.AreEqual<int>(0, report.NrOfErrors + report.NrOfWarnings);
        }