Exemplo n.º 1
0
        public void PassEmptyString()
        {
            var result = new CodeLine(string.Empty, TabCount);

            result.TabCount.ShouldEqual(0);
            result.Line.ShouldEqual(string.Empty);
        }
Exemplo n.º 2
0
        public void StartsWithSpace_TabCountZero()
        {
            var result = new CodeLine($" {AnyString}", TabCount);

            result.TabCount.ShouldEqual(0);
            result.SpaceCount.ShouldEqual(1);
        }
Exemplo n.º 3
0
        private static string TrimExcessTabs(CodeLine[] codeLines,
            int excessTabDepth,
            int spacesPerTab,
            bool endsWithNewLine)
        {
            var linesWithoutEmptyStartAndEnd = RemoveFirstAndLastBlankLines(codeLines);

            var numberOfSpacesToTrim = excessTabDepth * spacesPerTab;

            var builder = new StringBuilder();

            for (var i = 0; i < linesWithoutEmptyStartAndEnd.Length; i++)
            {
                if (linesWithoutEmptyStartAndEnd[i].IsEmpty)
                {
                    builder.Append(CodeLine.NewLine);
                    continue;
                }

                builder.Append(linesWithoutEmptyStartAndEnd[i].Line.Substring(numberOfSpacesToTrim));

                if (endsWithNewLine || i < linesWithoutEmptyStartAndEnd.Length - 1)
                {
                    builder.Append(CodeLine.NewLine);
                }
            }

            return builder.ToString();
        }
Exemplo n.º 4
0
        private static CodeLine[] RemoveFirstAndLastBlankLines(CodeLine[] codeLines)
        {
            if (codeLines == null
                || codeLines.Length <= 1
                || codeLines.All(cl => cl.IsEmpty))
            {
                return codeLines;
            }

            var startIsEmpty = codeLines[0].IsEmpty;
            var endIsEmpty = codeLines[codeLines.Length - 1].IsEmpty;

            if (!endIsEmpty && !startIsEmpty)
            {
                return codeLines;
            }

            var index = startIsEmpty ? 1 : 0;
            var length = endIsEmpty ? codeLines.Length - 1 : codeLines.Length;

            if (startIsEmpty)
            {
                length--;
            }

            var result = new CodeLine[length];
            Array.Copy(codeLines, index, result, 0, length);
            return result;
        }
Exemplo n.º 5
0
 public void PassZeroThrows()
 {
     try
     {
         var result = new CodeLine(AnyString, 0);
     }
     catch (ArgumentException ex)
     {
         ex.Message.ShouldContain("cannot be zero");
     }
 }
Exemplo n.º 6
0
 public void PassNull_Throws()
 {
     try
     {
         var result = new CodeLine(null, TabCount);
     }
     catch (ArgumentNullException ex)
     {
         ex.Message.ShouldContain("value");
     }
 }
Exemplo n.º 7
0
        public void StartsWithThreeTabs_Counted()
        {
            var result = new CodeLine($"{TabString}{TabString}{TabString}{AnyString}", TabCount);

            result.TabCount.ShouldEqual(3);
        }
Exemplo n.º 8
0
        public void StartsWithSpace_ReturnsCorrectSpaceCount()
        {
            var result = new CodeLine($" {AnyString}", TabCount);

            result.SpaceCount.ShouldEqual(1);
        }
Exemplo n.º 9
0
        public void StartsWithOneTab_ReturnsCorrectNumberOfSpaces()
        {
            var result = new CodeLine($"{TabString}{AnyString}", TabCount);

            result.SpaceCount.ShouldEqual(TabCount);
        }
Exemplo n.º 10
0
        public void StartsWithFullTab_Counted()
        {
            var result = new CodeLine($"{TabString}{AnyString}", TabCount);

            result.TabCount.ShouldEqual(1);
        }
Exemplo n.º 11
0
        public void EndsWithTab_NotCounted()
        {
            var result = new CodeLine($"{AnyString}{TabString}", TabCount);

            result.TabCount.ShouldEqual(0);
        }
Exemplo n.º 12
0
        public void ContainsSpacesInsideCode()
        {
            var result = new CodeLine($" {AnyString} {AnyString} 7;", TabCount);

            result.SpaceCount.ShouldEqual(1);
        }