-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ METHOD_RETURN and MEMBER tests (#55)
* Failing tests for METHOD_RETURN nodes * MethodReturn tests * Add MEMBER tests
- Loading branch information
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
testing/src/test/scala/io/github/plume/oss/querying/MemberTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.plume.oss.querying | ||
|
||
import io.github.plume.oss.PlumeCodeToCpgSuite | ||
import io.shiftleft.semanticcpg.language._ | ||
|
||
class MemberTests extends PlumeCodeToCpgSuite { | ||
|
||
override val code = | ||
""" | ||
|class Foo { | ||
| int x; | ||
|} | ||
|""".stripMargin | ||
|
||
"should contain MEMBER node with correct properties" in { | ||
val List(x) = cpg.member.l | ||
x.name shouldBe "x" | ||
x.code shouldBe "int x" | ||
x.typeFullName shouldBe "int" | ||
x.order shouldBe 1 | ||
} | ||
|
||
"should allow traversing from MEMBER to TYPE_DECL" in { | ||
val List(x) = cpg.member.typeDecl.l | ||
x.name shouldBe "Foo" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
testing/src/test/scala/io/github/plume/oss/querying/MethodReturnTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.plume.oss.querying | ||
|
||
import io.github.plume.oss.PlumeCodeToCpgSuite | ||
import io.shiftleft.semanticcpg.language._ | ||
|
||
class MethodReturnTests extends PlumeCodeToCpgSuite { | ||
|
||
override val code = | ||
"""class Foo { | ||
| int foo() { return 1; } | ||
|} | ||
|""".stripMargin | ||
|
||
"should have METHOD_RETURN node with correct fields" in { | ||
val List(x) = cpg.methodReturn.code("int").l | ||
x.code shouldBe "int" | ||
x.typeFullName shouldBe "int" | ||
// I think line 2 would be correct but close enough | ||
// given that it's bytecode | ||
x.lineNumber shouldBe Some(1) | ||
// we expect the METHOD_RETURN node to be the right-most | ||
// child so that when traversing the AST from left to | ||
// right in CFG construction, we visit it last. | ||
x.order shouldBe 3 | ||
} | ||
|
||
"should allow traversing to method" in { | ||
cpg.methodReturn.code("int").method.name.l shouldBe List("foo") | ||
} | ||
|
||
} |