From 060988637946a0f2c0c89bd9cc6bc02f7a36c0a8 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 4 Mar 2024 15:27:08 +0100 Subject: [PATCH] tests: add tests for pc `info` --- .../src/test/scala/tests/pc/InfoSuite.scala | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/cross/src/test/scala/tests/pc/InfoSuite.scala diff --git a/tests/cross/src/test/scala/tests/pc/InfoSuite.scala b/tests/cross/src/test/scala/tests/pc/InfoSuite.scala new file mode 100644 index 00000000000..fbad9edca9f --- /dev/null +++ b/tests/cross/src/test/scala/tests/pc/InfoSuite.scala @@ -0,0 +1,62 @@ +package tests.pc + +import scala.meta.internal.jdk.CollectionConverters._ +import scala.meta.pc.PcSymbolKind +import scala.meta.pc.PcSymbolProperty + +import tests.BasePCSuite +import scala.meta.pc.PcSymbolInformation + +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 + ) + } +}