David T. Lewis uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-tonyg.331.mcz==================== Summary ====================
Name: KernelTests-tonyg.331
Author: tonyg
Time: 31 January 2018, 11:38:54.000311 pm
UUID: 76ecc634-5cf0-43e2-8e17-3dcf9ba18408
Ancestors: KernelTests-nice.330
Updated and new tests for Promise, to match Kernel-tonyg.1148
=============== Diff against KernelTests-nice.330 ===============
Item was changed:
----- Method: PromiseTest>>testCannotRejectFulfilledPromise (in category 'testing - monad') -----
testCannotRejectFulfilledPromise
| p |
p := Promise unit: 1.
+ p rejectWith: Error new.
+ self assert: p isResolved.
+ self assert: 1 equals: p value.
+ !
- self should: [p rejectWith: Error new] raise: Error.!
Item was changed:
----- Method: PromiseTest>>testCannotResolveaRejectedPromise (in category 'testing - monad') -----
testCannotResolveaRejectedPromise
+ | p e |
- | p |
p := Promise new.
+ e := Error new.
+ p rejectWith: e.
+ p resolveWith: 1.
+ self assert: p isRejected.
+ self assert: p error == e.
+ !
- p rejectWith: Error new.
- self should: [p resolveWith: 1] raise: Error.!
Item was added:
+ ----- Method: PromiseTest>>testCollapsesChainsOfPromises (in category 'testing - monad') -----
+ testCollapsesChainsOfPromises
+ "The monadic bind operator has signature (m a -> (a -> m b) -> m b): that is, in our setting,
+ the block given to `then:` is expected to return a *Promise* of a value, not a value directly.
+ It is convenient to accept non-promise values and automatically lift them into the monad,
+ but we must also ensure we treat the case where a `then:`-block yields a Promise correctly."
+ | p q r |
+ p := Promise new.
+ q := p then: [:v | Promise unit: v * 2].
+ r := q then: [:v | Promise unit: v + 1].
+ p resolveWith: 4.
+ self assert: 4 * 2 equals: q value.
+ self assert: (4 * 2 + 1) equals: r value.!
Item was added:
+ ----- Method: PromiseTest>>testFirstResolutionWins (in category 'testing - monad') -----
+ testFirstResolutionWins
+ | p |
+ p := Promise new.
+ p resolveWith: 1.
+ p resolveWith: 2.
+ self assert: p isResolved.
+ self assert: p value == 1.
+ !