public void PassEmptyString() { var result = new CodeLine(string.Empty, TabCount); result.TabCount.ShouldEqual(0); result.Line.ShouldEqual(string.Empty); }
public void StartsWithSpace_TabCountZero() { var result = new CodeLine($" {AnyString}", TabCount); result.TabCount.ShouldEqual(0); result.SpaceCount.ShouldEqual(1); }
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(); }
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; }
public void PassZeroThrows() { try { var result = new CodeLine(AnyString, 0); } catch (ArgumentException ex) { ex.Message.ShouldContain("cannot be zero"); } }
public void PassNull_Throws() { try { var result = new CodeLine(null, TabCount); } catch (ArgumentNullException ex) { ex.Message.ShouldContain("value"); } }
public void StartsWithThreeTabs_Counted() { var result = new CodeLine($"{TabString}{TabString}{TabString}{AnyString}", TabCount); result.TabCount.ShouldEqual(3); }
public void StartsWithSpace_ReturnsCorrectSpaceCount() { var result = new CodeLine($" {AnyString}", TabCount); result.SpaceCount.ShouldEqual(1); }
public void StartsWithOneTab_ReturnsCorrectNumberOfSpaces() { var result = new CodeLine($"{TabString}{AnyString}", TabCount); result.SpaceCount.ShouldEqual(TabCount); }
public void StartsWithFullTab_Counted() { var result = new CodeLine($"{TabString}{AnyString}", TabCount); result.TabCount.ShouldEqual(1); }
public void EndsWithTab_NotCounted() { var result = new CodeLine($"{AnyString}{TabString}", TabCount); result.TabCount.ShouldEqual(0); }
public void ContainsSpacesInsideCode() { var result = new CodeLine($" {AnyString} {AnyString} 7;", TabCount); result.SpaceCount.ShouldEqual(1); }