Skip to content

Commit

Permalink
Add tests on locals in methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Oct 30, 2024
1 parent 9bcf070 commit 295f13e
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,16 @@ FamixPythonProject1Test >> testLocalVariableInFunctionSourceAnchor [
self assert: variable sourceText equals: 'local_in_function2'
]

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

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

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

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

Expand Down Expand Up @@ -820,6 +830,37 @@ FamixPythonProject1Test >> testLocalVariablesInFunctionWithTheSameNameButDiffere
(self functionNamed: 'function_with_local_variables2') }
]

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

| global |
self denyEmpty: self model allLocalVariables.

global := self localVariableNamed: 'local_in_method_with_tuple1'.

self assert: global class equals: FamixPythonLocalVariable.
self assert: global name equals: 'local_in_method_with_tuple1'.
self assert: global parentBehaviouralEntity equals: (self methodNamed: 'method_with_local_variables_and_tuples').

global := self localVariableNamed: 'local_in_method_with_tuple2'.

self assert: global class equals: FamixPythonLocalVariable.
self assert: global name equals: 'local_in_method_with_tuple2'.
self assert: global parentBehaviouralEntity equals: (self methodNamed: 'method_with_local_variables_and_tuples')
]

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

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

self assert: variables size equals: 2.
self assertCollection: (variables flatCollect: #parents) hasSameElements: {
(self methodNamed: 'method_with_local_variables').
(self methodNamed: 'method_with_local_variables2') }
]

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

Expand Down Expand Up @@ -1595,6 +1636,17 @@ FamixPythonProject1Test >> testSimpleLocalVariableInFunction [
self assert: variable parentBehaviouralEntity equals: (self functionNamed: 'function_with_local_variables')
]

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

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

self assert: variable class equals: FamixPythonLocalVariable.
self assert: variable name equals: 'local_in_method2'.
self assert: variable parentBehaviouralEntity equals: (self methodNamed: 'method_with_local_variables')
]

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

Expand Down Expand Up @@ -1674,3 +1726,10 @@ FamixPythonProject1Test >> testlocalVariableInFunctionAreDefinedOnlyOnce [

self assert: (self model allLocalVariables select: [ :variable | variable name = 'local_in_function3' ]) size equals: 1
]

{ #category : 'tests - local variables' }
FamixPythonProject1Test >> testlocalVariableInMethodAreDefinedOnlyOnce [
"We should have only one global even if it is assigned multiple times."

self assert: (self model allLocalVariables select: [ :variable | variable name = 'local_in_method3' ]) size equals: 1
]

0 comments on commit 295f13e

Please sign in to comment.