Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add tests for pc info #6198

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scala.meta.pc.HoverSignature
import scala.meta.pc.InlayHintsParams
import scala.meta.pc.Node
import scala.meta.pc.OffsetParams
import scala.meta.pc.PcSymbolInformation
import scala.meta.pc.PresentationCompiler
import scala.meta.pc.PresentationCompilerConfig
import scala.meta.pc.RangeParams
Expand Down Expand Up @@ -110,6 +111,11 @@ case class ScalaPresentationCompiler(
): CompletableFuture[ju.Optional[HoverSignature]] =
underlying.hover(params)

override def info(
symbol: String
): CompletableFuture[ju.Optional[PcSymbolInformation]] =
underlying.info(symbol)

override def convertToNamedArguments(
params: OffsetParams,
argIndices: ju.List[Integer],
Expand Down
62 changes: 62 additions & 0 deletions tests/cross/src/test/scala/tests/pc/InfoSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package tests.pc

import scala.meta.internal.jdk.CollectionConverters._
import scala.meta.pc.PcSymbolInformation
import scala.meta.pc.PcSymbolKind
import scala.meta.pc.PcSymbolProperty

import tests.BasePCSuite

class InfoSuite extends BasePCSuite {

def getInfo(symbol: String): PcSymbolInformation = {
val result = presentationCompiler.info(symbol).get()
assert(result.isPresent(), s"no info returned for symbol $symbol")
assertNoDiff(result.get().symbol(), symbol)
result.get()
}

test("list") {
val info = getInfo("scala/collection/immutable/List#")
assert(info.properties().contains(PcSymbolProperty.ABSTRACT))
assert(info.parents().contains("scala/collection/immutable/LinearSeq#"))
}

test("empty-list-constructor") {
val info = getInfo("scala/collection/immutable/List.empty().")
assertNoDiff(info.classOwner(), "scala/collection/immutable/List.")
assertEquals(info.kind(), PcSymbolKind.METHOD)
}

test("assert") {
val info = getInfo("scala/Predef.assert().")
assertEquals(info.kind(), PcSymbolKind.METHOD)
assertNoDiff(info.classOwner(), "scala/Predef.")
assertEquals(
info.alternativeSymbols().asScala.mkString("\n"),
"scala/Predef.assert(+1)."
)
}

test("flatMap") {
val info = getInfo("scala/collection/immutable/List#flatMap().")
assertEquals(info.kind(), PcSymbolKind.METHOD)
assertNoDiff(info.classOwner(), "scala/collection/immutable/List#")
val correctOverridden =
if (scalaVersion.startsWith("2.12") || scalaVersion.startsWith("2.11")) {
"""|scala/collection/TraversableLike#flatMap().
|scala/collection/GenTraversableLike#flatMap().
|scala/collection/generic/FilterMonadic#flatMap().
|""".stripMargin
} else {
"""|scala/collection/StrictOptimizedIterableOps#flatMap().
|scala/collection/IterableOps#flatMap().
|scala/collection/IterableOnceOps#flatMap().
|""".stripMargin
}
assertNoDiff(
info.overriddenSymbols().asScala.mkString("\n"),
correctOverridden
)
}
}
Loading