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

more tests SoilPersistentDictionaryTest #833

Merged
merged 1 commit into from
Oct 9, 2024
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
36 changes: 36 additions & 0 deletions src/Soil-Core-Tests/SoilPersistentDictionaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ SoilPersistentDictionaryTest >> testAtIfAbsent [
self assert: (dict at: #test2 ifAbsent: [#missing]) equals: #missing
]

{ #category : #tests }
SoilPersistentDictionaryTest >> testAtIfPresentIfAbsent [

| dict transaction |
transaction := soil newTransaction.
dict := SoilPersistentDictionary new.
dict at: #test1 put: 1.
transaction makeRoot: dict.
transaction commit.

self assert: (dict at: #test2 ifPresent: [#present] ifAbsent: [#missing]) equals: #missing.
self assert: (dict at: #test1 ifPresent: [:pr | #present] ifAbsent: [#missing]) equals: #present.
]

{ #category : #tests }
SoilPersistentDictionaryTest >> testAtPut [

Expand Down Expand Up @@ -138,6 +152,28 @@ SoilPersistentDictionaryTest >> testRemoveKey [



]

{ #category : #tests }
SoilPersistentDictionaryTest >> testRemoveKeyIfAbsent [

| dict transaction removed removed2|
transaction := soil newTransaction.
dict := SoilPersistentDictionary new.
transaction makeRoot: dict.
dict at: #test put: 'string'.
dict at: #test2 put: 'string2'.
removed := dict removeKey: #test ifAbsent: [ self error ].
removed2 := dict removeKey: #tt ifAbsent: [ #absent ].
transaction commit.

self assert: removed equals: 'string'.
self assert: (dict at: #test2) equals: 'string2'.
self deny: (dict includesKey: #test).
self assert: removed2 equals: #absent.



]

{ #category : #tests }
Expand Down
2 changes: 1 addition & 1 deletion src/Soil-Serializer/SoilPersistentDictionary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SoilPersistentDictionary >> at: key ifAbsentPut: aBlock [
{ #category : #forwarded }
SoilPersistentDictionary >> at: key ifPresent: aPresentBlock ifAbsent: anAbsentBlock [

^ aPresentBlock value: (self
^ aPresentBlock cull: (self
at: key
ifAbsent: [ ^ anAbsentBlock value ])
]
Expand Down
Loading