diff --git a/presentation-compiler/src/test/scala/org/alephium/ralph/lsp/pc/search/completion/FunctionBodyCompleterSpec.scala b/presentation-compiler/src/test/scala/org/alephium/ralph/lsp/pc/search/completion/FunctionBodyCompleterSpec.scala index b80c224b4..202e9394b 100644 --- a/presentation-compiler/src/test/scala/org/alephium/ralph/lsp/pc/search/completion/FunctionBodyCompleterSpec.scala +++ b/presentation-compiler/src/test/scala/org/alephium/ralph/lsp/pc/search/completion/FunctionBodyCompleterSpec.scala @@ -16,6 +16,7 @@ package org.alephium.ralph.lsp.pc.search.completion +import org.alephium.ralph.Ast import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec import org.alephium.ralph.lsp.pc.search.TestCodeProvider._ @@ -447,6 +448,69 @@ class FunctionBodyCompleterSpec extends AnyWordSpec with Matchers { actual.sortBy(_.label) shouldBe expected.sortBy(_.label) } + + "global enums exist" in { + val suggestions = + suggest { + """ + |enum GlobalEnumTop { + | ONE = 1 + | TWO = 2 + |} + | + |Contract Foo() { + | + | enum LocalEnum { + | THREE = 3 + | FOUR = 4 + | } + | + | pub fn test() -> () { + | @@ + | } + |} + | + |enum GlobalEnumBottom { + | FIVE = 5 + | SIX = 6 + |} + |""".stripMargin + } + + val actual = + suggestions + .collect { + case enums: Suggestion.EnumDef => + enums + + case enumCreatedTypes: Suggestion.CreatedType if enumCreatedTypes.node.source.tree.ast.isInstanceOf[Ast.EnumDef[_]] => + enumCreatedTypes + } + .flatMap(_.toCompletion()) + + // FIXME: Global enums should not be suggested as Classes. This is the case right now because + // All `GlobalDefinition`s that contain `typeId` are returned as Suggestion.CreatedInstance. + val expected = + List( + Completion.Enum( + label = "LocalEnum", + insert = "LocalEnum", + detail = "" + ), + Completion.Class( + label = "GlobalEnumTop", + insert = "GlobalEnumTop", + detail = "" + ), + Completion.Class( + label = "GlobalEnumBottom", + insert = "GlobalEnumBottom", + detail = "" + ) + ) + + actual.sortBy(_.label) shouldBe expected.sortBy(_.label) + } } "TxScript" should {