Пример #1
0
        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);
        }
Пример #2
0
 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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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();
        }
Пример #6
0
        public void StylesheetNameTest()
        {
            QLSNode qls = QLSParserHelper.Parse(SimpleStyle);

            Assert.AreEqual("TestForm", qls.ID);
            Assert.AreEqual(QLSNodeType.Stylesheet, qls.NodeType);
        }
Пример #7
0
        public void PageNameTest()
        {
            QLSNode qls = QLSParserHelper.Parse(SimpleStyle);

            Assert.AreEqual("FirstPage", qls.Children[0].ID);
            Assert.AreEqual(QLSNodeType.Page, qls.Children[0].NodeType);
        }
Пример #8
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        public void SimpleWithoutDuplicateQLSTest()
        {
            QLSNode node     = QLSParserHelper.Parse(simpleWithoutDuplicateQLS);
            var     analyser = new DuplicateIdentifiersAnalyser();
            var     result   = analyser.Analyse(node);

            Assert.IsTrue(result);
        }
Пример #12
0
        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);
        }
Пример #14
0
        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();
        }
Пример #17
0
        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]);
        }
Пример #18
0
        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);
        }
Пример #20
0
        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);
        }
Пример #21
0
        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);
        }
Пример #22
0
        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);
        }
Пример #24
0
        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);
        }
Пример #25
0
        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);
        }
Пример #27
0
 public static void Print(QLSNode node)
 {
     Console.WriteLine(node.ToString());
 }
Пример #28
0
 public void Visit(QLSNode node)
 {
     VisitChildren(node);
 }