Skip to content

Commit

Permalink
feat: <python> add basic inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 11, 2020
1 parent 5be1b82 commit 268cfe7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class PythonFullIdentListener(var fileName: String) : PythonAstBaseListener() {
currentNode = CodeDataStruct(
NodeName = ctx!!.name().text
)

if (ctx.arglist() != null) {
for (argumentContext in ctx.arglist().argument()) {
currentNode.MultipleExtend += argumentContext.text
}
}
}

override fun exitClassdef(ctx: PythonParser.ClassdefContext?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,19 @@ internal class PythonFullIdentListenerTest {
assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].NodeName, "foo")
}

@Test
internal fun shouldIdentClassInheritance() {
val code = """
class Student(Person):
pass
"""
val codeFile = PythonAnalyser().analysis(code, "")

assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].NodeName, "Student")
assertEquals(codeFile.DataStructures[0].MultipleExtend.size, 1)
assertEquals(codeFile.DataStructures[0].Extend, "")
assertEquals(codeFile.DataStructures[0].MultipleExtend[0], "Person")
}
}

0 comments on commit 268cfe7

Please sign in to comment.