forked from joernio/joern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ruby] Here-Docs Pt 1 (joernio#4322)
* [ruby] Fixed the trivial here-doc impl, just enough so the parser doesn't fall over anymore * [ruby] Removed import on heredochandling, simplified tests for heredoc * [ruby] Changed type on heredoc to heredoc, added test for heredoc in assingment * PR comments
- Loading branch information
1 parent
4314950
commit 9a30dda
Showing
7 changed files
with
97 additions
and
6 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
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
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
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
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
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
67 changes: 67 additions & 0 deletions
67
...cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/querying/HereDocTests.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,67 @@ | ||
package io.joern.rubysrc2cpg.querying | ||
|
||
import io.joern.rubysrc2cpg.testfixtures.RubyCode2CpgFixture | ||
import io.shiftleft.codepropertygraph.generated.nodes.{Call, Literal, Local, Method, Return} | ||
import io.shiftleft.semanticcpg.language.* | ||
|
||
class HereDocTests extends RubyCode2CpgFixture { | ||
|
||
"HereDoc simple" should { | ||
val cpg = code(""" | ||
| def f() | ||
| a = 10 | ||
| <<-SQL | ||
| this is some sql heredoc code | ||
| SQL | ||
| a | ||
| end | ||
|""".stripMargin) | ||
|
||
"have a LITERAL node" in { | ||
inside(cpg.method.name("f").l) { | ||
case func :: Nil => | ||
inside(func.block.astChildren.l) { | ||
case (localAst: Local) :: (callAst: Call) :: (literalAst: Literal) :: (returnAst: Return) :: Nil => | ||
localAst.code shouldBe "a" | ||
callAst.code shouldBe "a = 10" | ||
|
||
literalAst.typeFullName shouldBe "__builtin.String" | ||
|
||
returnAst.code shouldBe "a" | ||
case _ => | ||
} | ||
case _ => fail("Expected one method for f") | ||
} | ||
} | ||
} | ||
|
||
"HereDoc as function argument" should { | ||
val cpg = code(""" | ||
|def foo() | ||
| a = <<-SQL | ||
| SELECT * FROM TABLE; | ||
| SQL | ||
| | ||
| a | ||
|end | ||
|""".stripMargin) | ||
|
||
"parse Heredocs" in { | ||
inside(cpg.method.name("foo").l) { | ||
case fooFunc :: Nil => | ||
inside(fooFunc.block.astChildren.isCall.l) { | ||
case assignmentCall :: Nil => | ||
inside(assignmentCall.argument.l) { | ||
case lhsArg :: (rhsArg: Literal) :: Nil => | ||
lhsArg.code shouldBe "a" | ||
rhsArg.typeFullName shouldBe "__builtin.String" | ||
case _ => fail("Expected LHS and RHS for assignment") | ||
} | ||
case _ => fail("Expected call for assignment") | ||
} | ||
case _ => fail("Expected one method for foo") | ||
} | ||
} | ||
} | ||
|
||
} |