mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
JavaCodeInsightSanityTest updates
* be more prepared to handling non-java files in future * check parsing more thoroughly
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.java.propertyBased;
|
||||
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class CheckPsiTextConsistency implements MadTestingAction {
|
||||
private final PsiFile myFile;
|
||||
|
||||
CheckPsiTextConsistency(PsiFile file) {
|
||||
myFile = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction() {
|
||||
PsiTestUtil.checkPsiStructureWithCommit(myFile, PsiTestUtil::checkFileStructure);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class DeleteRange extends ActionOnRange {
|
||||
|
||||
private DeleteRange(PsiFile file, int startOffset, int endOffset) {
|
||||
super(file.getViewProvider().getDocument(), startOffset, endOffset);
|
||||
assert myMarker.getDocument().getTextLength() == file.getTextLength();
|
||||
assert myMarker.getDocument().getTextLength() == file.getTextLength() : file + " " + myMarker.getDocument();
|
||||
myFile = file;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ class DeleteRange extends ActionOnRange {
|
||||
if (start == null || end == null) return null;
|
||||
|
||||
PsiElement commonParent = PsiTreeUtil.findCommonParent(start, end);
|
||||
if (commonParent == null || commonParent.getTextRange() == null) { // directory; for multi-root files
|
||||
return null;
|
||||
}
|
||||
return new DeleteRange(psiFile,
|
||||
commonParent.getTextRange().getStartOffset(),
|
||||
commonParent.getTextRange().getEndOffset());
|
||||
|
||||
+18
-10
@@ -17,18 +17,18 @@ package com.intellij.java.propertyBased;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiBinaryFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiPlainTextFile;
|
||||
import com.intellij.testFramework.SkipSlowTestLocally;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import slowCheck.DataStructure;
|
||||
import slowCheck.Generator;
|
||||
import slowCheck.IntDistribution;
|
||||
import slowCheck.PropertyChecker;
|
||||
import slowCheck.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
@@ -58,7 +58,8 @@ public class JavaCodeInsightSanityTest extends LightPlatformCodeInsightFixtureTe
|
||||
|
||||
public void testReparse() {
|
||||
Function<PsiFile, Generator<? extends MadTestingAction>> fileActions = file ->
|
||||
Generator.anyOf(DeleteRange.psiRangeDeletions(file),
|
||||
Generator.anyOf(DeleteRange.psiRangeDeletions(file),
|
||||
Generator.constant(new CheckPsiTextConsistency(file)),
|
||||
InsertString.asciiInsertions(file));
|
||||
PropertyChecker.forAll(actionsOnJavaFiles(fileActions), FileWithActions::checkIncrementalReparse);
|
||||
}
|
||||
@@ -67,19 +68,26 @@ public class JavaCodeInsightSanityTest extends LightPlatformCodeInsightFixtureTe
|
||||
private static Generator<FileWithActions> actionsOnFileContents(CodeInsightTestFixture fixture, String rootPath,
|
||||
FileFilter fileFilter,
|
||||
Function<PsiFile, Generator<? extends MadTestingAction>> actions) {
|
||||
FileFilter childFilter = child -> {
|
||||
FileFilter interestingIdeaFiles = child -> {
|
||||
String name = child.getName();
|
||||
if (name.startsWith(".")) return false;
|
||||
|
||||
return child.isDirectory() ? shouldGoInsiderDir(name)
|
||||
: fileFilter.accept(child) && child.length() < 500_000;
|
||||
if (child.isDirectory()) {
|
||||
return shouldGoInsiderDir(name);
|
||||
}
|
||||
return !FileTypeManager.getInstance().getFileTypeByFileName(name).isBinary() &&
|
||||
fileFilter.accept(child) &&
|
||||
child.length() < 500_000;
|
||||
};
|
||||
Generator<File> randomFiles =
|
||||
Generator.from(new FileGenerator(new File(rootPath), childFilter)).suchThat(Objects::nonNull).noShrink();
|
||||
Generator.from(new FileGenerator(new File(rootPath), interestingIdeaFiles)).suchThat(Objects::nonNull).noShrink();
|
||||
return randomFiles.flatMap(ioFile -> {
|
||||
PsiFile file = copyFileToProject(ioFile, fixture, rootPath);
|
||||
if (file instanceof PsiBinaryFile || file instanceof PsiPlainTextFile) {
|
||||
return Generator.constant(null);
|
||||
}
|
||||
return Generator.nonEmptyLists(actions.apply(file)).map(a -> new FileWithActions(file, a));
|
||||
});
|
||||
}).suchThat(Objects::nonNull);
|
||||
}
|
||||
|
||||
private static boolean shouldGoInsiderDir(@NotNull String name) {
|
||||
|
||||
Reference in New Issue
Block a user