Skip to content

Commit

Permalink
Add test on double shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jan 16, 2025
1 parent 6b1f428 commit 772eb3b
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ FamixPythonProject1Test >> testFunctionShadowedByClass [
self assert: shadower name equals: 'function_shadowed_by_class'.
self deny: shadower isShadowed.
self assert: shadower typeContainer equals: (self moduleNamed: 'moduleWithShadowing').
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: ('class function_shadowed_by_class:
pass' copyReplaceAll: String cr with: String lf).

Expand All @@ -1161,7 +1161,7 @@ FamixPythonProject1Test >> testFunctionShadowedByFunction [
self assert: shadower name equals: 'function_to_shadow'.
self deny: shadower isShadowed.
self assert: shadower functionOwner equals: (self moduleNamed: 'moduleAtRoot6').
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: ('def function_to_shadow():
return 2' copyReplaceAll: String cr with: String lf).

Expand All @@ -1184,7 +1184,7 @@ FamixPythonProject1Test >> testFunctionShadowedByGlobal [
self assert: shadower name equals: 'global_then_function_then_global_then_class'.
self assert: shadower isShadowed. "<= In that case the shadower is also shadowed later"
self assert: shadower parentScope equals: (self moduleNamed: 'moduleWithShadowing').
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: ('global_then_function_then_global_then_class' copyReplaceAll: String cr with: String lf).

self assert: shadowed name equals: 'global_then_function_then_global_then_class'.
Expand All @@ -1205,7 +1205,7 @@ FamixPythonProject1Test >> testFunctionShadowedByTemporary [
self assert: shadower name equals: 'function_with_local_of_same_name'.
self deny: shadower isShadowed.
self assert: shadower parentBehaviouralEntity equals: shadowed.
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: ('function_with_local_of_same_name' copyReplaceAll: String cr with: String lf).

self assert: shadowed name equals: 'function_with_local_of_same_name'.
Expand All @@ -1220,6 +1220,43 @@ FamixPythonProject1Test >> testFunctionShadowedByTemporary [
return function_with_local_of_same_name + 3' copyReplaceAll: String cr with: String lf)
]

{ #category : 'tests - shadowing' }
FamixPythonProject1Test >> testFunctionShadowedTwice [

| shadower shadower2 shadowed |
shadower := self localVariableNamed: 'function_shadowed_twice'.
shadower2 := (self model allFunctions select: [ :entity | entity name = 'function_shadowed_twice' ]) asOrderedCollection detectMax: [ :entity |
entity sourceAnchor startPos ].
shadowed := (self model allFunctions select: [ :entity | entity name = 'function_shadowed_twice' ]) asOrderedCollection detectMin: [ :entity |
entity sourceAnchor startPos ].

self assert: shadower name equals: 'function_shadowed_twice'.
self deny: shadower isShadowed.
self assert: shadower parentBehaviouralEntity equals: shadowed.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: 'function_shadowed_twice'.

self assert: shadower2 name equals: 'function_shadowed_twice'.
self deny: shadower2 isShadowed.
self assert: shadower2 functionOwner equals: (self moduleNamed: 'moduleWithShadowing').
self assert: shadower2 shadowedEntity equals: shadowed.
self assert: shadower2 sourceText equals: ('def function_shadowed_twice():
return 4' copyReplaceAll: String cr with: String lf).

self assert: shadowed name equals: 'function_shadowed_twice'.
self assert: shadowed isShadowed.
self assert: shadowed functionOwner equals: (self moduleNamed: 'moduleWithShadowing').
self assertCollection: shadowed shadowingEntities hasSameElements: {
shadower.
shadower2 }.
self assert: shadowed sourceText equals: ('def function_shadowed_twice(init):
if init > 10:
return init
function_shadowed_twice = init
return function_shadowed_twice + 3' copyReplaceAll: String cr with: String lf)
]

{ #category : 'tests - functions' }
FamixPythonProject1Test >> testFunctionSourceAnchor [

Expand Down Expand Up @@ -1279,7 +1316,7 @@ FamixPythonProject1Test >> testGlobalShadowedByClass [
self assert: shadower name equals: 'global_then_function_then_global_then_class'.
self deny: shadower isShadowed.
self assert: shadower typeContainer equals: (self moduleNamed: 'moduleWithShadowing').
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: ('class global_then_function_then_global_then_class:
def __init__(self):
print(16)' copyReplaceAll: String cr with: String lf).
Expand All @@ -1302,7 +1339,7 @@ FamixPythonProject1Test >> testGlobalShadowedByFunction [
self assert: shadower name equals: 'global_then_function_then_global_then_class'.
self assert: shadower isShadowed. "<= In that case the shadower is also shadowed later"
self assert: shadower functionOwner equals: (self moduleNamed: 'moduleWithShadowing').
self assertCollection: shadowed shadowingEntities hasSameElements: { shadower }.
self assert: shadower shadowedEntity equals: shadowed.
self assert: shadower sourceText equals: ('def global_then_function_then_global_then_class():
print(14)' copyReplaceAll: String cr with: String lf).

Expand Down

0 comments on commit 772eb3b

Please sign in to comment.