Beispiel #1
0
        public void CorrectColumnsUsageWithRowClassOnTheParentParent()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div>
                               <div class='col-md-8'>               
                                 <b>Title 1</b>
                               </div>
                               <div class='col-md-4'>               
                                 <b>Title 2</b>
                               </div>
                             </div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
Beispiel #2
0
        public void ErrorMsgIfMoreThanTwelveColumns()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div class='col-md-10'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-3'>               
                                <b>Title 2</b>
                            </div>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("must not exceed 12"));
            Assert.IsTrue(compiled[0].Message.Contains("col-md-*"));
        }
Beispiel #3
0
    private MarkdownPage ParsePage(string fileName)
    {
        string html = CommonMark.CommonMarkConverter.Convert(File.ReadAllText(fileName));

        HtmlTree tree = new HtmlTree(new TextStream(html));

        tree.Build();

        ElementNode firstChild = tree.RootNode.Children[0];
        ElementNode prop       = firstChild.Children[0];

        MarkdownPage page = new MarkdownPage();

        page.Title        = AttrValue(prop, "pageTitle", Path.GetFileNameWithoutExtension(fileName));
        page.Description  = AttrValue(prop, "description", page.Title);
        page.Content      = html.Substring(firstChild.End, tree.RootNode.Length - firstChild.End).Trim();
        page.Keywords     = AttrValue(prop, "keywords", page.Title);
        page.Slug         = AttrValue(prop, "slug", page.Title.ToLowerInvariant());
        page.DateModified = File.GetLastWriteTime(fileName);
        page.FileName     = fileName.Replace(BaseDirectory, string.Empty).Replace("\\", "/");
        page.ShowInMenu   = Path.GetFileName(fileName).StartsWith("_") ? false : true;

        if (prop.GetAttribute("order") != null)
        {
            page.Order = int.Parse(prop.GetAttribute("order").Value);
        }
        else
        {
            page.Order = 1000 + page.Title[0];
        }

        return(page);
    }
        public void CorrectColumnsUsageWithRowClassOnTheParentParent()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div>
                               <div class='col-md-8'>               
                                 <b>Title 1</b>
                               </div>
                               <div class='col-md-4'>               
                                 <b>Title 2</b>
                               </div>
                             </div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
Beispiel #5
0
        public void WarnIfParentsElementIsMissingRowClass()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<html>
                            <body>
                            <div class='someClass'>
                             <div class='col-md-8'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-4'>               
                                <b>Title 2</b>
                            </div>
                        </div>
                        </body>
                        </html>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0].Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("col-md-8"));
        }
Beispiel #6
0
        private HtmlTree ParseHtml(string html)
        {
            HtmlParser parser = new HtmlParser();
            HtmlTree   tree   = new HtmlTree(new TextStream(html));

            tree.Build();
            return(tree);
        }
Beispiel #7
0
        public static void VerifyTree(EditorTree editorTree)
        {
#if ___DEBUG
            if (editorTree.TextBuffer != null)
            {
                var fullParseTree = new HtmlTree(new TextProvider(editorTree.TextSnapshot));
                fullParseTree.Build(rebuildCollection);

                CompareTrees(editorTree, fullParseTree);
            }
#endif
        }
Beispiel #8
0
        public static void VerifyTree(EditorTree editorTree)
        {
#if ___DEBUG
            if (editorTree.TextBuffer != null)
            {
                var fullParseTree = new HtmlTree(new TextProvider(editorTree.TextSnapshot));
                fullParseTree.Build(rebuildCollection);

                CompareTrees(editorTree, fullParseTree);
            }
#endif
        }
