public void SectionNameTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyle); Assert.AreEqual("SectionOne", qls.Children[0].Children[0].ID); Assert.AreEqual(QLSNodeType.Section, qls.Children[0].Children[0].NodeType); }
private void VisitChildren(QLSNode node) { foreach (var child in node.Children) { child.Accept(this); } }
public void StylesAtPageLevelTest() { QLSNode node = QLSParserHelper.Parse(PageStylesDefaultsRaw); Assert.AreEqual(1, node.Children.Count); Assert.AreEqual(2, node.Children[0].NodeStyles[0].StylingValues.Count); }
public void QuestionIdentifierTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyle); Assert.AreEqual("hasSoldHouse", qls.Children[0].Children[0].Children[0].ID); Assert.AreEqual(QLSNodeType.Question, qls.Children[0].Children[0].Children[0].NodeType); }
static void Main(string[] args) { Console.WriteLine("---- Start parsing the QL ----"); FormNode ql = QLParserHelper.Parse(Util.FileToString(QLFile)); QLPrinter.Print(ql); Console.WriteLine(); Console.WriteLine("---- Start parsing QLS ----"); QLSNode qls = QLSParserHelper.Parse(Util.FileToString(QLSFile)); QLSPrinter.Print(qls); Analyser.Analyse(ql, qls); var errors = Analyser.GetErrors(); Console.WriteLine("\n\n---- Errors and/or warnings: {0} ----", errors.Count); foreach (string error in errors) { Console.WriteLine(error); } Console.ReadLine(); }
public void StylesheetNameTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyle); Assert.AreEqual("TestForm", qls.ID); Assert.AreEqual(QLSNodeType.Stylesheet, qls.NodeType); }
public void PageNameTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyle); Assert.AreEqual("FirstPage", qls.Children[0].ID); Assert.AreEqual(QLSNodeType.Page, qls.Children[0].NodeType); }
public void MultipleDefaultStylesTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyleWithMultipleDefaults); var styles = qls.Children[0].Children[0].NodeStyles; Assert.AreEqual(2, styles.Count); }
public void StyleInSectionTest() { QLSNode node = QLSParserHelper.Parse(SectionDefaultsRaw); Assert.AreEqual(1, node.Children.Count); Assert.AreEqual(1, node.Children[0].Children.Count); Assert.AreEqual(2, node.Children[0].Children[0].NodeStyles[0].StylingValues.Count); }
public void MultipleStylesAtStylesheetLevelTest() { QLSNode node = QLSParserHelper.Parse(StyleSheetMultipleDefaultsRaw); Assert.AreEqual(1, node.Children.Count); Assert.AreEqual(2, node.NodeStyles[0].StylingValues.Count); Assert.AreEqual(3, node.NodeStyles[1].StylingValues.Count); }
public void SimpleWithoutDuplicateQLSTest() { QLSNode node = QLSParserHelper.Parse(simpleWithoutDuplicateQLS); var analyser = new DuplicateIdentifiersAnalyser(); var result = analyser.Analyse(node); Assert.IsTrue(result); }
public void NoIdentifiersAreUsed() { SymbolTable.Add("soldHouseIn2010", QValueType.Boolean); QLSNode node = QLSParserHelper.Parse(simpleWithouIdentifiersQLS); var analyser = new AllIdentifiersAreUsedAnalyser(); var result = analyser.Analyse(node); Assert.IsFalse(result); }
public void UnknownIdentifierWithTypoTests() { SymbolTable.Add("soldHouseIn2010", QValueType.Boolean); QLSNode node = QLSParserHelper.Parse(simpleWithTypoInQLS); var analyser = new UnknownIdentifiersAnalyser(); var isValid = analyser.Analyse(node); Assert.IsFalse(isValid); }
public void WidgetStyleTextfieldTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyleWithWidgetTypeTextfield); var questionNode = qls.Children[0].Children[0].Children[0]; Assert.AreEqual(WidgetType.Textfield, questionNode.NodeStyles[0].WidgetSpecification.WidgetType); Assert.AreEqual(0, questionNode.NodeStyles[0].WidgetSpecification.WidgetTypeArguments.Count); }
/// <summary> /// Adds QLS to a form /// </summary> /// <param name="formManager">Target form</param> /// <param name="qLSNode">Styling for the form</param> /// <param name="controller">Controller for object creation</param> /// <returns>Styled form</returns> public static FormManager ApplyQLS(FormManager formManager, QLSNode qLSNode, ElementManagerController controller, ref List <string> errors) { if (formManager.Identifier != qLSNode.ID) { errors.Add("Identifiers of ql and qls do not match!"); return(formManager); } List <ElementManagerLeaf> children = formManager.Children.Select(o => (ElementManagerLeaf)o).ToList(); return(ReconstructElementCollection(formManager, ref children, qLSNode, controller) as FormManager); }
private static ElementManagerCollection AddQLSToCollection(QLSNode qlsNode, ElementManagerCollection parent, ElementManagerController controller) { switch (qlsNode.NodeType) { case QLSNodeType.Page: return(new PageManager(qlsNode.ID, qlsNode.ID, parent, controller)); case QLSNodeType.Section: return(new SectionManager(qlsNode.ID, qlsNode.ID, parent, controller)); } throw new NotImplementedException(); }
public void WidgetStyleArgumentsTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyleWithWidgetTypeWithArguments); var questionNode = qls.Children[0].Children[0].Children[0]; Assert.AreEqual(WidgetType.Radio, questionNode.NodeStyles[0].WidgetSpecification.WidgetType); Assert.AreEqual(3, questionNode.NodeStyles[0].WidgetSpecification.WidgetTypeArguments.Count); Assert.AreEqual("Yes", questionNode.NodeStyles[0].WidgetSpecification.WidgetTypeArguments[0]); Assert.AreEqual("No", questionNode.NodeStyles[0].WidgetSpecification.WidgetTypeArguments[1]); Assert.AreEqual("Maybe", questionNode.NodeStyles[0].WidgetSpecification.WidgetTypeArguments[2]); }
public void DefaultStylesTest() { QLSNode qls = QLSParserHelper.Parse(SimpleStyleWithDefaults); var styles = qls.Children[0].Children[0].NodeStyles; Assert.AreEqual("width", styles[0].StylingValues[0].StyleProperty); Assert.AreEqual(QValueType.Integer, styles[0].StylingValues[0].QValueType); Assert.AreEqual("100", styles[0].StylingValues[0].StyleValue); Assert.AreEqual("fontSize", styles[0].StylingValues[1].StyleProperty); Assert.AreEqual(QValueType.Double, styles[0].StylingValues[1].QValueType); Assert.AreEqual("12.5", styles[0].StylingValues[1].StyleValue); }
private static ElementManagerLeaf AddQLSToLeaf(QLSNode node, ElementManagerLeaf leaf) { QLSStyle style = new QLSStyle(QValueType.Unknown, new QLSWidgetSpecification(WidgetType.Default, new List <string>())); if (node.NodeStyles.Count > 1) { throw new InvalidOperationException("Multiple styles in leaf node"); } else if (node.NodeStyles.Count == 1) { style = node.NodeStyles[0]; } leaf.SetStyle(style); return(leaf); }
private FormManager QLQLS(string rawQl, string rawQls, ElementManagerController elementManagerController, ref List <string> errors) { FormNode formNode = QLParserHelper.Parse(rawQl); QLSNode qlsNode = QLSParserHelper.Parse(rawQls); if (!Analyser.Analyse(formNode, qlsNode)) { errors.AddRange(Analyser.GetErrors()); return(null); } FormManager result = ElementManagerFactory.CreateForm(formNode, elementManagerController); result = ElementManagerFactory.ApplyQLS(result, qlsNode, elementManagerController, ref errors); return(result); }
public static bool Analyse(QLNode qlNode, QLSNode qlsNode) { Reset(); if (qlNode == null || qlsNode == null) { return(false); } // Analyse QL and QLS. var result = true; result = Analyse(qlNode) && result; result = Analyse(qlsNode) && result; return(result); }
public bool Analyse(QLSNode node) { this._visitedNodes.Clear(); this.Visit(node); var isValid = true; foreach (var visitedNode in _visitedNodes) { if (!SymbolTable.Instance.TypeMap.Keys.Contains(visitedNode.ID)) { Analyser.AddMessage(string.Format("{0} Unknown identifier in QLS: {1}", visitedNode.Location, visitedNode.ID), Language.QLS, MessageType.ERROR); isValid = false; } } return(isValid); }
public bool Analyse(QLSNode node) { var isValid = true; this._visitedNodes.Clear(); this.Visit(node); foreach (var key in SymbolTable.Instance.TypeMap.Keys) { if (!this._visitedNodes.Select(x => x.ID).Contains(key)) { Analyser.AddMessage(string.Format("Identifier has not been included in QLS: {0}", key), Language.QLS, MessageType.WARNING); isValid = false; } } return(isValid); }
private static bool Analyse(QLSNode node) { if (node == null) { return(false); } var result = true; foreach (IQLSAnalyser analyser in Instance._qlsAnalysers) { if (!analyser.Analyse(node) && result) { result = false; } } return(result); }
public bool Analyse(QLSNode node) { this._visitedNodes.Clear(); this.Visit(node); var isValid = true; foreach (var visitedNode in this._visitedNodes) { var idCount = this._visitedNodes.Count(x => x.ID == visitedNode.ID); if (idCount > 1) { isValid = false; Analyser.AddMessage(string.Format("{0} Duplicate key in QLS: {1}", visitedNode.Location, visitedNode.ID), Language.QLS, MessageType.WARNING); } } return(isValid); }
/// <summary> /// Creates the elementManager style as provided by the QLS node by inserting /// the manager objects provided by the QLS and insterts the given children into /// the tree on the positions defined in the QLS /// </summary> /// <param name="collection">Collection element to be reconstructed</param> /// <param name="children">Children that can occur as a child of the collection element</param> /// <param name="qlsChildren">Children of the QLS node that mached the collection node</param> /// <param name="controller">ElementManagerController for element creation</param> /// <returns>Element manager collection that contains all QLS defined children</returns> private static ElementManagerCollection ReconstructElementCollection(ElementManagerCollection collection, ref List <ElementManagerLeaf> children, QLSNode qlsNode, ElementManagerController controller) { collection.Children.Clear(); foreach (QLSNode node in qlsNode.Children) { switch (node.NodeType) { case QLSNodeType.Page: case QLSNodeType.Section: ElementManagerCollection collectionChild = AddQLSToCollection(node, collection, controller); collectionChild = ReconstructElementCollection(collectionChild, ref children, node, controller); collection.AddChild(collectionChild); break; case QLSNodeType.Question: IEnumerable <ElementManagerLeaf> foundMatches = children.Where(o => o.Identifier == node.ID).Select(o => o as ElementManagerLeaf); if (foundMatches.Count() != 1) { throw new InvalidOperationException(string.Format("Identifier: {0}, used in QLS, was found {1} times in QL!", node.ID, foundMatches.Count())); } ElementManagerLeaf child = foundMatches.First(); children.Remove(child); collection.AddChild(AddQLSToLeaf(node, child)); break; } } collection.AddStyle(qlsNode.NodeStyles.ToArray()); return(collection); }
public static void Print(QLSNode node) { Console.WriteLine(node.ToString()); }
public void Visit(QLSNode node) { VisitChildren(node); }