mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
GitBranchWorkerTest: use correct content to compare
Old versions of git (e.g. 1.7.0.2) are removing the line at the end of file. Adjust the content Reuse LOCAL_CHANGES_OVERWRITTEN_BY from GitScenarios instead of copy-pasting the content. Use correct system line separators instead of CRLF. Extract assertContent() method that would compare content smartly.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -52,4 +54,12 @@ public enum LineSeparator {
|
||||
public static boolean knownAndDifferent(@Nullable LineSeparator separator1, @Nullable LineSeparator separator2) {
|
||||
return separator1 != null && separator2 != null && !separator1.equals(separator2);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LineSeparator getSystemLineSeparator() {
|
||||
if (SystemInfo.isWindows) {
|
||||
return CRLF;
|
||||
}
|
||||
return LF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,15 +351,12 @@ class GitBranchWorkerTest {
|
||||
assertCurrentBranch("feature");
|
||||
cd myUltimate
|
||||
def actual = cat(localChanges[0])
|
||||
def expectedContent = """line with branch changes
|
||||
common content
|
||||
common content
|
||||
common content
|
||||
line with master changes
|
||||
"""
|
||||
assertEquals("Content doesn't match", StringUtil.convertLineSeparators(expectedContent, LineSeparator.CRLF.separatorString), actual)
|
||||
def expectedContent = LOCAL_CHANGES_OVERWRITTEN_BY.branchLine +
|
||||
LOCAL_CHANGES_OVERWRITTEN_BY.initial +
|
||||
LOCAL_CHANGES_OVERWRITTEN_BY.masterLine;
|
||||
assertContent(expectedContent, actual)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void "agree to smart merge should smart merge"() {
|
||||
def localChanges = agree_to_smart_operation("merge",
|
||||
@@ -367,13 +364,10 @@ line with master changes
|
||||
|
||||
cd myUltimate
|
||||
def actual = cat(localChanges[0])
|
||||
def expectedContent = """line with branch changes
|
||||
common content
|
||||
common content
|
||||
common content
|
||||
line with master changes
|
||||
"""
|
||||
assertEquals("Content doesn't match", StringUtil.convertLineSeparators(expectedContent, LineSeparator.CRLF.separatorString), actual)
|
||||
def expectedContent = LOCAL_CHANGES_OVERWRITTEN_BY.branchLine +
|
||||
LOCAL_CHANGES_OVERWRITTEN_BY.initial +
|
||||
LOCAL_CHANGES_OVERWRITTEN_BY.masterLine;
|
||||
assertEquals("Content doesn't match", StringUtil.convertLineSeparators(expectedContent, LineSeparator.getSystemLineSeparator().separatorString), actual)
|
||||
}
|
||||
|
||||
Collection<String> agree_to_smart_operation(String operation, String expectedSuccessMessage) {
|
||||
@@ -776,6 +770,12 @@ line with master changes
|
||||
assertEquals "Content doesn't match", content, cat(path)
|
||||
}
|
||||
|
||||
private static void assertContent(String expectedContent, String actual) {
|
||||
assertEquals "Content doesn't match",
|
||||
StringUtil.convertLineSeparators(expectedContent, LineSeparator.getSystemLineSeparator().separatorString),
|
||||
actual
|
||||
}
|
||||
|
||||
// TODO Somehow I wasn't able to make dynamic partial implementations, because both overloaded notifySuccess() methods are needed,
|
||||
// therefore there are duplicate entries in the map => only one method gets implemented.
|
||||
class AgreeToSmartOperationTestUiHandler implements GitBranchUiHandler {
|
||||
|
||||
@@ -30,14 +30,14 @@ class GitScenarios {
|
||||
|
||||
private static final String BRANCH_FOR_UNMERGED_CONFLICTS = "unmerged_files_branch_" + Math.random();
|
||||
|
||||
private static final def LOCAL_CHANGES_OVERWRITTEN_BY = [
|
||||
static final def LOCAL_CHANGES_OVERWRITTEN_BY = [
|
||||
initial:
|
||||
"""common content
|
||||
common content
|
||||
common content
|
||||
""",
|
||||
branchLine: "line with branch changes",
|
||||
masterLine: "line with master changes"
|
||||
branchLine: "line with branch changes\n",
|
||||
masterLine: "line with master changes\n"
|
||||
]
|
||||
|
||||
/**
|
||||
@@ -139,7 +139,7 @@ common content
|
||||
|
||||
def prepend(String fileName, String content) {
|
||||
def previousContent = cat(fileName)
|
||||
new File(myCurrentDir, fileName).withWriter("UTF-8") { it.write(content + "\n" + previousContent) }
|
||||
new File(myCurrentDir, fileName).withWriter("UTF-8") { it.write(content + previousContent) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user