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

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

public GetIndentationLevel ( string indentation ) : int
indentation string
Результат int
        public int GetIndentationLevel(string indentation)
        {
            return indentation.Replace(new string(' ', SpacesIndent), "\t").Replace(" ", "").Length;
        }

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));
        }