예제 #1
0
        private void ParseAttributes(string content, ref int pos)
        {
            if (pos >= content.Length)
            {
                return;
            }

            char attributeEndChar = HtmlStringHelper.GetAttributeTerminatingChar(content[pos]);

            if (attributeEndChar != '\0')
            {
                string attributes = HtmlStringHelper.ExtractTokenFromTagString(content, ref pos,
                                                                               new[] { attributeEndChar });
                if (attributes[attributes.Length - 1] != attributeEndChar)
                {
                    throw new HamlMalformedTagException(
                              "Malformed HTML Attributes collection \"" + attributes + "\".", SourceFileLineNum);
                }
                var attribCollection = new HamlNodeHtmlAttributeCollection(SourceFileLineNum, attributes);

                foreach (var attribute in attribCollection.Children.OfType <HamlNodeHtmlAttribute>().OrderBy(n => n.Name))
                {
                    _attributes.Add(attribute);
                }

                pos++;
            }
        }
        public void Constructor_ValidAttributeStrings_AttributeCollectionContainsCorrectAttributeCount(
            string attributeString, int expectedAttributeCount)
        {
            var tag = new HamlNodeHtmlAttributeCollection(0, attributeString);

            Assert.That(tag.Children.Count(), Is.EqualTo(expectedAttributeCount));
        }
        public void Constructor_ValidAttributeStrings_AttributeCollectionContainsCorrectAttributes(
            string attributeString, string expectedFirstAttribute)
        {
            var tag = new HamlNodeHtmlAttributeCollection(0, attributeString);

            Assert.That(tag.Children.First().Content, Is.EqualTo(expectedFirstAttribute));
        }
        public void Constructor_MixedBrackets_ParsesCorrectly(
            string attributeString, string expectedName, string expectedValue)
        {
            var tag = new HamlNodeHtmlAttributeCollection(0, attributeString);

            var firstChild = (HamlNodeHtmlAttribute)tag.Children.First();
            Assert.That(firstChild.Name, Is.EqualTo(expectedName));
            Assert.That(firstChild.Children.First().Content, Is.EqualTo(expectedValue));
        }
        public void Walk_VaryingAttributeCollections_WritesCorrectAttributes(string hamlLine, string expectedTag)
        {
            var node = new HamlNodeHtmlAttributeCollection(0, hamlLine);

            var builder = new ClassBuilderMock();
            new HamlNodeHtmlAttributeCollectionWalker(builder, new HamlHtmlOptions())
                .Walk(node);

            Assert.That(builder.Build(""), Is.EqualTo(expectedTag));
        }