From 8f12505e223cf569f2d499cc85358592ba15b632 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Wed, 11 Dec 2024 16:16:21 +0100 Subject: [PATCH] Add tests on different cases of function references --- .../FamixPythonProject1Test.class.st | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 00f26a0..159381b 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -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 [ @@ -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 [