예제 #1
0
        public void PassEmptyString()
        {
            var result = new CodeLine(string.Empty, TabCount);

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

            result.TabCount.ShouldEqual(0);
            result.SpaceCount.ShouldEqual(1);
        }
예제 #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();
        }
예제 #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;
        }
예제 #5
0
 public void PassZeroThrows()
 {
     try
     {
         var result = new CodeLine(AnyString, 0);
     }
     catch (ArgumentException ex)
     {
         ex.Message.ShouldContain("cannot be zero");
     }
 }
예제 #6
0
 public void PassNull_Throws()
 {
     try
     {
         var result = new CodeLine(null, TabCount);
     }
     catch (ArgumentNullException ex)
     {
         ex.Message.ShouldContain("value");
     }
 }
예제 #7
0
        public void StartsWithThreeTabs_Counted()
        {
            var result = new CodeLine($"{TabString}{TabString}{TabString}{AnyString}", TabCount);

            result.TabCount.ShouldEqual(3);
        }
예제 #8
0
        public void StartsWithSpace_ReturnsCorrectSpaceCount()
        {
            var result = new CodeLine($" {AnyString}", TabCount);

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

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

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

            result.TabCount.ShouldEqual(0);
        }
예제 #12
0
        public void ContainsSpacesInsideCode()
        {
            var result = new CodeLine($" {AnyString} {AnyString} 7;", TabCount);

            result.SpaceCount.ShouldEqual(1);
        }