mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: new implementation for assertContainsOrdered
Previous implementation uses retainAll. It is not perfectly match the case if we want to check if elements which is exist in "collection" list contains in the same order in "expected" list.
This commit is contained in:
@@ -31,6 +31,8 @@ import com.intellij.testFramework.exceptionCases.AbstractExceptionCase;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.PeekableIterator;
|
||||
import com.intellij.util.containers.PeekableIteratorWrapper;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import com.intellij.util.lang.CompoundRuntimeException;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -43,6 +45,7 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.ComparisonFailure;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -559,9 +562,20 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
}
|
||||
|
||||
public static <T> void assertContainsOrdered(@NotNull Collection<? extends T> collection, @NotNull Collection<? extends T> expected) {
|
||||
ArrayList<T> copy = new ArrayList<>(collection);
|
||||
copy.retainAll(expected);
|
||||
assertOrderedEquals(toString(collection), copy, expected);
|
||||
PeekableIterator<T> expectedIt = new PeekableIteratorWrapper<>(expected.iterator());
|
||||
PeekableIterator<T> actualIt = new PeekableIteratorWrapper<>(collection.iterator());
|
||||
|
||||
while (actualIt.hasNext() && expectedIt.hasNext()) {
|
||||
T expectedElem = expectedIt.peek();
|
||||
T actualElem = actualIt.peek();
|
||||
if (expectedElem.equals(actualElem)) {
|
||||
expectedIt.next();
|
||||
}
|
||||
actualIt.next();
|
||||
}
|
||||
if (expectedIt.hasNext()) {
|
||||
throw new ComparisonFailure("", toString(expected), toString(collection));
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
|
||||
@@ -4,12 +4,10 @@ package git4idea.ignore
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager
|
||||
import com.intellij.util.containers.PeekableIteratorWrapper
|
||||
import git4idea.GitUtil
|
||||
import git4idea.repo.GitRepositoryFiles.GITIGNORE
|
||||
import git4idea.test.GitPlatformTest
|
||||
import git4idea.test.createRepository
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
const val OUT = "out"
|
||||
@@ -60,32 +58,7 @@ class GitIgnoredFileTest : GitPlatformTest() {
|
||||
val generatedGitIgnoreContent = gitIgnoreFile.readText(projectCharset)
|
||||
assertFalse("Generated ignore file is empty", generatedGitIgnoreContent.isBlank())
|
||||
assertFalse("Generated ignore file content should be system-independent", generatedGitIgnoreContent.contains('\\'))
|
||||
assertIncludesAllOrdered(generatedGitIgnoreContent.lines(), gitIgnoreExpectedContentList)
|
||||
}
|
||||
|
||||
private fun assertIncludesAllOrdered(actualList: List<String>, expectedList: List<String>) {
|
||||
val expectedIt = PeekableIteratorWrapper(expectedList.iterator())
|
||||
val actualIt = PeekableIteratorWrapper(actualList.iterator())
|
||||
|
||||
while (actualIt.hasNext() && expectedIt.hasNext()) {
|
||||
val expected = expectedIt.peek()
|
||||
val actual = actualIt.peek()
|
||||
if (expected == actual) {
|
||||
expectedIt.next()
|
||||
actualIt.next()
|
||||
}
|
||||
else {
|
||||
actualIt.next()
|
||||
}
|
||||
}
|
||||
|
||||
if(expectedIt.hasNext()){
|
||||
Assert.fail("""
|
||||
Expected: $expectedList
|
||||
Actual: $actualList
|
||||
Not included in the same order.
|
||||
""".trimIndent())
|
||||
}
|
||||
assertContainsOrdered(generatedGitIgnoreContent.lines(), gitIgnoreExpectedContentList)
|
||||
}
|
||||
|
||||
private fun VirtualFile.findOrCreateDir(dirName: String) = this.findChild(dirName) ?: createChildDirectory(this, dirName)
|
||||
|
||||
Reference in New Issue
Block a user