public void DetectMostFrequentLineEnd_DetectFullLineEnding() { string text = "test\n\r\n\r\n test\r\n te\r restasd"; var result = NewLineManager.DetectMostFrequentLineEnd(text); Assert.AreEqual("\r\n", result); }
public void DetectMostFrequentLineEnd_LF_ReturnsLF() { const string textWithLF = "test\ntest"; var actual = NewLineManager.DetectMostFrequentLineEnd(textWithLF); Assert.That(actual, Is.EqualTo("\n")); }
public void ReplaceAllLineEnds_NewLineEndIsNull_ThrowsArgumentNullException() { var inputText = string.Empty; string newLineEnd = null; Assert.That(() => NewLineManager.ReplaceAllLineEnds(inputText, newLineEnd), Throws.InstanceOf <ArgumentNullException>()); }
public void DetectMostFrequentLineEnd_DifferentCRLF_ReturnsFullLineEnding() { const string textWithDifferentCRLF = "test\n\r\n\r\n test\r\n te\r restasd"; var actual = NewLineManager.DetectMostFrequentLineEnd(textWithDifferentCRLF); Assert.That(actual, Is.EqualTo("\r\n")); }
public void NextLineEndPosition_InputTextNull_ThrowsArgumentNullException() { string inputText = null; const int startIndex = -1; Assert.That(() => NewLineManager.NextLineEndPosition(inputText, startIndex), Throws.InstanceOf <ArgumentNullException>()); }
public void DetectMostFrequentLineEnd_CR_ReturnsCR() { const string textWithCR = "test\rtest"; var actual = NewLineManager.DetectMostFrequentLineEnd(textWithCR); Assert.That(actual, Is.EqualTo("\r")); }
public void NextLineEndPositionInformation_GivenStartIndexAndCountAndInputTextNull_ThrowsArgumentNullException() { string inputText = null; const int startIndex = 0; const int count = -1; Assert.That(() => NewLineManager.NextLineEndPositionInformation(inputText, startIndex, count), Throws.InstanceOf <ArgumentNullException>()); }
public void ReplaceAllLineEnds_ReplaceFullLineEnding() { string text1 = "test1"; string text2 = "test2"; string text3 = "test3"; string text4 = "test4"; string fulltext = text1 + "\r\n" + text2 + "\n" + text3 + "\r" + text4; Assert.AreEqual(text1 + text2 + text3 + text4, NewLineManager.ReplaceAllLineEnds(fulltext, string.Empty)); }
public void ReplaceAllLineEnds_NewLineEndIsEmpty_ReturnsTextWithoutLineEnds() { const string text1 = "test1"; const string text2 = "test2"; const string text3 = "test3"; const string text4 = "test4"; const string fulltext = text1 + "\r\n" + text2 + "\n" + text3 + "\r" + text4; var actual = NewLineManager.ReplaceAllLineEnds(fulltext, string.Empty); Assert.That(actual, Is.EqualTo(text1 + text2 + text3 + text4)); }
public static string Prepare(string headerText, string currentHeaderText, ICommentParser commentParser) { var lineEndingInDocument = NewLineManager.DetectMostFrequentLineEnd(headerText); var headerWithNewLine = NewLineManager.ReplaceAllLineEnds(headerText, lineEndingInDocument); //If there's a comment right at the beginning of the file, we need to add an empty line so that the comment doesn't //become a part of the header. If there already exists an empty line we dont have to add another one if (!CurrentFileStartsWithNewLine(currentHeaderText, lineEndingInDocument) && !HeaderEndsWithNewline(headerWithNewLine, lineEndingInDocument) && CurrentFileContainsCommentOnTop(currentHeaderText, commentParser)) { return(headerWithNewLine + lineEndingInDocument); } return(headerWithNewLine); }
public static string Prepare(string headerText, string currentHeaderText, ICommentParser commentParser) { var lineEndingInDocument = NewLineManager.DetectMostFrequentLineEnd(headerText); var headerWithNewLine = headerText; var newLine = NewLineManager.DetectMostFrequentLineEnd(headerWithNewLine); headerWithNewLine = NewLineManager.ReplaceAllLineEnds(headerWithNewLine, lineEndingInDocument); //if there's a comment right at the beginning of the file, //we need to add an empty line so that the comment doesn't //become a part of the header if (!string.IsNullOrEmpty(commentParser.Parse(currentHeaderText)) && !headerWithNewLine.EndsWith(lineEndingInDocument + lineEndingInDocument)) { headerWithNewLine += newLine; } return(headerWithNewLine); }
public void DetectLineEnd_CRLF() { string text = "test\r\ntest"; Assert.AreEqual("\r\n", NewLineManager.DetectMostFrequentLineEnd(text)); }
public void DetectMostFrequentLineEnd_DifferentEndings_ReturnsMostFrequentEnding(string text, string mostFrequentEnding) { var actual = NewLineManager.DetectMostFrequentLineEnd(text); Assert.That(actual, Is.EqualTo(mostFrequentEnding)); }
public void DetectMostFrequentLineEnd_InputTextIsNull_ThrowsArgumentNullException() { string inputText = null; Assert.That(() => NewLineManager.DetectMostFrequentLineEnd(inputText), Throws.InstanceOf <ArgumentNullException>()); }
public void NextLineEndPosition_GivenStartIndex_ReturnsCorrectPosition(string inputText, int startIndex, int expectedPosition) { var actual = NewLineManager.NextLineEndPosition(inputText, startIndex); Assert.That(actual, Is.EqualTo(expectedPosition)); }