-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…5187) * [c#] take into account global using directives * update typesInScope instead of findGlobalTypes
- Loading branch information
1 parent
5b77dea
commit a2eba41
Showing
4 changed files
with
75 additions
and
7 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
59 changes: 59 additions & 0 deletions
59
...sharpsrc2cpg/src/test/scala/io/joern/csharpsrc2cpg/querying/ast/UsingDirectiveTests.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,59 @@ | ||
package io.joern.csharpsrc2cpg.querying.ast | ||
|
||
import io.joern.csharpsrc2cpg.testfixtures.CSharpCode2CpgFixture | ||
import io.shiftleft.semanticcpg.language.* | ||
|
||
class UsingDirectiveTests extends CSharpCode2CpgFixture { | ||
|
||
"`global using` directive in another file" should { | ||
val cpg = code(""" | ||
|class Foo | ||
|{ | ||
| static void Run() | ||
| { | ||
| Console.WriteLine("Hello"); | ||
| } | ||
|}""".stripMargin) | ||
.moreCode( | ||
""" | ||
|global using System; | ||
|""".stripMargin, | ||
"globals.cs" | ||
) | ||
|
||
"make the imported namespace available in the current file" in { | ||
inside(cpg.call("WriteLine").l) { | ||
case writeLine :: Nil => | ||
writeLine.methodFullName shouldBe "System.Console.WriteLine:System.Void(System.String)" | ||
case xs => | ||
fail(s"Expected single WriteLine call, but found $xs") | ||
} | ||
} | ||
} | ||
|
||
"`using` directive in another file" should { | ||
val cpg = code(""" | ||
|class Foo | ||
|{ | ||
| static void Run() | ||
| { | ||
| Console.WriteLine("Hello"); | ||
| } | ||
|}""".stripMargin) | ||
.moreCode( | ||
""" | ||
|using System; | ||
|""".stripMargin, | ||
"dummy.cs" | ||
) | ||
|
||
"not affect the imported namespaces in the current file" in { | ||
inside(cpg.call("WriteLine").l) { | ||
case writeLine :: Nil => | ||
writeLine.methodFullName shouldBe "<unresolvedNamespace>.WriteLine:<unresolvedSignature>" | ||
case xs => | ||
fail(s"Expected single WriteLine call, but found $xs") | ||
} | ||
} | ||
} | ||
} |