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

document propertyOption accessors with test #4382

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Changes from 1 commit
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 @@ -11,6 +11,7 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.traversal.help.Table.{AvailableWidthProvider, ConstantWidth}

import java.util.Optional
import scala.jdk.CollectionConverters.IteratorHasAsScala

class StepsTest extends AnyWordSpec with Matchers {
Expand Down Expand Up @@ -355,4 +356,34 @@ class StepsTest extends AnyWordSpec with Matchers {
assertDoesNotCompile("cpg.id(1).outV") // `.outV` is only available on Traversal[Edge]
}

"property accessors" in {
val cpg = MockCpg().withCustom { (diffGraph, _) =>
diffGraph
.addNode(NewCall())
.addNode(NewCall()
.typeFullName("aa") // Cardinality.One
.argumentName("bb") // Cardinality.ZeroOrOne
.dynamicTypeHintFullName(Seq("cc", "dd")) // Cardinality.List
)
}.cpg

val (Seq(emptyCall), Seq(callWithProperties)) = cpg.call.l.partition(_.argumentName.isEmpty)

emptyCall.propertyOption(Properties.TYPE_FULL_NAME) shouldBe Optional.of("<empty>")
emptyCall.propertyOption(Properties.TYPE_FULL_NAME.name) shouldBe Optional.of("<empty>")
emptyCall.propertyOption(Properties.ARGUMENT_NAME) shouldBe Optional.empty
emptyCall.propertyOption(Properties.ARGUMENT_NAME.name) shouldBe Optional.empty
// these ones are rather a historic accident it'd be better and more consistent to return `None` here -
// we'll defer that change until after the flatgraph port though and just document it for now
emptyCall.propertyOption(Properties.DYNAMIC_TYPE_HINT_FULL_NAME) shouldBe Optional.of(Seq.empty)
emptyCall.propertyOption(Properties.DYNAMIC_TYPE_HINT_FULL_NAME.name) shouldBe Optional.of(Seq.empty)

callWithProperties.propertyOption(Properties.TYPE_FULL_NAME) shouldBe Optional.of("aa")
callWithProperties.propertyOption(Properties.TYPE_FULL_NAME.name) shouldBe Optional.of("aa")
callWithProperties.propertyOption(Properties.ARGUMENT_NAME) shouldBe Optional.of("bb")
callWithProperties.propertyOption(Properties.ARGUMENT_NAME.name) shouldBe Optional.of("bb")
callWithProperties.propertyOption(Properties.DYNAMIC_TYPE_HINT_FULL_NAME) shouldBe Optional.of(Seq("cc", "dd"))
callWithProperties.propertyOption(Properties.DYNAMIC_TYPE_HINT_FULL_NAME.name) shouldBe Optional.of(Seq("cc", "dd"))
}

}
Loading