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); } }
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); }
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); }
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); }
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); }
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; }
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; }
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); }