mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
@@ -63,7 +63,7 @@ public abstract class DiffRequestFactory {
|
||||
public abstract String getContentTitle(@NotNull VirtualFile file);
|
||||
|
||||
@NotNull
|
||||
public abstract String getTitle(@NotNull VirtualFile file1, @NotNull VirtualFile file2);
|
||||
public abstract String getTitle(@Nullable VirtualFile file1, @Nullable VirtualFile file2);
|
||||
|
||||
@NotNull
|
||||
public abstract String getTitle(@NotNull VirtualFile file);
|
||||
|
||||
@@ -16,5 +16,6 @@
|
||||
<orderEntry type="module" module-name="diff-impl" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="mockito" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="KotlinTest" level="project" />
|
||||
<orderEntry type="module" module-name="vcs-impl" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -111,14 +111,16 @@ public class DiffRequestFactoryImpl extends DiffRequestFactory {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTitle(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
|
||||
return getTitle(VcsUtil.getFilePath(file1), VcsUtil.getFilePath(file2), " vs ");
|
||||
public String getTitle(@Nullable VirtualFile file1, @Nullable VirtualFile file2) {
|
||||
FilePath path1 = file1 != null ? VcsUtil.getFilePath(file1) : null;
|
||||
FilePath path2 = file2 != null ? VcsUtil.getFilePath(file2) : null;
|
||||
return getTitle(path1, path2, " vs ");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTitle(@NotNull VirtualFile file) {
|
||||
return getTitle(file, file);
|
||||
return getTitle(file, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.progress.DumbProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vcs.LocalFilePath
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.containers.HashMap
|
||||
import com.intellij.util.text.CharSequenceSubSequence
|
||||
@@ -152,7 +153,7 @@ abstract class DiffTestCase : TestCase() {
|
||||
return Math.max(1, document.lineCount)
|
||||
}
|
||||
|
||||
infix fun Int.until(a: Int): IntRange = this..a - 1
|
||||
fun createFilePath(path: String) = LocalFilePath(path, path.endsWith('/') || path.endsWith('\\'))
|
||||
|
||||
//
|
||||
// AutoTests
|
||||
|
||||
@@ -30,9 +30,11 @@
|
||||
*/
|
||||
package com.intellij.diff.util
|
||||
|
||||
import com.intellij.diff.DiffRequestFactoryImpl
|
||||
import com.intellij.diff.DiffTestCase
|
||||
import com.intellij.openapi.diff.DiffBundle
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import java.io.File
|
||||
|
||||
class DiffUtilTest : DiffTestCase() {
|
||||
fun `test getSortedIndexes`() {
|
||||
@@ -78,4 +80,50 @@ class DiffUtilTest : DiffTestCase() {
|
||||
doTest(2, 1, "There are 2 changes and one conflict left")
|
||||
doTest(2, 3, "There are 2 changes and 3 conflicts left")
|
||||
}
|
||||
|
||||
fun `test diff content titles`() {
|
||||
fun doTest(path: String, expected: String) {
|
||||
val filePath = createFilePath(path)
|
||||
val actual1 = DiffRequestFactoryImpl.getContentTitle(filePath)
|
||||
val actual2 = DiffRequestFactoryImpl.getTitle(filePath, null, " <-> ")
|
||||
val actual3 = DiffRequestFactoryImpl.getTitle(null, filePath, " <-> ")
|
||||
|
||||
val expectedNative = expected.replace('/', File.separatorChar)
|
||||
assertEquals(expectedNative, actual1)
|
||||
assertEquals(expectedNative, actual2)
|
||||
assertEquals(expectedNative, actual3)
|
||||
}
|
||||
|
||||
doTest("file.txt", "file.txt")
|
||||
doTest("/path/to/file.txt", "file.txt (/path/to)")
|
||||
doTest("/path/to/dir/", "/path/to/dir")
|
||||
}
|
||||
|
||||
fun `test diff request titles`() {
|
||||
fun doTest(path1: String, path2: String, expected: String) {
|
||||
val filePath1 = createFilePath(path1)
|
||||
val filePath2 = createFilePath(path2)
|
||||
val actual = DiffRequestFactoryImpl.getTitle(filePath1, filePath2, " <-> ")
|
||||
assertEquals(expected.replace('/', File.separatorChar), actual)
|
||||
}
|
||||
|
||||
doTest("file1.txt", "file1.txt", "file1.txt")
|
||||
doTest("/path/to/file1.txt", "/path/to/file1.txt", "file1.txt (/path/to)")
|
||||
doTest("/path/to/dir1/", "/path/to/dir1/", "/path/to/dir1")
|
||||
|
||||
doTest("file1.txt", "file2.txt", "file1.txt <-> file2.txt")
|
||||
doTest("/path/to/file1.txt", "/path/to/file2.txt", "file1.txt <-> file2.txt (/path/to)")
|
||||
doTest("/path/to/dir1/", "/path/to/dir2/", "dir1 <-> dir2 (/path/to)")
|
||||
|
||||
doTest("/path/to/file1.txt", "/path/to_another/file1.txt", "file1.txt (/path/to <-> /path/to_another)")
|
||||
doTest("/path/to/file1.txt", "/path/to_another/file2.txt", "file1.txt <-> file2.txt (/path/to <-> /path/to_another)")
|
||||
doTest("/path/to/dir1/", "/path/to_another/dir2/", "dir1 <-> dir2 (/path/to <-> /path/to_another)")
|
||||
|
||||
doTest("file1.txt", "/path/to/file1.txt", "file1.txt <-> /path/to/file1.txt")
|
||||
doTest("file1.txt", "/path/to/file2.txt", "file1.txt <-> /path/to/file2.txt")
|
||||
|
||||
doTest("/path/to/dir1/", "/path/to/file2.txt", "dir1/ <-> file2.txt (/path/to)")
|
||||
doTest("/path/to/file1.txt", "/path/to/dir2/", "file1.txt <-> dir2/ (/path/to)")
|
||||
doTest("/path/to/dir1/", "/path/to_another/file2.txt", "dir1/ <-> file2.txt (/path/to <-> /path/to_another)")
|
||||
}
|
||||
}
|
||||
|
||||
+3
-18
@@ -341,24 +341,9 @@ public class ChangeDiffRequestProducer implements DiffRequestProducer {
|
||||
public static String getRequestTitle(@NotNull Change change) {
|
||||
ContentRevision bRev = change.getBeforeRevision();
|
||||
ContentRevision aRev = change.getAfterRevision();
|
||||
|
||||
assert bRev != null || aRev != null;
|
||||
if (bRev != null && aRev != null) {
|
||||
FilePath bPath = bRev.getFile();
|
||||
FilePath aPath = aRev.getFile();
|
||||
if (bPath.equals(aPath)) {
|
||||
return DiffRequestFactoryImpl.getContentTitle(bPath);
|
||||
}
|
||||
else {
|
||||
return DiffRequestFactoryImpl.getTitle(bPath, aPath, " -> ");
|
||||
}
|
||||
}
|
||||
else if (bRev != null) {
|
||||
return DiffRequestFactoryImpl.getContentTitle(bRev.getFile());
|
||||
}
|
||||
else {
|
||||
return DiffRequestFactoryImpl.getContentTitle(aRev.getFile());
|
||||
}
|
||||
FilePath bPath = bRev != null ? bRev.getFile() : null;
|
||||
FilePath aPath = aRev != null ? aRev.getFile() : null;
|
||||
return DiffRequestFactoryImpl.getTitle(bPath, aPath, " -> ");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -96,13 +96,7 @@ public class VcsHistoryUtil {
|
||||
FilePath path1 = getRevisionPath(revision1);
|
||||
FilePath path2 = getRevisionPath(revision2);
|
||||
|
||||
String title;
|
||||
if (path1 != null && path2 != null) {
|
||||
title = DiffRequestFactoryImpl.getTitle(path1, path2, " -> ");
|
||||
}
|
||||
else {
|
||||
title = DiffRequestFactoryImpl.getContentTitle(path);
|
||||
}
|
||||
String title = DiffRequestFactoryImpl.getTitle(path1, path2, " -> ");
|
||||
|
||||
DiffContent diffContent1 = createContent(project, content1, revision1, path);
|
||||
DiffContent diffContent2 = createContent(project, content2, revision2, path);
|
||||
|
||||
Reference in New Issue
Block a user