Skip to content

Commit

Permalink
Add tests on different cases of function references
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 11, 2024
1 parent dcd2761 commit 8f12505
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,40 @@ FamixPythonProject1Test >> testFunctionInAPackage [
self assert: function functionOwner equals: (self packageNamed: 'subsubpackage1')
]

{ #category : 'tests - function references' }
FamixPythonProject1Test >> testFunctionReferenceFromClass [

| function class reference |
function := self functionNamed: 'return2'.
class := self classNamed: 'ClassWithFunctionReference'.

reference := (function incomingFunctionReferences detect: [ :aReference | aReference referencer = class ]).

self assert: reference class equals: FamixPythonFunctionReference.
self assert: reference source equals: class.
self assert: reference referencer equals: class.
self assert: reference target equals: function.
self assert: reference referredFunction equals: function.
self assert: (class outgoingFunctionReferences anySatisfy: [ :aReference | aReference referredFunction = function ])
]

{ #category : 'tests - function references' }
FamixPythonProject1Test >> testFunctionReferenceFromFunction [

| function function2 reference |
function := self functionNamed: 'return2'.
function2 := self functionNamed: 'function_with_function_ref'.

reference := (function incomingFunctionReferences detect: [ :aReference | aReference referencer = function2 ]).

self assert: reference class equals: FamixPythonFunctionReference.
self assert: reference source equals: function2.
self assert: reference referencer equals: function2.
self assert: reference target equals: function.
self assert: reference referredFunction equals: function.
self assert: (function2 outgoingFunctionReferences anySatisfy: [ :aReference | aReference referredFunction = function ])
]

{ #category : 'tests - function references' }
FamixPythonProject1Test >> testFunctionReferenceFromImportedEntity [

Expand Down Expand Up @@ -648,6 +682,40 @@ FamixPythonProject1Test >> testFunctionReferenceFromImportedEntityWithAliasSourc
self assert: reference sourceText equals: 'fwi'
]

{ #category : 'tests - function references' }
FamixPythonProject1Test >> testFunctionReferenceFromLambda [

| function lambda reference |
function := self functionNamed: 'return2'.
lambda := (self functionNamed: 'function_with_lambda_with_function_ref') lambdas anyOne.

reference := function incomingFunctionReferences detect: [ :aReference | aReference referencer = lambda ].

self assert: reference class equals: FamixPythonFunctionReference.
self assert: reference source equals: lambda.
self assert: reference referencer equals: lambda.
self assert: reference target equals: function.
self assert: reference referredFunction equals: function.
self assert: (lambda outgoingFunctionReferences anySatisfy: [ :aReference | aReference referredFunction = function ])
]

{ #category : 'tests - function references' }
FamixPythonProject1Test >> testFunctionReferenceFromMethod [

| function method reference |
function := self functionNamed: 'return2'.
method := self methodNamed: 'method_with_function_ref'.

reference := (function incomingFunctionReferences detect: [ :aReference | aReference referencer = method ]).

self assert: reference class equals: FamixPythonFunctionReference.
self assert: reference source equals: method.
self assert: reference referencer equals: method.
self assert: reference target equals: function.
self assert: reference referredFunction equals: function.
self assert: (method outgoingFunctionReferences anySatisfy: [ :aReference | aReference referredFunction = function ])
]

{ #category : 'tests - function references' }
FamixPythonProject1Test >> testFunctionReferenceFromModule [

Expand Down

0 comments on commit 8f12505

Please sign in to comment.