Skip to content

Commit

Permalink
Add tests on local variables on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Oct 30, 2024
1 parent 3498af3 commit 50c44d9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ FamixPythonAbstractImporterTest >> importNamed: aName [
^ self model allImports detect: [ :import | import importedEntity name = aName ]
]

{ #category : 'accessing' }
FamixPythonAbstractImporterTest >> localVariableNamed: aName [

^ self model allLocalVariables detect: [ :variable | variable name = aName ]
]

{ #category : 'accessing' }
FamixPythonAbstractImporterTest >> methodNamed: aName [

Expand Down
52 changes: 52 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,47 @@ FamixPythonProject1Test >> testInstanceVariablesWithSameNameButDifferenClass [
(self classNamed: 'Stool') }
]

{ #category : 'tests - local variables' }
FamixPythonProject1Test >> testLocalVariableInFunctionSourceAnchor [

| variable |
variable := self localVariableNamed: 'local_in_function2'.

self assert: variable sourceAnchor isNotNil.
self assert: variable sourceText equals: 'local_in_function2'
]

{ #category : 'tests - local variables' }
FamixPythonProject1Test >> testLocalVariablesInFunctionAssignedWithATuple [

| global |
self denyEmpty: self model allLocalVariables.

global := self localVariableNamed: 'local_in_function_with_tuple1'.

self assert: global class equals: FamixPythonLocalVariable.
self assert: global name equals: 'local_in_function_with_tuple1'.
self assert: global parentBehaviouralEntity equals: (self functionNamed: 'function_with_local_variables_and_tuples').

global := self localVariableNamed: 'local_in_function_with_tuple2'.

self assert: global class equals: FamixPythonLocalVariable.
self assert: global name equals: 'local_in_function_with_tuple2'.
self assert: global parentBehaviouralEntity equals: (self functionNamed: 'function_with_local_variables_and_tuples')
]

{ #category : 'tests - local variables' }
FamixPythonProject1Test >> testLocalVariablesInFunctionWithTheSameNameButDifferentParents [

| variables |
variables := self model allLocalVariables select: [ :variable | variable name = 'local_in_function1' ].

self assert: variables size equals: 2.
self assertCollection: (variables flatCollect: #parents) hasSameElements: {
(self functionNamed: 'function_with_local_variables').
(self functionNamed: 'function_with_local_variables2') }
]

{ #category : 'tests - from-import' }
FamixPythonProject1Test >> testMethodImportsClassFromAModule [

Expand Down Expand Up @@ -1536,6 +1577,17 @@ FamixPythonProject1Test >> testSimpleInstanceVariable [
self deny: variable isClassSide
]

{ #category : 'tests - local variables' }
FamixPythonProject1Test >> testSimpleLocalVariableInFunction [

| variable |
variable := self localVariableNamed: 'local_in_function2'.

self assert: variable class equals: FamixPythonLocalVariable.
self assert: variable name equals: 'local_in_function2'.
self assert: variable parentBehaviouralEntity equals: (self functionNamed: 'function_with_local_variables')
]

{ #category : 'tests - methods' }
FamixPythonProject1Test >> testSimpleMethod [

Expand Down

0 comments on commit 50c44d9

Please sign in to comment.