private void checkMatchFile(@NotNull GoBuildMatcher matcher, boolean expected, @NotNull String fileName, @NotNull String text) { myFixture.configureByText(fileName, text + "\n\n package main\n\n func main() {}"); assertEquals(fileName + ":" + text, expected, matcher.matchFile(myFixture.getFile())); } }
private void doTestWithExistingPackage(@NotNull String fileName, @NotNull String expectedPackage, @NotNull String expectedPackageWithTestSuffix) { myFixture.configureByText("a.go", "package a"); doTest(myFixture.getFile().getContainingDirectory(), fileName, expectedPackage, expectedPackageWithTestSuffix); }
private <T> void doTestGetUseScope(@NotNull String text, @NotNull Class<T> scope) { myFixture.configureByText("a.go", text); PsiFile file = myFixture.getFile(); GoVarDefinition var = PsiTreeUtil.findChildOfType(file, GoVarDefinition.class); assertNotNull(var); assertTrue(scope.isInstance(var.getUseScope())); }
public void testRetrieveBuildFlagsWithoutNewLineAfter() { myFixture.configureByText("a.go", "// Copyright 2009 The Go Authors. All rights reserved.\n" + "// Use of this source code is governed by a BSD-style\n" + "// license that can be found in the LICENSE file.\n" + "\n" + "// +build freebsd linux\n" + "package net\n"); assertNull(((GoFile)myFixture.getFile()).getBuildFlags()); }
public void testRetrieveBuildFlags() { myFixture.configureByText("a.go", "// Copyright 2009 The Go Authors. All rights reserved.\n" + "// Use of this source code is governed by a BSD-style\n" + "// license that can be found in the LICENSE file.\n" + "\n" + "// +build darwin dragonfly\n" + "\n" + "package net\n"); assertEquals("darwin dragonfly", ((GoFile)myFixture.getFile()).getBuildFlags()); }
public void testPackageNameOfTestFile() { myFixture.configureByText("foo_test.go", "package foo_test"); assertEquals("foo_test", ((GoFile)myFixture.getFile()).getPackageName()); }
public void testPackageNameOfNonTestPackageInTestFile() { myFixture.configureByText("foo_test.go", "package fooa"); assertEquals("fooa",((GoFile)myFixture.getFile()).getPackageName()); }
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); } }
protected void assertUnwrapped(@NotNull String codeBefore, @NotNull String codeAfter, int option) { myFixture.configureByText("a.go", normalizeCode(codeBefore)); UnwrapHandler h = new UnwrapHandler() { @Override protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) { if (options.isEmpty()) return; options.get(option).actionPerformed(null); } }; h.invoke(getProject(), myFixture.getEditor(), myFixture.getFile()); myFixture.checkResult(normalizeCode(codeAfter)); }
private <T extends GoExpression> void doTest(@NotNull String text, @NotNull Class<T> aClass, int expected) { myFixture.configureByText("a.go", text); PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()); T callExpr = PsiTreeUtil.getParentOfType(element, aClass); assertEquals(expected, GoInspectionUtil.getExpressionResultCount(callExpr)); }
private void doTest(@NotNull String text, String... usages) { myFixture.configureByText("foo.go", text); @SuppressWarnings("unchecked") HighlightUsagesHandlerBase<PsiElement> handler = HighlightUsagesHandler.createCustomHandler(myFixture.getEditor(), myFixture.getFile()); assertNotNull(handler); List<PsiElement> targets = handler.getTargets(); assertEquals(1, targets.size()); handler.computeUsages(targets); List<String> textUsages = ContainerUtil.map(handler.getReadUsages(), range -> range.substring(myFixture.getFile().getText())); assertSameElements(textUsages, usages); } }
protected void assertOptions(@NotNull String code, String... expectedOptions) { myFixture.configureByText("a.go", normalizeCode(code)); List<String> actualOptions = ContainerUtil.newArrayList(); UnwrapHandler h = new UnwrapHandler() { @Override protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) { actualOptions.addAll(options.stream().map(each -> each.getTemplatePresentation().getText()).collect(Collectors.toList())); } }; h.invoke(getProject(), myFixture.getEditor(), myFixture.getFile()); assertOrderedEquals(actualOptions, expectedOptions); } }
private Object[] getItemsToShow() { CreateParameterInfoContext createCtx = new MockCreateParameterInfoContext(myFixture.getEditor(), myFixture.getFile()); GoArgumentList psiElement = myParameterInfoHandler.findElementForParameterInfo(createCtx); assertNotNull(psiElement); myParameterInfoHandler.showParameterInfo(psiElement, createCtx); return createCtx.getItemsToShow(); }
public void testPackage_test() { PsiFile file = myFixture.addFileToProject("import/path/package_test.go", "package ma<caret>in; import `gopkg.in/check.v1`"); myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); doTestProducedConfigurations(myFixture.getFile().findElementAt(myFixture.getCaretOffset())); }
private int getHighlightedItem() { MockUpdateParameterInfoContext updateCtx = new MockUpdateParameterInfoContext(myFixture.getEditor(), myFixture.getFile()); GoArgumentList psiElement = myParameterInfoHandler.findElementForUpdatingParameterInfo(updateCtx); assertNotNull(psiElement); myParameterInfoHandler.updateParameterInfo(psiElement, updateCtx); return updateCtx.getCurrentParameter(); }
public void testPackageNameOfTestPackageInNonTestFile() { myFixture.configureByText("foo.go", "package foo"); myFixture.configureByText("foo_test.go", "package foo_test"); myFixture.configureByText("main.go", "package main"); myFixture.configureByText("docs.go", "package documentation"); myFixture.configureByText("bar_test.go", "package tricky_package_name"); myFixture.configureByText("non_test_file.go", "package non_test"); myFixture.configureByText("ignored.go", "// +build ignored\n\npackage ignored"); assertSameElements(GoPackageUtil.getAllPackagesInDirectory(myFixture.getFile().getContainingDirectory(), null, true), "foo", "main", "non_test", "tricky_package_name"); assertSameElements(GoPackageUtil.getAllPackagesInDirectory(myFixture.getFile().getContainingDirectory(), null, false), "foo", "foo_test", "main", "non_test", "tricky_package_name"); }
private void doTest(boolean replaceAll) { String testName = getTestName(true); myFixture.configureByFile(testName + ".go"); GoIntroduceVariableBase.performAction(new GoIntroduceOperation(getProject(), myFixture.getEditor(), myFixture.getFile(), replaceAll)); myFixture.checkResultByFile(testName + "-after.go"); }
public void testSdkTestDataDirectory() { myFixture.configureByText("a.go", "package a; import `doc/testdata`; func _() { println(pkg.ExportedConst<caret>ant) } "); PsiReference reference = myFixture.getFile().findReferenceAt(myFixture.getCaretOffset()); PsiElement resolve = reference != null ? reference.resolve() : null; assertNotNull(resolve); assertEquals("pkg.go", resolve.getContainingFile().getName()); assertEmpty(myFixture.findUsages(resolve)); }
public void testCgoCImport() { myFixture.configureByText("a.go", "package a; import \"C\""); PsiFile file = myFixture.getFile(); assertTrue(new GoBuildMatcher(new GoTargetSystem("linux", "amd64", "1.4", null, ThreeState.YES)).matchFile(file)); assertFalse(new GoBuildMatcher(new GoTargetSystem("linux", "amd64", "1.4", null, ThreeState.NO)).matchFile(file)); }
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> }"); }