Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Nov 28, 2024
1 parent 8f31553 commit 69f5a81
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,31 @@ class GraphExamples {
}
}

fun getInferenceNestedNamespace(
config: TranslationConfiguration =
TranslationConfiguration.builder()
.defaultPasses()
.registerLanguage(StructTestLanguage("."))
.inferenceConfiguration(
InferenceConfiguration.builder().inferRecords(true).build()
)
.build()
) =
testFrontend(config).build {
translationResult {
translationUnit("Test.java") {
record("Test") {
function("foo") {
body {
declare { variable("node", t("java.lang.String")) }
returnStmt { isImplicit = true }
}
}
}
}
}
}

fun getVariables(
config: TranslationConfiguration =
TranslationConfiguration.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,26 @@ class InferenceTest {
assertNotNull(nextField)
assertLocalName("T*", nextField.type)
}

@Test
fun testNestedNamespace() {
val result = GraphExamples.getInferenceNestedNamespace()
with(result) {
val java = result.namespaces["java"]
assertNotNull(java)
assertLocalName("java", java)

val javaLang = result.namespaces["java.lang"]
assertNotNull(javaLang)
assertLocalName("lang", javaLang)
// should exist in the scope of "java"
assertEquals(java, javaLang.scope?.astNode)

val javaLangString = result.records["java.lang.String"]
assertNotNull(javaLangString)
assertLocalName("String", javaLangString)
// should exist in the scope of "java.lang"
assertEquals(javaLang, javaLangString.scope?.astNode)
}
}
}

0 comments on commit 69f5a81

Please sign in to comment.