Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Adding a first test + making #privateTransform => implementor… #1442

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 15 additions & 239 deletions src/Spec2-Code-Tests/SpCodePresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -176,57 +176,6 @@ SpCodePresenterTest >> testDoBrowseImplementors [
equals: { SpCodePresenterTest>>#testDoBrowseImplementors }
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseImplementorsOnBrokenSelectorDoesNotOpenAClassBrowser [
| navigation |

navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
presenter beForScripting.
self openInstance.

presenter text: '#degressThatDoesNotExist'.
presenter doBrowseImplementors.

self
assert: navigation browseClass
equals: nil
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseImplementorsOnBrokenSelectorRepresentingAClassOpensAClassBrowser [
| navigation |

navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
presenter beForScripting.
self openInstance.

presenter text: '#Point23456'.
presenter doBrowseImplementors.

self
assert: navigation browseClass
equals: nil
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseImplementorsOnSelectorRepresentingAClassOpensAClassBrowser [
| navigation |

navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
presenter beForScripting.
self openInstance.

presenter text: '#Point'.
presenter doBrowseImplementors.

self
assert: navigation browseClass
equals: Point
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseMethodReferences [
| navigation |
Expand Down Expand Up @@ -330,146 +279,6 @@ SpCodePresenterTest >> testDoBrowseMethodsMatchingStringSensitive [

]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseOnBrokenSelectorDoesNotBrowseTheClass [

| navigation |
navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
self openInstance.

presenter text: '#degressThatDoesNotExist'.
"Selection"
presenter selectionInterval: (1 to: 6).
presenter doBrowseClass.

self assert: navigation browseClass equals: nil.

navigation reset.
"Line"
presenter cursorPositionIndex: 1.
presenter selectionInterval: (1 to: 0).
presenter doBrowseClass.
self assert: navigation browseClass equals: nil.

"Middle of line"
presenter cursorPositionIndex: 5.
presenter selectionInterval: (5 to: 4).
presenter doBrowseClass.
self assert: navigation browseClass equals: nil.

"End of line"
presenter cursorPositionIndex: 14.
presenter selectionInterval: (14 to: 13).
presenter doBrowseClass.
self assert: navigation browseClass equals: nil.
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseOnBrokenSymbolRepresentingAClassDoesNotBrowseTheClass [

| navigation |
navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
self openInstance.

presenter text: '#Point234'.
"Selection"
presenter selectionInterval: (1 to: 6).
presenter doBrowseClass.

self assert: navigation browseClass equals: Point.

navigation reset.
"Line"
presenter cursorPositionIndex: 1.
presenter selectionInterval: (1 to: 0).
presenter doBrowseClass.
self assert: navigation browseClass equals: nil.

"Middle of line"
presenter cursorPositionIndex: 5.
presenter selectionInterval: (5 to: 4).
presenter doBrowseClass.
self assert: navigation browseClass equals: nil.

"End of line"
presenter cursorPositionIndex: 14.
presenter selectionInterval: (14 to: 13).
presenter doBrowseClass.
self assert: navigation browseClass equals: nil.
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseOnSelectorOpensAnImplementor [

| navigation |
navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
self openInstance.

presenter text: '#~~>'.
"Selection"
presenter selectionInterval: (1 to: 4).
presenter doBrowseClass.

self assert: navigation messageList first selector equals: #'~~>'.

navigation reset.
"Line"
presenter cursorPositionIndex: 1.
presenter selectionInterval: (1 to: 0).
presenter doBrowseClass.
self assert: navigation messageList first selector equals: #'~~>'.

"Middle of line"
presenter cursorPositionIndex: 5.
presenter selectionInterval: (5 to: 4).
presenter doBrowseClass.
self assert: navigation messageList first selector equals: #'~~>'.

"End of line"
presenter cursorPositionIndex: 14.
presenter selectionInterval: (14 to: 13).
presenter doBrowseClass.
self assert: navigation messageList first selector equals: #'~~>'.
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseOnSymbolRepresentingAClassBrowsesTheClass [

| navigation |
navigation := SpCodeSystemNavigationMock new.
presenter systemNavigation: navigation.
self openInstance.

presenter text: '#Point'.
"Selection"
presenter selectionInterval: (1 to: 6).
presenter doBrowseClass.

self assert: navigation browseClass equals: Point.

navigation reset.
"Line"
presenter cursorPositionIndex: 1.
presenter selectionInterval: (1 to: 0).
presenter doBrowseClass.
self assert: navigation browseClass equals: Point.

"Middle of line"
presenter cursorPositionIndex: 5.
presenter selectionInterval: (5 to: 4).
presenter doBrowseClass.
self assert: navigation browseClass equals: Point.

"End of line"
presenter cursorPositionIndex: 14.
presenter selectionInterval: (14 to: 13).
presenter doBrowseClass.
self assert: navigation browseClass equals: Point.
]

{ #category : #'tests - commands' }
SpCodePresenterTest >> testDoBrowseSenders [
| navigation |
Expand Down Expand Up @@ -758,51 +567,37 @@ SpCodePresenterTest >> testEvaluateOnCompileErrorOnError [

{ #category : #'tests - command support' }
SpCodePresenterTest >> testEvaluateSendAnnouncements [

| willBeEvaluated succeed failed |
presenter announcer
when: SpCodeWillBeEvaluatedAnnouncement
do: [ :ann | willBeEvaluated := true ]
for: self;
when: SpCodeEvaluationSucceedAnnouncement
do: [ :ann | succeed := true ]
for: self;
when: SpCodeEvaluationFailedAnnouncement
do: [ :ann | failed := true ]
for: self.

willBeEvaluated := false.

presenter announcer
when: SpCodeWillBeEvaluatedAnnouncement do: [ :ann | willBeEvaluated := true ];
when: SpCodeEvaluationSucceedAnnouncement do: [ :ann | succeed := true ];
when: SpCodeEvaluationFailedAnnouncement do: [ :ann | failed := true ].

willBeEvaluated := false.
succeed := false.
failed := false.
presenter
evaluate: '42 factorial'
onCompileError: [ #compileError ]
onError: [ :e | #error ].
presenter evaluate: '42 factorial' onCompileError: [ #compileError ] onError: [ :e | #error ].
self assert: willBeEvaluated.
self assert: succeed.
self deny: failed.

willBeEvaluated := false.
willBeEvaluated := false.
succeed := false.
failed := false.
presenter
evaluate: 'Obj { }}'
onCompileError: [ #compile ]
onError: [ :e | #error ].
presenter evaluate: 'Obj { }}' onCompileError: [ #compile ] onError: [ :e | #error ].
self assert: willBeEvaluated.
self deny: succeed.
self assert: failed.

willBeEvaluated := false.
willBeEvaluated := false.
succeed := false.
failed := false.
presenter
evaluate: 'nil text'
onCompileError: [ #compile ]
onError: [ :e | #error ].
presenter evaluate: 'nil text' onCompileError: [ #compile ] onError: [ :e | #error ].
self assert: willBeEvaluated.
self deny: succeed.
self assert: failed
self assert: failed.

]

{ #category : #tests }
Expand Down Expand Up @@ -892,25 +687,6 @@ SpCodePresenterTest >> testSelectedSelectorForScripting [
self assert: selector equals: #noMethod"
]

{ #category : #'tests - command support' }
SpCodePresenterTest >> testSelectedSelectorForScripting2 [
"Testing border cases to avoid breaking execution. The selector extraction logic should be tested in the extractor class"

"Code presenter has nil text for some reason"

| selector |
presenter text: nil.
presenter beForScripting.
selector := presenter selectedSelector.
self assert: selector isNil.
presenter text: '#Point'.
selector := presenter selectedSelector.
self assert: selector equals: #Point.



]

{ #category : #'tests - command support' }
SpCodePresenterTest >> testSelectedSelectorWithPointerAtEnd [
"Testing border cases to avoid breaking execution. The selector extraction logic should be tested in the extractor class"
Expand Down
29 changes: 8 additions & 21 deletions src/Spec2-Code/SpCodePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,18 @@ SpCodePresenter >> contextMenu [

{ #category : #commands }
SpCodePresenter >> doBrowseClass [
| result selector |
| result |

result := self
evaluate: self selectedTextOrLine
onCompileError: [ ^ self ]
onError: [ :e | ^ self ].

(result isKindOf: Symbol)
ifTrue: [
| classToBrowse |
| classToBrowse |
classToBrowse := self class environment at: result ifAbsent: [ nil ].
classToBrowse ifNotNil: [ ^ self systemNavigation browse: classToBrowse ].
^ self systemNavigation browseAllImplementorsOf: result ].
self selectedTextOrLine first isUppercase
ifTrue: [ ^ self systemNavigation browse: result ].
selector := self selectedSelector ifNil: [ ^ nil ].
selector ifNotNil: [
^ self systemNavigation browseAllImplementorsOf: selector ].
^ self systemNavigation browse: result
classToBrowse ifNotNil: [ ^ self systemNavigation browse: classToBrowse ] ].
self systemNavigation browse: result
]

{ #category : #commands }
Expand Down Expand Up @@ -312,22 +306,15 @@ SpCodePresenter >> doBrowseHierarchy [
{ #category : #commands }
SpCodePresenter >> doBrowseImplementors [
| variableOrClassName variable |

variableOrClassName := self selectedSelector ifNil: [ ^ nil ].
variable := self lookupEnvironment lookupVar: variableOrClassName.

"For global and class variables, implementors-of browses the class of the value of the variable,
for classes this means it browses the class"
(variable isNotNil and: [variable isGlobalVariable or: [variable isClassVariable]])
ifTrue: [ variable value browse
"pay attention to pass through the systemNavigation else we cannot write tests...!
And BTW please write tests!"]
ifFalse: [
| classToBrowse |
classToBrowse := (self class environment bindingOf: variableOrClassName) value.
classToBrowse isNotNil
ifFalse: [self systemNavigation browseAllImplementorsOf: variableOrClassName ]
ifTrue: [ self systemNavigation browse: classToBrowse ]]
ifTrue: [ variable value browse ]
ifFalse: [ self systemNavigation browseAllImplementorsOf: variableOrClassName ]
]

{ #category : #commands }
Expand Down
Loading