Skip to content
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
47 changes: 47 additions & 0 deletions src/Kernel-Tests-Extended/CompiledMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,53 @@ CompiledMethodTest >> testPragmaAt [
self assert: (method pragmaAt: #hello) equals: nil
]

{ #category : #tests }
CompiledMethodTest >> testProperties [

| method tmp |
method := self class >> #returnTrue.

"No property. Unlike classic collections, nil is returned on absence"
self deny: method hasProperties.
self deny: (method hasProperty: #doesNotExist).
self assert: (method propertyAt: #doesNotExist) equals: nil.
self assert: (method propertyAt: #doesNotExist ifAbsent: [ #tag ]) equals: #tag.
self assert: (method removeProperty: #doesNotExist) equals: nil.
self assert: (method removeProperty: #doesNotExist ifAbsent: [ #tag ]) equals: #tag.

"Add a property"
self assert: (method propertyAt: #doesNotExist put: #yesItDoes) equals: #yesItDoes.
self assert: method hasProperties.
self assert: (method hasProperty: #doesNotExist).
self assert: (method propertyAt: #doesNotExist) equals: #yesItDoes.
self assert: (method propertyAt: #doesNotExist ifAbsent: [ #tag ]) equals: #yesItDoes.

"Remove it"
self assert: (method removeProperty: #doesNotExist) equals: #yesItDoes.
self deny: method hasProperties.
self assert: (method removeProperty: #doesNotExist) equals: nil.

"Add it back"
self assert: (method propertyAt: #doesNotExist ifAbsentPut: [ #yesItDoesAgain ]) equals: #yesItDoesAgain.
self assert: method hasProperties.
self assert: (method propertyAt: #doesNotExist) equals: #yesItDoesAgain.

"Add a second one"
self assert: (method propertyAt: #doesExist put: #yesItDoes) equals: #yesItDoes.

tmp := OrderedCollection new.
method propertyKeysAndValuesDo: [ :key :value | tmp add: { key . value } ].
self assertCollection: tmp hasSameElements: #( #( #doesNotExist #yesItDoesAgain ) #(#doesExist #yesItDoes) ).

"Remove both"
method removeProperty: #doesNotExist.
self assert: method hasProperties.
self assert: (method propertyAt: #doesNotExist) equals: nil.
self assert: (method propertyAt: #doesExist) equals: #yesItDoes.
method removeProperty: #doesExist.
self deny: method hasProperties
]

{ #category : #'tests - instance variable' }
CompiledMethodTest >> testReadsField [
| method |
Expand Down
3 changes: 3 additions & 0 deletions src/Kernel/CompiledMethod.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,9 @@ CompiledMethod >> removeProperty: propName [
(Association
key: propName
value: value)).

"Remove unneded AdditionalMethodState"
self penultimateLiteral size = 0 ifTrue: [ self penultimateLiteral: self selector ].
^value
]

Expand Down