Whee.WordBuilder.ProjectV2.ProjectSerializer.ReadIndentationToken C# (CSharp) Метод

ReadIndentationToken() публичный Метод

public ReadIndentationToken ( IProjectNode node ) : Token
node IProjectNode
Результат Token
        public Token ReadIndentationToken(IProjectNode node)
        {
            m_warningsToNode = node;
            CheckForComments(node);
            StringBuilder sb = new StringBuilder();
            int start = m_Offset;
            int len = ReadWhiteSpace(sb);

            if (len > 0)
            {
                m_lastIndentationLevel = m_currentIndentationLevel;
                m_currentIndentationLevel = GetIndentationLevel(sb.ToString());
                return CreateToken(node, TokenType.Indentation, sb.ToString(), start, len);
            }

            m_lastIndentationLevel = m_currentIndentationLevel;
            m_currentIndentationLevel = 0;
            return null;
        }

Usage Example

Пример #1
0
        public void TestIndentationLevelVerification()
        {
            Mockery mockery = new Mockery();
            IProjectNode pn = mockery.NewMock<IProjectNode>();
            ProjectSerializer ps = new ProjectSerializer("\tged\r\n\t  hest \r\n\tnejj\r\n", null, null);
            ps.SpacesIndent = 2;

            Token t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t", t.Text);

            t = ps.ReadTextToken(pn);

            Assert.AreEqual(TokenType.Text, t.Type);
            Assert.AreEqual("ged", t.Text);

            t = ps.ReadLineBreakToken(pn);

            t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t  ", t.Text);
            Assert.AreEqual(2, ps.GetIndentationLevel(t.Text));

            t = ps.ReadTextToken(pn);

            Assert.AreEqual(TokenType.Text, t.Type);
            Assert.AreEqual("hest", t.Text);

            t = ps.ReadLineBreakToken(pn);

            t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t", t.Text);
            Assert.AreEqual(1, ps.GetIndentationLevel(t.Text));

            ps.RollBackToken(t);

            t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t", t.Text);
            Assert.AreEqual(1, ps.GetIndentationLevel(t.Text));
        }