From 7eb37d480610a01aefcae85ccf4462c3337c3e30 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 28 Jul 2017 17:07:44 +0200 Subject: [PATCH] mad testing: introduce StripTestDataMarkup action --- .../JavaCodeInsightSanityTest.java | 1 + .../propertyBased/FileWithActions.java | 2 +- .../propertyBased/StripTestDataMarkup.java | 51 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/StripTestDataMarkup.java diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java index bb978f4c745f..9173a715c099 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java @@ -37,6 +37,7 @@ public class JavaCodeInsightSanityTest extends LightCodeInsightFixtureTestCase { Function> fileActions = file -> Generator.anyOf(InvokeIntention.randomIntentions(file, new JavaIntentionPolicy()), InvokeCompletion.completions(file, new JavaCompletionPolicy()), + Generator.constant(new StripTestDataMarkup(file)), DeleteRange.psiRangeDeletions(file)); PropertyChecker.forAll(actionsOnJavaFiles(fileActions)).shouldHold(FileWithActions::runActions); } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java index b1dab625fb82..28a5496ccf05 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java @@ -35,7 +35,7 @@ public class FileWithActions { myActions = actions; } - PsiFile getPsiFile() { + public PsiFile getPsiFile() { return myFile; } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/StripTestDataMarkup.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/StripTestDataMarkup.java new file mode 100644 index 000000000000..ae2b6e3f297d --- /dev/null +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/StripTestDataMarkup.java @@ -0,0 +1,51 @@ +/* + * 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.testFramework.propertyBased; + +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.ExpectedHighlightingData; +import com.intellij.testFramework.PsiTestUtil; + +/** + * @author peter + */ +public class StripTestDataMarkup implements MadTestingAction { + private final PsiFile myFile; + + public StripTestDataMarkup(PsiFile file) { + myFile = file; + } + + @Override + public void performAction() { + WriteCommandAction.runWriteCommandAction(myFile.getProject(), () -> { + Document document = myFile.getViewProvider().getDocument(); + new ExpectedHighlightingData(document, true, true, true, true, myFile).init(); + removeMarkup(document, ""); + removeMarkup(document, ""); + removeMarkup(document, ""); + removeMarkup(document, ""); + }); + PsiTestUtil.checkPsiStructureWithCommit(myFile, PsiTestUtil::checkStubsMatchText); + } + + private static void removeMarkup(Document document, String marker) { + document.setText(StringUtil.replace(document.getText(), marker, "")); + } +}