-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[swiftsrc2cpg] Initial work to get file content going (#4169)
- Loading branch information
1 parent
4777e41
commit 33ddb87
Showing
3 changed files
with
63 additions
and
11 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
33 changes: 33 additions & 0 deletions
33
...ends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/io/CodeDumperFromContentTest.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,33 @@ | ||
package io.joern.swiftsrc2cpg.io | ||
|
||
import io.joern.swiftsrc2cpg.testfixtures.SwiftSrc2CpgSuite | ||
import io.joern.swiftsrc2cpg.Config | ||
import io.shiftleft.semanticcpg.language.* | ||
|
||
class CodeDumperFromContentTest extends SwiftSrc2CpgSuite { | ||
|
||
private val codeString = """ | ||
|// A comment | ||
|func my_func(param1: Int) -> Int { | ||
| let x: Int = foo(p: param1) | ||
|}""".stripMargin | ||
|
||
"dumping code from content" should { | ||
implicit val finder: NodeExtensionFinder = DefaultNodeExtensionFinder | ||
|
||
val cpg = code(codeString, "test.swift").withConfig(Config().withDisableFileContent(false)) | ||
|
||
"allow one to dump a method node's source code from `File.contents`" in { | ||
inside(cpg.method.nameExact("my_func").dumpRaw.l) { | ||
case content :: Nil => | ||
content.linesIterator.map(_.strip).l shouldBe List( | ||
"func my_func(param1: Int) -> Int { /* <=== test.swift:<global>:my_func */", | ||
"let x: Int = foo(p: param1)", | ||
"}" | ||
) | ||
case content => fail(s"Expected exactly 1 content dump, but got: $content") | ||
} | ||
} | ||
} | ||
|
||
} |
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