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_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 DetectMostFrequentLineEnd_LF_ReturnsLF() { const string textWithLF = "test\ntest"; var actual = NewLineManager.DetectMostFrequentLineEnd(textWithLF); Assert.That(actual, Is.EqualTo("\n")); }
public void DetectMostFrequentLineEnd_CR_ReturnsCR() { const string textWithCR = "test\rtest"; var actual = NewLineManager.DetectMostFrequentLineEnd(textWithCR); Assert.That(actual, Is.EqualTo("\r")); }
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>()); }