Skip to content

Commit

Permalink
feat: <python> add import as support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 11, 2020
1 parent 9c06331 commit a2599a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PythonFullIdentListener(var fileName: String) : PythonAstBaseListener() {
codeImport.UsageName += firstNameCtx.name().text
}

for (i in 1 until dotNames.size - 1) {
for (i in 1 until dotNames.size) {
codeImport.UsageName += dotNames[i].text
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,19 @@ import collections.abc
assertEquals(codeFile.Imports[0].Source, "collections.abc")
assertEquals(codeFile.Imports[0].UsageName.size, 0)
}
@Test
internal fun shouldIdentImportAs() {
val code = """
import collections.abc as ss, itertools
"""

val codeFile = PythonAnalyser().analysis(code, "")

assertEquals(codeFile.Imports.size, 1)
assertEquals(codeFile.Imports[0].Source, "collections.abc")
assertEquals(codeFile.Imports[0].UsageName.size, 2)
assertEquals(codeFile.Imports[0].UsageName[0], "ss")
assertEquals(codeFile.Imports[0].UsageName[1], "itertools")
}
}

0 comments on commit a2599a8

Please sign in to comment.