Skip to content

Commit d639bac

Browse files
committed
Colocate aggregator parser tests as Java/JUnit in scip-aggregator
Rewrite SymbolDescriptorSuite and JdkPackageSuite as JUnit 5 tests next to the code under test; wire jupiter-interface (test scope) into the scip project.
1 parent 8677e7b commit d639bac

5 files changed

Lines changed: 95 additions & 65 deletions

File tree

build.sbt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ lazy val scip = project
164164
moduleName := "scip-aggregator",
165165
javaOnlySettings,
166166
libraryDependencies ++=
167-
Seq("org.scip-code" % "scip-java-bindings" % V.scipBindings),
167+
Seq(
168+
"org.scip-code" % "scip-java-bindings" % V.scipBindings,
169+
// JUnit 5 for the colocated Java unit tests (test scope only, so it is
170+
// excluded from the published POM and keeps this a Java-only module).
171+
"com.github.sbt.junit" % "jupiter-interface" %
172+
JupiterKeys.jupiterVersion.value % Test
173+
),
168174
(Compile / PB.targets) :=
169175
Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value),
170176
Compile / PB.protocOptions := Seq("--experimental_allow_proto3_optional")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.sourcegraph.scip_aggregator;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
/**
8+
* Colocated unit test for {@link JdkPackage#parse}. Migrated from the former Scala JdkPackageSuite
9+
* in tests/unit.
10+
*/
11+
class JdkPackageTest {
12+
13+
@Test
14+
void keepsMajorVersionJdk11() {
15+
assertEquals("11", JdkPackage.parse("11.0.9").version);
16+
}
17+
18+
@Test
19+
void keepsMajorVersionJdk17() {
20+
assertEquals("17", JdkPackage.parse("17.0.5").version);
21+
}
22+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.sourcegraph.scip_aggregator;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.sourcegraph.scip.ScipSymbols.Descriptor.Kind;
6+
import org.junit.jupiter.api.Test;
7+
8+
/**
9+
* Colocated unit test for {@link SymbolDescriptor#parseFromSymbol}. Migrated from the former Scala
10+
* SymbolDescriptorSuite in tests/unit; the expected (kind, name, owner) triples follow the SCIP
11+
* symbol grammar.
12+
*/
13+
class SymbolDescriptorTest {
14+
15+
private static void check(String symbol, Kind kind, String name, String owner) {
16+
SymbolDescriptor obtained = SymbolDescriptor.parseFromSymbol(symbol);
17+
assertEquals(name, obtained.descriptor.name, symbol);
18+
assertEquals(owner, obtained.owner, symbol);
19+
assertEquals(kind, obtained.descriptor.kind, symbol);
20+
}
21+
22+
@Test
23+
void topLevelType() {
24+
check("Test#", Kind.Type, "Test", "_root_/");
25+
}
26+
27+
@Test
28+
void typeInPackage() {
29+
check("sample/Test#", Kind.Type, "Test", "sample/");
30+
}
31+
32+
@Test
33+
void method() {
34+
check("sample/Test#m1().", Kind.Method, "m1", "sample/Test#");
35+
}
36+
37+
@Test
38+
void parameter() {
39+
check("sample/Test#m1().(t1)", Kind.Parameter, "t1", "sample/Test#m1().");
40+
}
41+
42+
@Test
43+
void typeParameter() {
44+
check("sample/Test#m1().[T1]", Kind.TypeParameter, "T1", "sample/Test#m1().");
45+
}
46+
47+
@Test
48+
void term() {
49+
check("sample/Test#field.", Kind.Term, "field", "sample/Test#");
50+
}
51+
52+
@Test
53+
void constructor() {
54+
check("sample/Test#`<init>`().", Kind.Method, "<init>", "sample/Test#");
55+
}
56+
57+
@Test
58+
void innerType() {
59+
check("sample/Test#Inner#", Kind.Type, "Inner", "sample/Test#");
60+
}
61+
62+
@Test
63+
void packageDescriptor() {
64+
check("sample/", Kind.Package, "sample", "_root_/");
65+
}
66+
}

tests/unit/src/test/scala/tests/JdkPackageSuite.scala

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/unit/src/test/scala/tests/SymbolDescriptorSuite.scala

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)