-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rubysrc2cpg] Unit Tests for Identifier Nodes (#3075)
1. `identifier` to `method parameter in` traversal 2. `identifier` to `local` traversal 3. across the file additional unit test
- Loading branch information
1 parent
1545988
commit 3ef1614
Showing
3 changed files
with
131 additions
and
0 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
87 changes: 87 additions & 0 deletions
87
...nds/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/passes/ast/IdentifierLocalTests.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,87 @@ | ||
package io.joern.rubysrc2cpg.passes.ast | ||
|
||
import io.joern.rubysrc2cpg.testfixtures.RubyCode2CpgFixture | ||
import io.shiftleft.semanticcpg.language._ | ||
|
||
class IdentifierLocalTests extends RubyCode2CpgFixture { | ||
|
||
val cpg = code(""" | ||
|def method1() | ||
| x = 1 | ||
| x = 2 | ||
|end | ||
| | ||
|def method2(x) | ||
| x = 2 | ||
|end | ||
| | ||
|def method3(x) | ||
| y = 0 | ||
| | ||
| if true | ||
| innerx = 0 | ||
| innery = 0 | ||
| | ||
| innerx = 1 | ||
| innery = 1 | ||
| end | ||
| | ||
| x = 1 | ||
| y = 1 | ||
|end | ||
| | ||
|""".stripMargin) | ||
|
||
// TODO: Need to be fixed. | ||
"be correct for local x in method1" ignore { | ||
val List(method) = cpg.method.nameExact("method1").l | ||
method.block.ast.isIdentifier.l.size shouldBe 2 | ||
val List(indentifierX, _) = method.block.ast.isIdentifier.l | ||
indentifierX.name shouldBe "x" | ||
|
||
val localX = indentifierX._localViaRefOut.get | ||
localX.name shouldBe "x" | ||
} | ||
|
||
// TODO: Need to be fixed | ||
"be correct for parameter x in method2" ignore { | ||
val List(method) = cpg.method.nameExact("method2").l | ||
val List(indentifierX) = method.block.ast.isIdentifier.l | ||
indentifierX.name shouldBe "x" | ||
|
||
indentifierX.refsTo.l.size shouldBe 1 | ||
val List(paramx) = indentifierX.refsTo.l | ||
paramx.name shouldBe "x" | ||
|
||
val parameterX = indentifierX._methodParameterInViaRefOut.get | ||
parameterX.name shouldBe "x" | ||
} | ||
|
||
// TODO: Need to be fixed. | ||
"Reach parameter from last identifer" ignore { | ||
val List(method) = cpg.method.nameExact("method3").l | ||
val List(outerIdentifierX) = method.ast.isIdentifier.lineNumber(22).l | ||
val parameterX = outerIdentifierX._methodParameterInViaRefOut.get | ||
parameterX.name shouldBe "x" | ||
} | ||
|
||
// TODO: Need to be fixed. | ||
"inner block test" ignore { | ||
val List(method) = cpg.method.nameExact("method3").l | ||
method.block.astChildren.isBlock.l.size shouldBe 1 | ||
val List(nestedBlock) = method.block.astChildren.isBlock.l | ||
nestedBlock.ast.isIdentifier.nameExact("innerx").l.size shouldBe 2 | ||
} | ||
|
||
// TODO: Need to be fixed. | ||
"nested block identifer to local taversal" ignore { | ||
val List(method) = cpg.method.nameExact("method3").l | ||
method.block.astChildren.isBlock.l.size shouldBe 1 | ||
val List(nestedBlock) = method.block.astChildren.isBlock.l | ||
nestedBlock.ast.isIdentifier.nameExact("innerx").l.size shouldBe 2 | ||
val List(nestedIdentifierX, _) = nestedBlock.ast.isIdentifier.nameExact("innerx").l | ||
|
||
val nestedLocalX = nestedIdentifierX._localViaRefOut.get | ||
nestedLocalX.name shouldBe "innerx" | ||
} | ||
} |
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