Skip to content

Commit

Permalink
Merge pull request #68 from moosetechnology/local-resolver
Browse files Browse the repository at this point in the history
Local resolver
  • Loading branch information
NicolasAnquetil authored Mar 8, 2024
2 parents 271df8d + 9570593 commit 3da5f10
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 270 deletions.
6 changes: 6 additions & 0 deletions src/FAST-Core-Model/FASTTEntity.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ FASTTEntity >> endPos: anObject [
endPos := anObject
]

{ #category : #testing }
FASTTEntity >> isNonLocalDeclaration [

^false
]

{ #category : #accessing }
FASTTEntity >> startPos [

Expand Down
132 changes: 132 additions & 0 deletions src/FAST-Core-Tools-Tests/FASTLocalResolverScopingTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"
A FASTLocalResolverScopingTest is a test class for testing the behavior of FASTLocalResolverScoping
"
Class {
#name : #FASTLocalResolverScopingTest,
#superclass : #TestCase,
#instVars : [
'resolverScoping'
],
#category : #'FAST-Core-Tools-Tests-Resolver'
}

{ #category : #running }
FASTLocalResolverScopingTest >> setUp [
super setUp.

resolverScoping := FASTLocalResolverScoping new
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testAddNonLocalDeclaration [
"testing helper method #addNonLocalDeclaration:"
resolverScoping resetScopes.
resolverScoping pushScope.

resolverScoping scopeAddNonLocalDeclaration: 'blah'.

"second scope is empty"
self assert: resolverScoping popScope isEmpty.

"first scope contains NonLocalDeclaration"
self assert: (resolverScoping findDeclaration: 'blah') class equals: FASTNonLocalDeclaration
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testFindDeclarationInCurrentScope [
|node|
node := FASTEntity new.
resolverScoping resetScopes.
resolverScoping scopeAdd: 'blah' declaration: node.

self assert: (resolverScoping findDeclaration: 'blah') equals: node
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testFindDeclarationInEmptyScope [
resolverScoping resetScopes.
self assert: (resolverScoping findDeclaration: 'blah') equals: nil.

]

{ #category : #tests }
FASTLocalResolverScopingTest >> testFindDeclarationInParentScope [
|node|
node := FASTEntity new.
resolverScoping resetScopes.
resolverScoping scopeAdd: 'blah' declaration: node.
resolverScoping pushScope.

self assert: (resolverScoping findDeclaration: 'blah') equals: node
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testFindDeclarationNotInScope [
|node|
node := FASTEntity new.
resolverScoping resetScopes.
resolverScoping scopeAdd: 'blah' declaration: node.

self assert: (resolverScoping findDeclaration: 'blih') equals: nil.

]

{ #category : #tests }
FASTLocalResolverScopingTest >> testHasScopes [
"initialization creates a scope"

self assert: resolverScoping hasScopes
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testLocalDeclarationFor [
"testing helper method #localDeclaration:for:"
| declNode refNode |
declNode := FASTEntity new.
refNode := FASTEntity new.
declNode resetLocalUses.
resolverScoping localDeclaration: declNode for: refNode.

self assert: refNode localDeclaration notNil.
self assert: refNode localDeclaration equals: declNode.

self assert: declNode localUses size equals: 1.
self assert: declNode localUses first equals: refNode
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testResetScopes [
resolverScoping resetScopes.
self assert: resolverScoping hasScopes.

]

{ #category : #tests }
FASTLocalResolverScopingTest >> testScopeAddDeclarationTwiceRaisesError [
|node|
node := FASTEntity new.
resolverScoping resetScopes.

resolverScoping scopeAdd: 'blah' declaration: node.

self assert: resolverScoping currentScope size equals: 1.

self
should: [ resolverScoping scopeAdd: 'blah' declaration: node ]
raise: DuplicatedVariableError
]

{ #category : #tests }
FASTLocalResolverScopingTest >> testScopeAddNonLocalDeclarationTwiceRaisesError [
|node|
node := FASTEntity new.
resolverScoping resetScopes.

resolverScoping scopeAddNonLocalDeclaration: 'blah'.

self assert: resolverScoping currentScope size equals: 1.

self
should: [ resolverScoping scopeAddNonLocalDeclaration: 'blah' ]
raise: DuplicatedVariableError
]
131 changes: 0 additions & 131 deletions src/FAST-Core-Tools-Tests/FASTLocalResolverVisitorTest.class.st

This file was deleted.

Loading

0 comments on commit 3da5f10

Please sign in to comment.