Beispiel #9
0
        internal IReadOnlyList <INamedItemInfo> LoadFunctionInfoFromPackageHelpIndex()
        {
            List <INamedItemInfo> functions = new List <INamedItemInfo>();
            string content = null;

            try {
                string htmlFile = Path.Combine(this.InstallPath, this.Name, "html", "00index.html");
                if (File.Exists(htmlFile))
                {
                    using (StreamReader sr = new StreamReader(htmlFile, Encoding.UTF8)) {
                        content = sr.ReadToEnd();
                    }
                }
            } catch (IOException) { }

            if (!string.IsNullOrEmpty(content))
            {
                HtmlTree tree = new HtmlTree(new TextStream(content));
                tree.Build();

                FunctionSearch functionSearch = new FunctionSearch(functions);
                tree.Accept(functionSearch, null);
            }

            Dictionary <string, INamedItemInfo> functionIndex = new Dictionary <string, INamedItemInfo>();

            foreach (INamedItemInfo ni in functions)
            {
                functionIndex[ni.Name] = ni;
            }

            IReadOnlyDictionary <string, string> mappedNames = GetMappedNames();

            foreach (string mappedName in mappedNames.Keys)
            {
                INamedItemInfo ni;
                string         actualName = mappedNames[mappedName];
                if (functionIndex.TryGetValue(actualName, out ni))
                {
                    INamedItemInfo niAlias = new NamedItemInfo()
                    {
                        Name        = mappedName,
                        Description = ni.Description,
                        ItemType    = ni.ItemType
                    };
                    functions.Add(niAlias);
                }
            }

            return(functions);
        }
Beispiel #10
0
        private void VerifyPositions(string html, HtmlPositionType[] positionTypes)
        {
            var tree = new HtmlTree(new TextStream(html), null, null, ParsingMode.Html);

            tree.Build();

            for (int i = 0; i < html.Length; i++)
            {
                ElementNode   element;
                AttributeNode attribute;

                var pos = tree.RootNode.GetPositionElement(i, out element, out attribute);
                Assert.Equal(positionTypes[i], pos);
            }
        }
            public void FoundationClassValidatorDoNothingIfClassAttributContainsNothingAboutColumns()
            {
                FoundationClassValidator validator = new FoundationClassValidator();

                var source = @"<div class='somethingElse'>2 columns</div>";

                var tree = new HtmlTree(new TextStream(source));

                tree.Build();

                IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

                int expected = 0;

                Assert.AreEqual(expected, compiled.Count);
            }
            public void ValidColumnDeclaration()
            {
                FoundationClassValidator validator = new FoundationClassValidator();

                var source = @"<div class='small-2 columns'>2 columns</div>";

                var tree = new HtmlTree(new TextStream(source));

                tree.Build();

                IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

                int expected = 0;

                Assert.AreEqual(expected, compiled.Count);
            }
            public void ValidColumnDeclaration()
            {
                FoundationClassValidator validator = new FoundationClassValidator();

                var source = @"<div class='small-2 columns'>2 columns</div>";

                var tree = new HtmlTree(new TextStream(source));

                tree.Build();

                IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

                int expected = 0;

                Assert.AreEqual(expected, compiled.Count);
            }
        public void NoWarningIfNoParentForColumns()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='medium-2 columns'>2 columns</div>
                           <div class='medium-10 columns'>10 columns</div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void OkToHaveLessThan12ColumnsIfCenteredClassPresentEvenOnAnotherSize()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                               <div class='small-6 large-centered columns'>6 centered</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
Beispiel #16
0
        public void MinimalistCorrectColumnUsage()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='columns'>12 columns</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
