Esempio n. 1
0
        public void InvertedSectionToken_Uniqueness()
        {
            var str     = new StringSlice("foo");
            var literal = new LiteralToken
            {
                Content = new[] { str },
                ContentStartPosition = 0,
                ContentEndPosition   = 2,
                Indent       = 0,
                IsClosed     = true,
                IsWhitespace = false
            };

            var blockToken = new InvertedSectionToken
            {
                SectionName = "section"
            };

            blockToken.Children.Add(literal);

            var blockToken2 = new InvertedSectionToken
            {
                SectionName = "section"
            };

            blockToken2.Children.Add(literal);

            Assert.Equal("section", blockToken.Identifier);
            Assert.False(blockToken.Equals(null));
            Assert.StrictEqual(blockToken, blockToken2);
            Assert.Equal(blockToken.GetHashCode(), blockToken2.GetHashCode());
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to open an inverted section tag using the slice
        /// </summary>
        /// <param name="processor">The processor</param>
        /// <param name="slice">The slice</param>
        /// <returns>The result of the match</returns>
        public override ParserState TryOpenBlock(Processor processor, ref StringSlice slice)
        {
            var tagStart = slice.Start - processor.CurrentTags.StartTag.Length;
            var index    = slice.Start;

            while (slice[index].IsWhitespace())
            {
                index++;
            }

            var match = slice[index];

            if (match == OpeningTagDelimiter)
            {
                slice.Start = index;

                // Skip whitespace
                while (slice.CurrentChar.IsWhitespace())
                {
                    slice.NextChar();
                }

                var startIndex = slice.Start + 1;

                // Take characters until closing tag
                while (!slice.IsEmpty && !slice.Match(processor.CurrentTags.EndTag))
                {
                    slice.NextChar();
                }

                var sectionName          = slice.ToString(startIndex, slice.Start).TrimEnd();
                var contentStartPosition = slice.Start + processor.CurrentTags.EndTag.Length;

                var sectionTag = new InvertedSectionToken
                {
                    SectionName   = sectionName,
                    StartPosition = tagStart,
                    Parser        = this,
                    IsClosed      = false
                };

                processor.CurrentToken = sectionTag;

                slice.Start = contentStartPosition;

                return(ParserState.Break);
            }

            return(ParserState.Continue);
        }