Skip to content

Commit ea4b5bf

Browse files
committed
Add tests on local var of dictionary conprehension
1 parent 6c4fc1c commit ea4b5bf

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,6 +3395,28 @@ FamixPythonProject1Test >> testLocalMethodInvocationSourceAnchor [
33953395
self assert: invocation sourceText equals: 'self.get_name()'
33963396
]
33973397
3398+
{ #category : 'tests - local variables' }
3399+
FamixPythonProject1Test >> testLocalVariableInDictionaryComprehension [
3400+
3401+
| variable |
3402+
variable := self localVariableNamed: 'localVariableInDictionaryComprehension'.
3403+
3404+
self assert: variable class equals: FamixPythonLocalVariable.
3405+
self assert: variable name equals: 'localVariableInDictionaryComprehension'.
3406+
self assert: variable parentBehaviouralEntity equals: (self moduleNamed: 'moduleAtRoot15').
3407+
self deny: variable isStub
3408+
]
3409+
3410+
{ #category : 'tests - local variables' }
3411+
FamixPythonProject1Test >> testLocalVariableInDictionaryComprehensionSourceAnchor [
3412+
3413+
| variable |
3414+
variable := self localVariableNamed: 'localVariableInDictionaryComprehension'.
3415+
3416+
self assert: variable sourceAnchor isNotNil.
3417+
self assert: variable sourceText equals: 'localVariableInDictionaryComprehension'
3418+
]
3419+
33983420
{ #category : 'tests - local variables' }
33993421
FamixPythonProject1Test >> testLocalVariableInFunctionSourceAnchor [
34003422
@@ -5752,6 +5774,25 @@ FamixPythonProject1Test >> testReadAccessInUnaryOperator [
57525774
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
57535775
]
57545776
5777+
{ #category : 'tests - accesses' }
5778+
FamixPythonProject1Test >> testReadAccessOfLocalInDictionaryComprehension [
5779+
5780+
| global module access |
5781+
global := self localVariableNamed: 'localVarToAccessInDictionaryComprehension'.
5782+
module := self moduleNamed: 'moduleAtRoot13'.
5783+
5784+
access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].
5785+
5786+
self assert: access class equals: FamixPythonAccess.
5787+
self assert: access source equals: module.
5788+
self assert: access accessor equals: module.
5789+
self assert: access target equals: global.
5790+
self assert: access variable equals: global.
5791+
self deny: access isWrite.
5792+
self assert: access isRead.
5793+
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
5794+
]
5795+
57555796
{ #category : 'tests - accesses' }
57565797
FamixPythonProject1Test >> testReadAccessSourceAnchor [
57575798

src/Famix-Python-Importer/FamixPythonVisitor.class.st

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,6 @@ FamixPythonVisitor >> initialize [
267267
importPaths := IdentityDictionary new
268268
]
269269

270-
{ #category : 'testing' }
271-
FamixPythonVisitor >> isAccessOrReferenceNode: anIdentifierNode [
272-
"I should return true if an Identifier node represent an access or a reference."
273-
274-
^ #( elif_clause list argument_list return_statement lambda if_statement comparison_operator binary_operator assignment not_operator expression_statement
275-
augmented_assignment unary_operator boolean_operator pair list_splat default_parameter dictionary_splat #if_clause #for_in_clause generator_expression list_comprehension) includes: anIdentifierNode parent type
276-
]
277-
278270
{ #category : 'testing' }
279271
FamixPythonVisitor >> isMetaclassDefinition: aClassDefinitionNode [
280272

@@ -287,7 +279,7 @@ FamixPythonVisitor >> isMetaclassDefinition: aClassDefinitionNode [
287279
FamixPythonVisitor >> manageAccessOrReferencesFrom: anIdentifierNode [
288280
"To know if the identifier can be an access or reference we need to check its parents."
289281

290-
(self isAccessOrReferenceNode: anIdentifierNode) ifTrue: [
282+
anIdentifierNode isAccessOrReferenceNode ifTrue: [
291283
self
292284
resolve: ((SRIdentifierResolvable identifier: anIdentifierNode sourceText)
293285
expectedKind: {

src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ FamixTSNodeWrapper >> assignationNode [
77
^ self parent ifNotNil: [ self parent assignationNode ]
88
]
99

10+
{ #category : '*Famix-Python-Importer' }
11+
FamixTSNodeWrapper >> isAccessOrReferenceNode [
12+
"I should return true if an Identifier node represent an access or a reference."
13+
14+
^ #( elif_clause list argument_list return_statement lambda if_statement comparison_operator binary_operator assignment not_operator expression_statement
15+
augmented_assignment unary_operator boolean_operator pair list_splat default_parameter dictionary_splat #if_clause #for_in_clause generator_expression
16+
list_comprehension dictionary_comprehension ) includes: self parent type
17+
]
18+
1019
{ #category : '*Famix-Python-Importer' }
1120
FamixTSNodeWrapper >> isInField: aName ofParentOfType: aType [
1221

@@ -33,6 +42,9 @@ FamixTSNodeWrapper >> isLocalVariableDeclaration [
3342
"[localVarInListComprehension for localVarInListComprehension in [4, 5] if localVarInListComprehension > 2]"
3443
(self isInField: #body ofParentOfType: #list_comprehension) ifTrue: [ ^ true ].
3544

45+
"{localVariableInDictionaryComprehension * localVariableInDictionaryComprehension: localVariableInDictionaryComprehension for localVariableInDictionaryComprehension in [4, 5] if localVariableInDictionaryComprehension > 10}"
46+
(self isInField: #body ofParentOfType: #dictionary_comprehension) ifTrue: [ ^ true ].
47+
3648
^ false
3749
]
3850

0 commit comments

Comments
 (0)