Beispiel #17
0
        public void BootStrapClassValidatorDoNothingIfClassAttributIsMissing()
        {
            BootstrapClassValidator validator = new BootstrapClassValidator();

            var source = @"<a id='someHyperlink' href='#'>
                        Link text
                        </a>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void NoColumnsNoWarnings()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='someClass'>
                            <i class='someOtherClass'></i>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void MinimalistCorrectColumnUsage()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='columns'>12 columns</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void NoColumnsNoWarnings()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='someClass'>
                            <i class='someOtherClass'></i>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void BootStrapClassValidatorDoNothingIfClassAttributIsMissing()
        {
            BootstrapClassValidator validator = new BootstrapClassValidator();

            var source = @"<a id='someHyperlink' href='#'>
                        Link text
                        </a>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void BootstrapNestedFontAwesomeTest()
        {
            BootstrapClassValidator validator = new BootstrapClassValidator();

            var source = @"<span class='fa-stack fa-lg'>
                            <i class='fa-circle fa-stack-2x fa'></i>
                            <i class='fa fa-twitter fa-stack-1x fa-inverse'></i>
                        </span>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
            public void MissingColumnClass()
            {
                FoundationClassValidator validator = new FoundationClassValidator();

                var source = @"<div class='small-2'>2 columns</div>";

                var tree = new HtmlTree(new TextStream(source));

                tree.Build();

                IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

                int    expected            = 1;
                string expectedMessagePart = "When using \"small-#\"";

                Assert.AreEqual(expected, compiled.Count);
                Assert.IsTrue(compiled[0].Message.Contains(expectedMessagePart));
                System.Console.WriteLine(compiled[0].Message);
            }
        public void CorrectComplexColumnsUsage()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                             <div class='small-8 medium-8 large-6 columns'>8-8-6</div>
                             <div class='small-4 medium-4 large-6 columns'>4-4-6</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
Beispiel #25
0
        public void BootstrapNestedFontAwesomeTest()
        {
            BootstrapClassValidator validator = new BootstrapClassValidator();

            var source = @"<span class='fa-stack fa-lg'>
                            <i class='fa-circle fa-stack-2x fa'></i>
                            <i class='fa fa-twitter fa-stack-1x fa-inverse'></i>
                        </span>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void CorrectComplexColumnsUsage()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                             <div class='small-8 medium-8 large-6 columns'>8-8-6</div>
                             <div class='small-4 medium-4 large-6 columns'>4-4-6</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
Beispiel #27
0
        public void AttributeParsing_IncompleteTyping1()
        {
            var text = "<div lang=dir=ltr>";
            var tree = new HtmlTree(new TextStream(text));

            tree.Build();

            var div = tree.RootNode.Children[0];

            Assert.Equal(2, div.Attributes.Count);

            Assert.Equal("lang", div.Attributes[0].Name);
            Assert.False(div.Attributes[0].HasValue());

            Assert.Equal("dir", div.Attributes[1].Name);
            Assert.True(div.Attributes[1].HasValue());

            Assert.Equal("ltr", div.Attributes[1].Value);
        }
        public void BootstrapBtnPrimaryClassRequireBtnClassToo()
        {
            BootstrapClassValidator validator = new BootstrapClassValidator();

            var source = @"<a class='btn-primary'>
                        Link text
                        </a>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 1;
            string expectedMessage = "When using \"btn-primary\", you must also specify the class \"btn\".";

            Assert.AreEqual(expected, compiled.Count);
            Assert.AreEqual(expectedMessage, compiled[0].Message);
        }
Beispiel #29
0
        public void AttributeParsing_IncompleteTyping3()
        {
            var text = "<div lang=\"dir=\"ltr\">";
            var tree = new HtmlTree(new TextStream(text));

            tree.Build();

            var div = tree.RootNode.Children[0];

            Assert.Equal(2, div.Attributes.Count);

            Assert.Equal("lang", div.Attributes[0].Name);
            Assert.True(div.Attributes[0].HasValue());
            Assert.Equal(6, div.Attributes[0].ValueToken.Length);
            Assert.Equal('\"', div.Attributes[0].ValueToken.OpenQuote);
            Assert.Equal('\"', div.Attributes[0].ValueToken.CloseQuote);

            Assert.Equal("ltr\"", div.Attributes[1].Name);
            Assert.False(div.Attributes[1].HasValue());
        }
Beispiel #30
0
        /// <summary>
        /// Downloads the index html page specified, and extracts a set of known fields from it.
        /// </summary>
        /// <param name="packageUri">Location of index.html page.</param>
        /// <param name="result">RPackage object to fill in. A new one is created if none is passed in.</param>
        /// <returns>RPackage object populated with the information found in the html page.</returns>
        /// <exception cref="WebException">Page cannot be loaded.</exception>
        /// <remarks>
        /// If an existing RPackage object is passed in, the fields that are already filled in
        /// won't be overwritten by the ones extracted from the html page.
        /// </remarks>
        public static async Task <RPackage> RetrievePackageInfo(Uri packageUri, RPackage result = null)
        {
            string content;

            using (var webClient = new WebClient()) {
                content = await webClient.DownloadStringTaskAsync(packageUri);
            }

            var pkg = result ?? new RPackage();

            var tree = new HtmlTree(new Microsoft.Web.Core.Text.TextStream(content));

            tree.Build();

            var search = new IndexVisitor(pkg);

            tree.Accept(search, null);

            return(pkg);
        }
        public void TwoRowsOnMobileDesign_InvalidExampleWithMoreThan12ColumnsBecauseNotMultipleOfTwelve()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='small-6 large-2 columns'>...</div>
                              <div class='small-6 large-8 columns'>...</div>
                              <div class='small-8 large-2 columns'>...</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void InvalidComplexColumnsUsage_MissingOneLargeDefinition()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                             <div class='small-8 medium-8 large-10 columns'>8-8-6</div>
                             <div class='small-4 medium-4 columns'>4-4-6</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Console.WriteLine(compiled[0].Message);
        }
Beispiel #33
0
        public void BootstrapBtnPrimaryClassRequireBtnClassToo()
        {
            BootstrapClassValidator validator = new BootstrapClassValidator();

            var source = @"<a class='btn-primary'>
                        Link text
                        </a>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int    expected        = 1;
            string expectedMessage = "When using \"btn-primary\", you must also specify the class \"btn\".";

            Assert.AreEqual(expected, compiled.Count);
            Assert.AreEqual(expectedMessage, compiled[0].Message);
        }
        public void UnderTwelveIsOKIfEndClassIsThereAtLastColumn()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns end'>3 columns - End</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void ErrorMsgIfMoreThanTwelveColumns()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='medium-8 columns'>8 columns</div>
                              <div class='medium-6 columns'>6 columns</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("more than 12 columns"));
            Assert.IsTrue(compiled[0].Message.Contains("medium-"));
        }
Beispiel #36
0
        public void MustWorkForNonDivElementsToo()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='form-group row'>
                              <label for='commentcontent' class='control-label col-sm-2'>Comment (no HTML allowed)</label>
                              <div class='col-sm-10'>
                                 <textarea id='commentcontent' class='form-control' rows='4' placeholder='Comment' required></textarea>
                              </div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void ErrorIfUnderTwelveWithoutEndClass()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns'>3 columns - End</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("the last column need the 'end' class element"));
        }
