diff --git a/src/Soil-Core-Tests/SoilPersistentDictionaryTest.class.st b/src/Soil-Core-Tests/SoilPersistentDictionaryTest.class.st index 4f901910..0a5736ca 100644 --- a/src/Soil-Core-Tests/SoilPersistentDictionaryTest.class.st +++ b/src/Soil-Core-Tests/SoilPersistentDictionaryTest.class.st @@ -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 [ @@ -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 } diff --git a/src/Soil-Serializer/SoilPersistentDictionary.class.st b/src/Soil-Serializer/SoilPersistentDictionary.class.st index f80073d9..5448947f 100644 --- a/src/Soil-Serializer/SoilPersistentDictionary.class.st +++ b/src/Soil-Serializer/SoilPersistentDictionary.class.st @@ -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 ]) ]