From de7427e16ae8517db51077aec2b77a84084b0332 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Wed, 13 Nov 2024 17:47:25 +0100 Subject: [PATCH] Add tests on shadowing of classes and methods --- .../FamixPythonProject1Test.class.st | 68 ++++++++++++++++--- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 1999f27..a880576 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -170,14 +170,38 @@ FamixPythonProject1Test >> testClassInPackage [ self assert: class typeContainer equals: (self packageNamed: 'subpackage1') ] -{ #category : 'tests - classes' } +{ #category : 'tests - shadowing' } +FamixPythonProject1Test >> testClassShadowedByFunction [ + + | shadower shadowed | + shadower := (self model allFunctions select: [ :entity | entity name = 'shadowedName' ]) asOrderedCollection detectMax: [ :entity | + entity sourceAnchor startPos ]. + shadowed := (self model allClasses select: [ :entity | entity name = 'shadowedName' ]) asOrderedCollection detectMin: [ :entity | + entity sourceAnchor startPos ]. + + self assert: shadower name equals: 'shadowedName'. + self deny: shadower isShadowed. + self assert: shadower functionOwner equals: (self moduleNamed: 'moduleWithShadowing'). + self assert: shadower shadowedEntity equals: shadowed. + self assert: shadower sourceText equals: ('def shadowedName(): + print("I''m the last one so I win")' copyReplaceAll: String cr with: String lf). + + self assert: shadowed name equals: 'shadowedName'. + self assert: shadowed isShadowed. + self assert: shadowed typeContainer equals: (self moduleNamed: 'moduleWithShadowing'). + self assert: shadowed shadowingEntity equals: shadower. + self assert: shadowed sourceText equals: ('class shadowedName: + shadowedNameVar = 2' copyReplaceAll: String cr with: String lf) +] + +{ #category : 'tests - shadowing' } FamixPythonProject1Test >> testClassShadowedByOtherClass [ | shadower shadowed | - shadower := (self model allClasses select: [ :funct | funct name = 'ClassShadowedByOtherClass' ]) asOrderedCollection detectMax: [ :funct | - funct sourceAnchor startPos ]. - shadowed := (self model allClasses select: [ :funct | funct name = 'ClassShadowedByOtherClass' ]) asOrderedCollection detectMin: [ :funct | - funct sourceAnchor startPos ]. + shadower := (self model allClasses select: [ :entity | entity name = 'ClassShadowedByOtherClass' ]) asOrderedCollection detectMax: [ :entity | + entity sourceAnchor startPos ]. + shadowed := (self model allClasses select: [ :entity | entity name = 'ClassShadowedByOtherClass' ]) asOrderedCollection detectMin: [ :entity | + entity sourceAnchor startPos ]. self assert: shadower name equals: 'ClassShadowedByOtherClass'. self deny: shadower isShadowed. @@ -511,6 +535,30 @@ FamixPythonProject1Test >> testFunctionInAPackage [ self assert: function functionOwner equals: (self packageNamed: 'subsubpackage1') ] +{ #category : 'tests - shadowing' } +FamixPythonProject1Test >> testFunctionShadowedByClass [ + + | shadower shadowed | + shadower := (self model allClasses select: [ :entity | entity name = 'function_shadowed_by_class' ]) asOrderedCollection detectMax: [ :entity | + entity sourceAnchor startPos ]. + shadowed := (self model allFunctions select: [ :entity | entity name = 'function_shadowed_by_class' ]) asOrderedCollection detectMin: [ :entity | + entity sourceAnchor startPos ]. + + self assert: shadower name equals: 'function_shadowed_by_class'. + self deny: shadower isShadowed. + self assert: shadower typeContainer equals: (self moduleNamed: 'moduleWithShadowing'). + self assert: shadower shadowedEntity equals: shadowed. + self assert: shadower sourceText equals: ('class function_shadowed_by_class: + pass' copyReplaceAll: String cr with: String lf). + + self assert: shadowed name equals: 'function_shadowed_by_class'. + self assert: shadowed isShadowed. + self assert: shadowed functionOwner equals: (self moduleNamed: 'moduleWithShadowing'). + self assert: shadowed shadowingEntity equals: shadower. + self assert: shadowed sourceText equals: ('def function_shadowed_by_class(): + return 2' copyReplaceAll: String cr with: String lf) +] + { #category : 'tests - functions' } FamixPythonProject1Test >> testFunctionSourceAnchor [ @@ -1715,7 +1763,7 @@ FamixPythonProject1Test >> testRootPackage [ self assert: rootPackage isRoot ] -{ #category : 'tests - functions' } +{ #category : 'tests - shadowing' } FamixPythonProject1Test >> testShadowableFunction [ | function shadowable | @@ -1732,7 +1780,7 @@ FamixPythonProject1Test >> testShadowableFunction [ return 2' copyReplaceAll: String cr with: String lf) ] -{ #category : 'tests - functions' } +{ #category : 'tests - shadowing' } FamixPythonProject1Test >> testShadowableFunctionWithDifferentParameter [ | function shadowable | @@ -1750,7 +1798,7 @@ FamixPythonProject1Test >> testShadowableFunctionWithDifferentParameter [ return age' copyReplaceAll: String cr with: String lf) ] -{ #category : 'tests - functions' } +{ #category : 'tests - shadowing' } FamixPythonProject1Test >> testShadowedFunction [ | function shadower | @@ -1767,7 +1815,7 @@ FamixPythonProject1Test >> testShadowedFunction [ return 1' copyReplaceAll: String cr with: String lf) ] -{ #category : 'tests - functions' } +{ #category : 'tests - shadowing' } FamixPythonProject1Test >> testShadowedFunctionCreatesDifferentFunctions [ | functions | @@ -1777,7 +1825,7 @@ FamixPythonProject1Test >> testShadowedFunctionCreatesDifferentFunctions [ functions do: [ :function | self assert: function functionOwner equals: (self moduleNamed: 'moduleAtRoot6') ] ] -{ #category : 'tests - functions' } +{ #category : 'tests - shadowing' } FamixPythonProject1Test >> testShadowedFunctionWithDifferentParameter [ | function shadower |