@NotNull private GoStringLiteral createRawStringFromText(@NotNull String text) { return GoElementFactory.createStringLiteral(myFixture.getProject(), String.format(Locale.US, "`%s`", text)); } }
@NotNull private GoStringLiteral createStringFromText(@NotNull String text) { return GoElementFactory.createStringLiteral(myFixture.getProject(), String.format(Locale.US, "\"%s\"", text)); }
@NotNull private GoCoverageProjectData parseData(@NotNull String coverageSource) throws IOException { try (BufferedReader reader = new BufferedReader(new FileReader(new File(getTestDataPath(), coverageSource)))) { GoCoverageProjectData data = GoCoverageRunner.parseCoverage(reader, myFixture.getProject(), myModule); assertNotNull(data); return data; } }
@NotNull private GoCoverageAnnotator annotate(@NotNull GoCoverageProjectData data) { GoCoverageAnnotator annotator = new GoCoverageAnnotator(myFixture.getProject()); annotator.annotateAllFiles(data, getRoot()); return annotator; }
private GoRunFileConfiguration createFileConfiguration(String filePath) { GoRunFileConfigurationType type = GoRunFileConfigurationType.getInstance(); GoRunFileConfiguration result = new GoRunFileConfiguration(myFixture.getProject(), "run file", type); result.setFilePath(filePath); return result; }
private String doTest(@Nullable Character c, String testName) { if (c == null) { WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> { CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile()); }); } else { myFixture.type(c); } return String.format("%s-after.go", testName); } }
@NotNull private GoTestRunConfiguration createFileConfiguration(GoTestFramework framework, String path) { GoTestRunConfigurationType configurationType = GoTestRunConfigurationType.getInstance(); GoTestRunConfiguration runConfiguration = new GoTestRunConfiguration(myFixture.getProject(), "name", configurationType); runConfiguration.setFilePath(path); runConfiguration.setKind(GoTestRunConfiguration.Kind.FILE); runConfiguration.setTestFramework(framework); return runConfiguration; }
private GoApplicationConfiguration createRunAppFileConfiguration(String filePath) { GoRunFileConfigurationType type = GoRunFileConfigurationType.getInstance(); GoApplicationConfiguration result = new GoApplicationConfiguration(myFixture.getProject(), "run file", type); result.setKind(GoApplicationConfiguration.Kind.FILE); result.setFilePath(filePath); return result; }
private GoApplicationConfiguration createRunAppPackageConfiguration(String importPath) { GoApplicationRunConfigurationType type = GoApplicationRunConfigurationType.getInstance(); GoApplicationConfiguration result = new GoApplicationConfiguration(myFixture.getProject(), "run package", type); result.setKind(GoApplicationConfiguration.Kind.PACKAGE); result.setPackage(importPath); return result; }
@NotNull private GoTestRunConfiguration createDirectoryConfiguration(GoTestFramework framework, String path, String workingDirectoryPath) { GoTestRunConfigurationType configurationType = GoTestRunConfigurationType.getInstance(); GoTestRunConfiguration runConfiguration = new GoTestRunConfiguration(myFixture.getProject(), "name", configurationType); runConfiguration.setDirectoryPath(path); runConfiguration.setWorkingDirectory(workingDirectoryPath); runConfiguration.setKind(GoTestRunConfiguration.Kind.DIRECTORY); runConfiguration.setTestFramework(framework); return runConfiguration; }
@NotNull private GoTestRunConfiguration createPackageConfiguration(GoTestFramework framework, String pattern, String importPath) { GoTestRunConfigurationType configurationType = GoTestRunConfigurationType.getInstance(); GoTestRunConfiguration runConfiguration = new GoTestRunConfiguration(myFixture.getProject(), "name", configurationType); runConfiguration.setPattern(pattern); runConfiguration.setPackage(importPath); runConfiguration.setKind(GoTestRunConfiguration.Kind.PACKAGE); runConfiguration.setTestFramework(framework); return runConfiguration; }
private void doAddImportTest() { myFixture.configureByFile(getTestName(true) + ".go"); WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> { ((GoFile)myFixture.getFile()).addImport("package/path", null); }); myFixture.checkResultByFile(getTestName(true) + "_after.go"); }
private int search(final String pattern, String input) { myFixture.configureByText("a.java", input); final Editor editor = myFixture.getEditor(); final Project project = myFixture.getProject(); final SearchGroup searchGroup = VimPlugin.getSearch(); final Ref<Integer> ref = Ref.create(-1); RunnableHelper.runReadCommand(project, new Runnable() { @Override public void run() { final int n = searchGroup.search(editor, pattern, 1, Command.FLAG_SEARCH_FWD, false); ref.set(n); } }, null, null); return ref.get(); } }
protected void doTest(@NotNull String codeBefore, @NotNull String expectedCodeAfter, @NotNull String surrounderDescription, boolean apply) { PsiFile file = myFixture.configureByText("a.go", normalizeCode(codeBefore)); List<AnAction> applicable = SurroundWithHandler.buildSurroundActions(myFixture.getProject(), myFixture.getEditor(), file, null); if (applicable == null) { assertFalse(apply); return; } String suffix = ". " + surrounderDescription; for (AnAction action : applicable) { String actionPresentation = action.getTemplatePresentation().getText(); if (actionPresentation != null && StringUtil.endsWith(actionPresentation, suffix)) { assertTrue(apply); myFixture.testAction(action); return; } } if (apply) { myFixture.checkResult(normalizeCode(expectedCodeAfter), true); } } }
public void testUndo() { DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); updateSettings(true); myFixture.configureByText("a.go", "package main\n\nfunc main() { <caret> }"); myFixture.type("fmt."); myFixture.doHighlighting(); myFixture.doHighlighting(); myFixture.checkResult("package main\n\nimport \"fmt\"\n\nfunc main() { fmt. }"); FileEditor editor = FileEditorManager.getInstance(myFixture.getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile()); UndoManager.getInstance(myFixture.getProject()).undo(editor); myFixture.checkResult("package main\n\nfunc main() { <caret> }"); }
private void setUpProjectSdk() { ApplicationManager.getApplication().runWriteAction(() -> { Sdk sdk = getProjectDescriptor().getSdk(); ProjectJdkTable.getInstance().addJdk(sdk); ProjectRootManager.getInstance(myFixture.getProject()).setProjectSdk(sdk); }); }
@Override protected void setUp() throws Exception { super.setUp(); VirtualFile workingDirectory = createTestRoot("workingDirectory"); VirtualFile goPath = createTestRoot("goPath"); GoApplicationLibrariesService.getInstance().setLibraryRootUrls(goPath.getUrl()); myFilter = new GoConsoleFilter(myFixture.getProject(), myFixture.getModule(), workingDirectory.getUrl()); }
protected void setUpProjectSdk() { ApplicationManager.getApplication().runWriteAction(() -> { Sdk sdk = getProjectDescriptor().getSdk(); ProjectJdkTable.getInstance().addJdk(sdk); ProjectRootManager.getInstance(myFixture.getProject()).setProjectSdk(sdk); }); }
protected void doTest() { Executor executor = new DefaultRunExecutor(); GoTestRunConfiguration runConfig = new GoTestRunConfiguration(myFixture.getProject(), "", GoTestRunConfigurationType.getInstance()); runConfig.setTestFramework(getTestFramework()); GoTestConsoleProperties consoleProperties = new GoTestConsoleProperties(runConfig, executor); GoTestEventsConverterBase converter = (GoTestEventsConverterBase)consoleProperties.createTestEventsConverter("gotest", consoleProperties); LoggingServiceMessageVisitor serviceMessageVisitor = new LoggingServiceMessageVisitor(); try { for (String line : FileUtil.loadLines(new File(getTestDataPath(), getTestName(true) + ".txt"), CharsetToolkit.UTF8)) { converter.processServiceMessages(line + "\n", ProcessOutputTypes.STDOUT, serviceMessageVisitor); } } catch (IOException | ParseException e) { throw new RuntimeException(e); } ((OutputToGeneralTestEventsConverter)converter).flushBufferBeforeTerminating(); Disposer.dispose((OutputToGeneralTestEventsConverter)converter); assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + "-expected.txt", serviceMessageVisitor.getLog()); }
public void testImportPackageWithoutBuildableSource() { PsiFile file = myFixture.addFileToProject("withSources/a.go", "package withSources"); myFixture.addFileToProject("withIgnoredFiles/a.go", "package documentation"); myFixture.addFileToProject("withIgnoredFiles/.b.go", "package withIgnoredFiles"); myFixture.addFileToProject("withIgnoredFiles/_b.go", "package withIgnoredFiles"); WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> { //noinspection ConstantConditions file.getParent().getParent().createSubdirectory("withoutSources"); }); myFixture.configureByText("a.go", "package pack\n" + "import `withSources`\n" + "import <error descr=\"'/src/withIgnoredFiles' has no buildable Go source files\">`withIgnoredFiles`</error>\n" + "import <error descr=\"'/src/withoutSources' has no buildable Go source files\">`withoutSources`</error>\n" + "import <error descr=\"'/src/withoutSources' has no buildable Go source files\">_ `without<caret>Sources`</error>\n" + "import `unresolved`\n"); myFixture.checkHighlighting(); applySingleQuickFix(GoDeleteImportQuickFix.QUICK_FIX_NAME); myFixture.checkResult("package pack\n" + "import `withSources`\n" + "import `withIgnoredFiles`\n" + "import `withoutSources`\n" + "import `unresolved`\n"); }