/test/passenger_pane/NuBacon/bacon.nu
Unknown | 94 lines | 81 code | 13 blank | 0 comment | 0 complexity | 284279996fe2da6c27c69bace575749a MD5 | raw file
1(load "NuBacon/bacon_summary") 2(load "NuBacon/bacon_specification") 3(load "NuBacon/bacon_context") 4(load "NuBacon/bacon_should") 5(load "NuBacon/bacon_macros") 6 7(class Bacon is NSObject 8 (ivars (id) contexts 9 (id) currentContextIndex) 10 11 (+ sharedInstance is $BaconSharedInstance) 12 13 (- init is 14 (super init) 15 (set @contexts (NSMutableArray array)) 16 (set @currentContextIndex 0) 17 self 18 ) 19 20 (- addContext:(id)context is 21 (@contexts addObject:context) 22 ) 23 24 (- (id) run is 25 (if (> (@contexts count) 0) 26 (then 27 (set context (self currentContext)) 28 (context setDelegate:self) 29 (context performSelector:"run" withObject:nil afterDelay:0) 30 ; TODO check if this is really the right way to do it? 31 ; TODO make this work nicely when there is already a runloop, like in an (iOS) app runner 32 ;((NSRunLoop mainRunLoop) runUntilDate:(NSDate dateWithTimeIntervalSinceNow:0.1)) 33 ;((NSRunLoop mainRunLoop) runUntilDate:(NSDate distantFuture)) 34 (try 35 ((NSApplication sharedApplication) run) 36 (catch (e)) 37 ; running on iOS most probably 38 ) 39 ) 40 (else 41 ; DONE 42 ($BaconSummary print) 43 ) 44 ) 45 ) 46 47 (- (id) currentContext is 48 (@contexts objectAtIndex:@currentContextIndex) 49 ) 50 51 (- (id) contextDidFinish:(id)context is 52 (if (< (+ @currentContextIndex 1) (@contexts count)) 53 (then 54 (set @currentContextIndex (+ @currentContextIndex 1)) 55 (self run) 56 ) 57 (else 58 ; DONE! 59 ($BaconSummary print) 60 (try 61 ((NSApplication sharedApplication) terminate:self) 62 (catch (e)) 63 ; running on iOS most probably 64 ) 65 ) 66 ) 67 ) 68) 69(set $BaconSharedInstance ((Bacon alloc) init)) 70 71; TODO How should I subclass NSException? 72(class BaconError is NSObject 73 (ivar (id) description) 74 75 (- (id) initWithDescription:(id)description is 76 (self init) 77 (set @description description) 78 self 79 ) 80 81 (- (id) name is "BaconError") 82 (- (id) reason is @description) 83) 84 85(class NSObject 86 (- (id) instanceEval:(id)block is 87 (set c (send block context)) 88 (send block evalWithArguments:nil context:c self:self) 89 ) 90 91 (- (id) should is ((BaconShould alloc) initWithObject:self)) 92 (- (id) should:(id)block is (((BaconShould alloc) initWithObject:self) satisfy:nil block:block)) 93) 94