Beispiel #38
0
        static public void BuildTree(HtmlTestFilesFixture fixture, string name)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".tree";
            string text         = fixture.LoadDestinationFile(name);

            var tree = new HtmlTree(new TextStream(text), null, null, ParsingMode.Html);

            tree.Build();

            TreeWriter tw     = new TreeWriter();
            string     actual = tw.WriteTree(tree);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, name) + ".tree";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
        public void ErrorMsgIfMoreThanTwelveColumns()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='medium-8 columns'>8 columns</div>
                              <div class='medium-6 columns'>6 columns</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("more than 12 columns"));
            Assert.IsTrue(compiled[0].Message.Contains("medium-"));
        }
        public void ErrorMsgIfMoreThanTwelveColumns()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div class='col-md-10'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-3'>               
                                <b>Title 2</b>
                            </div>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("must not exceed 12"));
            Assert.IsTrue(compiled[0].Message.Contains("col-md-*"));
        }
        public void UnderTwelveIsOKIfEndClassIsThereAtLastColumn()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns end'>3 columns - End</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void NoWarningIfNoParentForColumns()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='medium-2 columns'>2 columns</div>
                           <div class='medium-10 columns'>10 columns</div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void TotalOfGridColumnsMustEqual12ForAllTypeOfColumns()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div class='col-md-8 col-sm-8'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-4 col-sm-6'>               
                                <b>Title 2</b>
                            </div>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("must equal 12"));
        }
        public void ErrorIfUnderTwelveWithoutEndClass()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns'>3 columns</div>
                              <div class='medium-3 columns'>3 columns - End</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("the last column need the 'end' class element"));
        }
        public void TotalOfGridColumnsMustEqual12AndHandleOffSetCorrectly()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div class='col-md-7'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-offset-1 col-md-4'>               
                                <b>Title 2</b>
                            </div>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
            public void MissingColumnClass()
            {
                FoundationClassValidator validator = new FoundationClassValidator();

                var source = @"<div class='small-2'>2 columns</div>";

                var tree = new HtmlTree(new TextStream(source));

                tree.Build();

                IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

                int expected = 1;
                string expectedMessagePart = "When using \"small-#\"";

                Assert.AreEqual(expected, compiled.Count);
                Assert.IsTrue(compiled[0].Message.Contains(expectedMessagePart));
                System.Console.WriteLine(compiled[0].Message);
            }
        public void TwoRowsOnMobileDesign_InvalidExampleWithMoreThan12ColumnsBecauseNotMultipleOfTwelve()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                              <div class='small-6 large-2 columns'>...</div>
                              <div class='small-6 large-8 columns'>...</div>
                              <div class='small-8 large-2 columns'>...</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void InvalidComplexColumnsUsage_MissingOneLargeDefinition()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                             <div class='small-8 medium-8 large-10 columns'>8-8-6</div>
                             <div class='small-4 medium-4 columns'>4-4-6</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Console.WriteLine(compiled[0].Message);
        }
            public void FoundationClassValidatorDoNothingIfClassAttributContainsNothingAboutColumns()
            {
                FoundationClassValidator validator = new FoundationClassValidator();

                var source = @"<div class='somethingElse'>2 columns</div>";

                var tree = new HtmlTree(new TextStream(source));

                tree.Build();

                IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]);

                int expected = 0;

                Assert.AreEqual(expected, compiled.Count);
            }
        public void MustWorkForNonDivElementsToo()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='form-group row'>
                              <label for='commentcontent' class='control-label col-sm-2'>Comment (no HTML allowed)</label>
                              <div class='col-sm-10'>
                                 <textarea id='commentcontent' class='form-control' rows='4' placeholder='Comment' required></textarea>
                              </div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void OkToHaveLessThan12ColumnsIfCenteredClassPresentEvenOnAnotherSize()
        {
            FoundationColumnsValidator validator = new FoundationColumnsValidator();

            var source = @"<div class='row'>
                               <div class='small-6 large-centered columns'>6 centered</div>
                           </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void PullAndPushMustBeIgnored()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='row'>
                             <div class='col-sm-6 col-md-9 col-md-push-3'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-3 col-md-pull-9 col-sm-6'>               
                                <b>Title 2</b>
                            </div>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 0;

            Assert.AreEqual(expected, compiled.Count);
        }
        public void WarnIfParentDivRowClassColumnIsMissing()
        {
            BootstrapColumnsValidator validator = new BootstrapColumnsValidator();

            var source = @"<div class='someClass'>
                             <div class='col-md-8'>               
                                <b>Title 1</b>
                            </div>
                             <div class='col-md-4'>               
                                <b>Title 2</b>
                            </div>
                        </div>";

            var tree = new HtmlTree(new TextStream(source));

            tree.Build();

            IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]);

            int expected = 1;

            Assert.AreEqual(expected, compiled.Count);
            Assert.IsTrue(compiled[0].Message.Contains("col-md-8"));
        }