From 228ff94d652ae9b16bc723bb5448196f4d7dc62b Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Fri, 18 Feb 2022 08:36:01 +0100 Subject: Find profile usages --- .../intellij/findUsages/FindDefinitionTest.java | 24 ---------- .../findUsages/FindFunctionDefinitionTest.java | 20 +++++++++ .../findUsages/FindFunctionUsagesTest.java | 42 ++++++++++++++++++ .../findUsages/FindRankProfileUsagesTest.java | 32 ++++++++++++++ .../vespa/intellij/findUsages/FindUsagesTest.java | 51 ---------------------- .../ai/vespa/intellij/findUsages/UsagesTester.java | 7 +++ 6 files changed, 101 insertions(+), 75 deletions(-) delete mode 100644 integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindDefinitionTest.java create mode 100644 integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionDefinitionTest.java create mode 100644 integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionUsagesTest.java create mode 100644 integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindRankProfileUsagesTest.java delete mode 100644 integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java (limited to 'integration/intellij/src/test') diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindDefinitionTest.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindDefinitionTest.java deleted file mode 100644 index 36fb842ce24..00000000000 --- a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindDefinitionTest.java +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.intellij.findUsages; - -import ai.vespa.intellij.PluginTestBase; -import com.intellij.usageView.UsageInfo; -import com.intellij.util.Processor; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author bratseth - */ -public class FindDefinitionTest extends PluginTestBase { - - @Test - public void testFindUsagesInRankProfileModularity() { - useDir("src/test/applications/rankprofilemodularity"); - var tester = new UsagesTester("test.sd", getProject()); - UsageInfo usage = tester.findFunctionDefinition("outside_schema1", 93); - } - -} diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionDefinitionTest.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionDefinitionTest.java new file mode 100644 index 00000000000..3ac45be4d9b --- /dev/null +++ b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionDefinitionTest.java @@ -0,0 +1,20 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.intellij.findUsages; + +import ai.vespa.intellij.PluginTestBase; +import com.intellij.usageView.UsageInfo; +import org.junit.Test; + +/** + * @author bratseth + */ +public class FindFunctionDefinitionTest extends PluginTestBase { + + @Test + public void testFindUsagesInRankProfileModularity() { + useDir("src/test/applications/rankprofilemodularity"); + var tester = new UsagesTester("test.sd", getProject()); + UsageInfo usage = tester.findFunctionDefinition("outside_schema1", 93); + } + +} diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionUsagesTest.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionUsagesTest.java new file mode 100644 index 00000000000..a5315cea8fe --- /dev/null +++ b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindFunctionUsagesTest.java @@ -0,0 +1,42 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.intellij.findUsages; + +import ai.vespa.intellij.PluginTestBase; +import com.intellij.usageView.UsageInfo; +import org.junit.Test; + +/** + * @author bratseth + */ +public class FindFunctionUsagesTest extends PluginTestBase { + + @Test + public void testFindUsagesInRankProfileModularity() { + useDir("src/test/applications/rankprofilemodularity"); + var tester = new UsagesTester("test.sd", getProject()); + tester.assertFunctionUsages("0 refs", 0, "in_schema1", "tensorFunction"); + tester.assertFunctionUsages("1 local ref in first-phase", 1, "in_schema2", "f2"); + tester.assertFunctionUsages("2 local refs", 2, "in_schema2", "ff1"); + tester.assertFunctionUsages("1 local ref", 1, "in_schema4", "f2"); + tester.assertFunctionUsages("1 local ref", 1, "outside_schema1", "local1"); + tester.assertFunctionUsages("4 local refs", 4, "outside_schema1", "local12"); + tester.assertFunctionUsages("3 refs in parent schema", 3, "outside_schema2", "fo2"); + } + + @Test + public void testFindUsagesInSchemaInheritance() { + useDir("src/test/applications/schemainheritance"); + var tester = new UsagesTester("parent.sd", getProject()); + tester.assertFunctionUsages("1 ref in child schema", 1, "parent_profile", "parentFunction"); + } + + @Test + public void testUsageDetails() { + useDir("src/test/applications/rankprofilemodularity"); + var tester = new UsagesTester("test.sd", getProject()); + UsageInfo usage = tester.assertFunctionUsages("1 local ref", 1, "outside_schema1", "local1").get(0); + assertEquals(93, usage.getNavigationOffset()); + assertEquals(93 + 6, usage.getNavigationRange().getEndOffset()); + } + +} diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindRankProfileUsagesTest.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindRankProfileUsagesTest.java new file mode 100644 index 00000000000..ef916d52c0d --- /dev/null +++ b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindRankProfileUsagesTest.java @@ -0,0 +1,32 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.intellij.findUsages; + +import ai.vespa.intellij.PluginTestBase; +import com.intellij.usageView.UsageInfo; +import org.junit.Test; + +/** + * @author bratseth + */ +public class FindRankProfileUsagesTest extends PluginTestBase { + + @Test + public void testFindUsagesInRankProfileModularity() { + useDir("src/test/applications/rankprofilemodularity"); + var tester = new UsagesTester("test.sd", getProject()); + tester.assertProfileUsages(2, "in_schema1"); + tester.assertProfileUsages(0, "in_schema2"); + tester.assertProfileUsages(1, "outside_schema1"); + tester.assertProfileUsages(4, "outside_schema2"); + } + + @Test + public void testFindUsagesInSchemaInheritance() { + useDir("src/test/applications/schemainheritance"); + var tester = new UsagesTester("parent.sd", getProject()); + UsageInfo usage = tester.assertProfileUsages(1, "parent_profile").get(0); + assertEquals(406, usage.getNavigationOffset()); + assertEquals(560, usage.getNavigationRange().getEndOffset()); + } + +} diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java deleted file mode 100644 index 141e5dd4b59..00000000000 --- a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.intellij.findUsages; - -import ai.vespa.intellij.PluginTestBase; -import ai.vespa.intellij.schema.findUsages.SdFindUsagesHandler; -import ai.vespa.intellij.schema.model.Schema; -import ai.vespa.intellij.schema.utils.Path; -import com.intellij.find.findUsages.FindUsagesOptions; -import com.intellij.openapi.project.Project; -import com.intellij.usageView.UsageInfo; -import com.intellij.util.Processor; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author bratseth - */ -public class FindUsagesTest extends PluginTestBase { - - @Test - public void testFindUsagesInRankProfileModularity() { - useDir("src/test/applications/rankprofilemodularity"); - var tester = new UsagesTester("test.sd", getProject()); - tester.assertFunctionUsages("0 refs", 0, "in_schema1", "tensorFunction"); - tester.assertFunctionUsages("1 local ref in first-phase", 1, "in_schema2", "f2"); - tester.assertFunctionUsages("2 local refs", 2, "in_schema2", "ff1"); - tester.assertFunctionUsages("1 local ref", 1, "in_schema4", "f2"); - tester.assertFunctionUsages("1 local ref", 1, "outside_schema1", "local1"); - tester.assertFunctionUsages("4 local refs", 4, "outside_schema1", "local12"); - tester.assertFunctionUsages("3 refs in parent schema", 3, "outside_schema2", "fo2"); - } - - @Test - public void testFindUsagesInSchemaInheritance() { - useDir("src/test/applications/schemainheritance"); - var tester = new UsagesTester("parent.sd", getProject()); - tester.assertFunctionUsages("1 ref in child schema", 1, "parent_profile", "parentFunction"); - } - - @Test - public void testUsageDetails() { - useDir("src/test/applications/rankprofilemodularity"); - var tester = new UsagesTester("test.sd", getProject()); - UsageInfo usage = tester.assertFunctionUsages("1 local ref", 1, "outside_schema1", "local1").get(0); - assertEquals(93, usage.getNavigationOffset()); - assertEquals(93 + 6, usage.getNavigationRange().getEndOffset()); - } - -} diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/UsagesTester.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/UsagesTester.java index f48ef7f107a..319240b9ceb 100644 --- a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/UsagesTester.java +++ b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/UsagesTester.java @@ -36,6 +36,13 @@ class UsagesTester { return usageProcessor.usages; } + List assertProfileUsages(int expectedUsages, String profileName) { + var profile = schema.rankProfiles().get(profileName).definition(); + findUsages(profile); + assertEquals(expectedUsages, usageProcessor.usages.size()); + return usageProcessor.usages; + } + /** Finds the function referred at the given character offset in the given profile. */ UsageInfo findFunctionDefinition(String profileName, int offset) { PsiElement referringElement = schema.rankProfiles().get(profileName).definition().findElementAt(offset); -- cgit v1.2.3