From 50e44b79cb5a11df1c6af84c61a31b64dafce0ff Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 17 Oct 2012 20:39:27 +0400 Subject: [PATCH] GitBranchWorkerTest: don't use system line separators: Git may apply its own conversion. Detect actual separators, and convert expected text according to them. --- .../git4idea/branch/GitBranchWorkerTest.groovy | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy index eba1a7b77022..6c5e603e6b34 100644 --- a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy +++ b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy @@ -28,6 +28,7 @@ import com.intellij.openapi.vcs.changes.CurrentContentRevision import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.vcs.MockChangeListManager import com.intellij.util.LineSeparator +import com.intellij.util.text.CharArrayUtil import git4idea.PlatformFacade import git4idea.commands.Git import git4idea.config.GitVersion @@ -773,12 +774,25 @@ class GitBranchWorkerTest { } private static void assertContent(String expectedContent, String actual) { - expectedContent = StringUtil.convertLineSeparators(expectedContent, LineSeparator.getSystemLineSeparator().separatorString).trim() + expectedContent = StringUtil.convertLineSeparators(expectedContent, detectLineSeparators(actual).separatorString).trim() actual = actual.trim() assertEquals String.format("Content doesn't match.%nExpected:%n%s%nActual:%n%s%n", substWhitespaces(expectedContent), substWhitespaces(actual)), expectedContent, actual } + private static LineSeparator detectLineSeparators(String actual) { + char[] chars = CharArrayUtil.fromSequenceWithoutCopying(actual); + for (char c : chars) { + if (c == '\r') { + return LineSeparator.CRLF; + } + else if (c == '\n') { // if we are here, there was no \r before + return LineSeparator.LF; + } + } + return LineSeparator.LF; + } + private static String substWhitespaces(String s) { return s.replaceAll("\r", Matcher.quoteReplacement("\\r")).replaceAll("\n", Matcher.quoteReplacement("\\n")).replaceAll(" ", "_") }