From 86767c2349a790787ec73f6ee055f49f7c358bb9 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 13 Feb 2014 19:06:12 +0400 Subject: [PATCH] Remove write action for paste for better idea actual behaviour emulation --- .../JetLightCodeInsightFixtureTestCase.java | 24 ++++++++++++++++++- .../AbstractInsertImportOnPasteTest.java | 6 ++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java b/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java index 97b71bcbe49..1dc44929210 100644 --- a/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java +++ b/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2014 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. @@ -17,6 +17,9 @@ package org.jetbrains.jet.plugin; import com.intellij.ide.startup.impl.StartupManagerImpl; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.ex.ActionManagerEx; +import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.io.FileUtil; import com.intellij.testFramework.LightProjectDescriptor; @@ -69,4 +72,23 @@ public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsigh protected String fileName() { return getTestName(false) + ".kt"; } + + protected boolean performNotWriteEditorAction(String actionId) { + DataContext dataContext = ((EditorEx)myFixture.getEditor()).getDataContext(); + + ActionManagerEx managerEx = ActionManagerEx.getInstanceEx(); + AnAction action = managerEx.getAction(actionId); + AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, new Presentation(), managerEx, 0); + + action.update(event); + if (!event.getPresentation().isEnabled()) { + return false; + } + + managerEx.fireBeforeActionPerformed(action, dataContext, event); + action.actionPerformed(event); + + managerEx.fireAfterActionPerformed(action, dataContext, event); + return true; + } } diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractInsertImportOnPasteTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractInsertImportOnPasteTest.java index 0d6c36f440d..c4f8d6cc02b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractInsertImportOnPasteTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractInsertImportOnPasteTest.java @@ -69,14 +69,18 @@ public abstract class AbstractInsertImportOnPasteTest extends JetLightCodeInsigh myFixture.setTestDataPath(BASE_PATH); File testFile = new File(path); String testFileName = testFile.getName(); + configureByDependencyIfExists(testFileName.replace(".kt", ".dependency.kt")); configureByDependencyIfExists(testFileName.replace(".kt", ".dependency.java")); myFixture.configureByFile(testFileName); myFixture.performEditorAction(cutOrCopy); + String toFileName = testFileName.replace(".kt", ".to.kt"); JetFile toFile = configureToFile(toFileName); - myFixture.performEditorAction(IdeActions.ACTION_PASTE); + performNotWriteEditorAction(IdeActions.ACTION_PASTE); + myFixture.checkResultByFile(testFileName.replace(".kt", ".expected.kt")); + if (!InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile), ALLOW_UNRESOLVED_DIRECTIVE)) { checkNoUnresolvedReferences(toFile); }