< Summary

Class:GDX.Developer.TextGenerator
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/TextGenerator.cs
Covered lines:59
Uncovered lines:0
Coverable lines:59
Total lines:163
Line coverage:100% (59 of 59)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:10
Method coverage:100% (10 of 10)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TextGenerator(...)0%110100%
ApplyIndent()0%220100%
Append(...)0%110100%
AppendLine(...)0%110100%
AppendLineRange(...)0%330100%
GetIndentLevel()0%110100%
NextLine()0%110100%
PopIndent()0%3.053081.82%
PushIndent(...)0%220100%
ToString()0%220100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/TextGenerator.cs

#LineLine coverage
 1using System.Collections;
 2using System.Text;
 3
 4namespace GDX.Developer
 5{
 6    /// <summary>
 7    ///     A formatted text generator useful for creating text based files with some semblance of organization.
 8    /// </summary>
 9    public class TextGenerator
 10    {
 11        /// <summary>
 12        ///     The actual buffer holder used to create the dynamic string.
 13        /// </summary>
 14        readonly StringBuilder m_Builder;
 15
 16        /// <summary>
 17        ///     The content used to indicate the closing of a section that was indented.
 18        /// </summary>
 19        readonly string m_IndentClose;
 20
 21        /// <summary>
 22        ///     The assigned indent content used to indent lines where applicable.
 23        /// </summary>
 24        readonly string m_IndentContent;
 25
 26        /// <summary>
 27        ///     The content used to indicate the opening of a section which should be indented.
 28        /// </summary>
 29        readonly string m_IndentOpen;
 30
 31        /// <summary>
 32        ///     The current level of indentation.
 33        /// </summary>
 34        int m_IndentLevel;
 35
 36        /// <summary>
 37        ///     Create a new <see cref="TextGenerator" /> with the
 38        /// </summary>
 39        /// <param name="indentContent">
 40        ///     The characters used to indent the content when applicable. By default it will use a tab representation,
 41        ///     however for code files you may want to use four spaces.
 42        /// </param>
 43        /// <param name="indentOpen"></param>
 44        /// <param name="indentClose"></param>
 1845        public TextGenerator(string indentContent = "\t", string indentOpen = null, string indentClose = null)
 1846        {
 1847            m_IndentContent = indentContent;
 1848            m_IndentOpen = indentOpen;
 1849            m_IndentClose = indentClose;
 1850            m_Builder = new StringBuilder();
 1851        }
 52
 53        /// <summary>
 54        ///     Apply the current level of indent to the current line being operated on.
 55        /// </summary>
 56        public void ApplyIndent()
 74057        {
 426058            for (int i = 0; i < m_IndentLevel; i++)
 139059            {
 139060                m_Builder.Append(m_IndentContent);
 139061            }
 74062        }
 63
 64        /// <summary>
 65        ///     Append content to the current line being operated on.
 66        /// </summary>
 67        /// <param name="content">The content to append to the current line.</param>
 68        public void Append(string content)
 7469        {
 7470            m_Builder.Append(content);
 7471        }
 72
 73        /// <summary>
 74        ///     Apply the appropriate amount of indentation to the current line, appending content afterwards and then
 75        ///     advancing to the next line.
 76        /// </summary>
 77        /// <param name="content">The content to append to the current line.</param>
 78        public void AppendLine(string content = "")
 71379        {
 71380            ApplyIndent();
 71381            m_Builder.AppendLine(content);
 71382        }
 83
 84        /// <summary>
 85        ///     Append an <see cref="IEnumerable" /> set of content as individual lines with proper indentation.
 86        /// </summary>
 87        /// <param name="content">The content to be added.</param>
 88        public void AppendLineRange(IEnumerable content)
 189        {
 790            foreach (string s in content)
 291            {
 292                ApplyIndent();
 293                m_Builder.AppendLine(s);
 294            }
 195        }
 96
 97        /// <summary>
 98        ///     Gets the current indent level of the <see cref="TextGenerator" />.
 99        /// </summary>
 100        /// <returns>The indent level.</returns>
 101        public int GetIndentLevel()
 5102        {
 5103            return m_IndentLevel;
 5104        }
 105
 106        /// <summary>
 107        ///     Move the builder to the start of the next line.
 108        /// </summary>
 109        public void NextLine()
 15110        {
 15111            m_Builder.AppendLine();
 15112        }
 113
 114        /// <summary>
 115        ///     Remove a level of indentation from the builder.
 116        /// </summary>
 117        public void PopIndent()
 59118        {
 59119            if (m_IndentLevel <= 0)
 1120            {
 1121                return;
 122            }
 123
 58124            m_IndentLevel--;
 58125            if (m_IndentOpen == null)
 53126            {
 53127                return;
 128            }
 129
 5130            ApplyIndent();
 5131            m_Builder.AppendLine(m_IndentClose);
 59132        }
 133
 134        /// <summary>
 135        ///     Add a level of indentation to the builder.
 136        /// </summary>
 137        /// <param name="applyOpener">Should the opener be applied?</param>
 138        public void PushIndent(bool applyOpener = true)
 58139        {
 58140            if (m_IndentOpen != null && applyOpener)
 5141            {
 5142                ApplyIndent();
 5143                m_Builder.AppendLine(m_IndentOpen);
 5144            }
 145
 58146            m_IndentLevel++;
 58147        }
 148
 149        /// <summary>
 150        ///     Returns the built string content for the builder.
 151        /// </summary>
 152        /// <remarks>Will automatically reduce the indentation level to 0.</remarks>
 153        public override string ToString()
 11154        {
 16155            while (m_IndentLevel > 0)
 5156            {
 5157                PopIndent();
 5158            }
 159
 11160            return m_Builder.ToString().Trim();
 11161        }
 162    }
 163}

Coverage by test methods
















Methods/Properties

TextGenerator(System.String, System.String, System.String)
ApplyIndent()
Append(System.String)
AppendLine(System.String)
AppendLineRange(System.Collections.IEnumerable)
GetIndentLevel()
NextLine()
PopIndent()
PushIndent(System.Boolean)
ToString()