From 2aabde46c794429f53db3976a65ba875accfc867 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Thu, 21 Nov 2024 17:44:49 +0100 Subject: [PATCH] Add more tests on edge cases --- .../FamixPythonProject1Test.class.st | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 2916b67..aeafa11 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -791,6 +791,18 @@ FamixPythonProject1Test >> testGlobalVariablesAssignedWithATuple [ self assert: global parentScope equals: (self moduleNamed: 'moduleAtRoot') ] +{ #category : 'tests - global variables' } +FamixPythonProject1Test >> testGlobalVariablesShadowedThenRedefined [ + + | globals | + globals := self model allGlobalVariables select: [ :variable | variable name = 'global_then_function_then_global_then_class' ]. + + self assert: globals size equals: 2. + globals do: [ :global | + self assert: global name equals: 'global_then_function_then_global_then_class'. + self assert: global parentScope equals: (self moduleNamed: 'moduleWithShadowing') ] +] + { #category : 'tests - global variables' } FamixPythonProject1Test >> testGlobalVariablesWithTheSameNameButDifferentParents [ @@ -2246,6 +2258,23 @@ FamixPythonProject1Test >> testWriteAccessFromPackage [ self assert: (p accesses anySatisfy: [ :anAccess | anAccess variable = a ]) ] +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testWriteAccessOfGlobalThatGotShadowedAndRedefined [ + "This test ensure that if we declare a global, shadow it and redefine it again, the accesses are going to the right global." + + | global1 global2 module accesses | + global1 := (self model allGlobalVariables select: [ :entity | entity name = 'global_then_function_then_global_then_class' ]) asOrderedCollection detectMin: [ + :entity | entity sourceAnchor startPos ]. + global2 := (self model allGlobalVariables select: [ :entity | entity name = 'global_then_function_then_global_then_class' ]) asOrderedCollection detectMax: [ + :entity | entity sourceAnchor startPos ]. + module := self moduleNamed: 'moduleWithShadowing'. + + accesses := module accesses select: [ :anAccess | anAccess variable name = 'global_then_function_then_global_then_class' ]. + + self assert: (accesses detectMin: [ :entity | entity sourceAnchor startPos ]) variable equals: global1. + self assert: (accesses detectMax: [ :entity | entity sourceAnchor startPos ]) variable equals: global2 +] + { #category : 'tests - accesses' } FamixPythonProject1Test >> testWriteAccessSourceAnchor [