Skip to content

Commit

Permalink
tests: add tests for pc info
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Mar 12, 2024
1 parent 9590166 commit ad46b2b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
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
)
}
}

0 comments on commit ad46b2b

Please sign in to comment.