inspect | = | "DefaultBehavior Conditions" |
contains behavior related to conditions
-
none
- availableRestarts(condition Condition)
- bind(+[bindablesAndCode])
- error!(datum, +:errorArguments)
- findRestart(nameOrRestart)
- handle(+conditionsAndAction)
- invokeRestart(nameOrRestart, +arguments)
- rescue(+conditionsAndAction)
- restart([name] nil, report: nil, test: nil, action)
- signal!(datum, +:conditionArguments)
- warn!(datum, +:krest)
takes an optional condition to specify - returns all restarts that are applicable to that condition. closer restarts will be first in the list
- - should return the available restarts
[ show source ]
r = restart(fox, fn) bind(r, availableRestarts [](0) should ==(r))
- - should use the test of a restart to see if it's correct
[ show source ]
r = restart(fox, fn) Ground Cond1 = Condition mimic Ground calledRTest = false r test = fn(c, Ground calledRTest = true c ==(Cond1)) bind(r, availableRestarts [](0) should not ==(r)) calledRTest should be true
- - should get the restarts applicable
[ show source ]
r = restart(fox, fn) Ground Cond1 = Condition mimic r test = fn(c, c ==(Cond1)) bind(r, availableRestarts(Cond1) [](0) should ==(r))
will evaluate all arguments, and expects all except for the last to be a Restart. bind will associate these restarts for the duration of the execution of the last argument and then unbind them again. it will return the result of the last argument, or if a restart is executed it will instead return the result of that invocation.
- - should evaluate it's last argument and return the result of that
[ show source ]
bind should be nil bind(42) should ==(42) bind( restart(fn), restart(fn), restart(fn), 42 +(43) 10 +(12)) should ==(22)
- - should fail if any argument except the last doesn't evaluate to a restart
[ show source ]
fn(bind(10, 10)) should signal(Condition Error Type IncorrectType)
takes the same kind of arguments as 'signal!', and will signal a condition. the default condition used is Condition Error Default. if no rescue or restart is invoked error! will report the condition to System err and exit the currently running Ioke VM. this might be a problem when exceptions happen inside of running Java code, as callbacks and so on.. if 'System currentDebugger' is non-nil, it will be invoked before the exiting of the VM. the exit can only be avoided by invoking a restart. that means that error! will never return.
- - should signal a Condition Error Default by default
[ show source ]
x = bind( rescue(fn(c, c)), error!("something")) x text should ==("something") x should have kind("Condition Error Default")
- - should take an existing condition
[ show source ]
c1 = Condition mimic cx = nil bind( rescue(fn(c, cx = c)), error!(c1)) cx should ==(c1)
- - should take a condition mimic and a set of keyword parameters
[ show source ]
cx = bind( rescue(fn(c, c)), error!(Condition, foo: "bar")) cx foo should ==("bar") cx should not ==(Condition)
takes either a name (as a symbol) or a Restart instance. if the restart is active, will return that restart, otherwise returns nil.
- - should return nil if it can't find the named restart
[ show source ]
findRestart(:foo) should be nil bind( restart(bar, fn), findRestart(:foo)) should be nil
- - should return the restart if found
[ show source ]
bind( restart(foo, fn), findRestart(:foo)) should not be nil re = restart(foo, fn) bind( re, findRestart(:foo)) should ==(re)
- - should return the innermost restart for the name
[ show source ]
re1 = restart(foo, fn) re2 = restart(foo, fn) re3 = restart(foo, fn) bind( re1, bind( re2, bind( re3, findRestart(:foo)))) should ==(re3) re1 = restart(foo, fn) re2 = restart(foo, fn) re3 = restart(foo, fn) bind( re1, bind( re2, bind( re3, bind( restart(bar, fn), findRestart(:foo))))) should ==(re3)
- - should fail when given nil
[ show source ]
fn(findRestart(nil)) should signal(Condition Error Type IncorrectType) fn(bind( restart, findRestart(nil))) should signal(Condition Error Invocation TooFewArguments) fn(bind( restart(foo, fn), findRestart(nil))) should signal(Condition Error Type IncorrectType)
- - should take a restart as argument and return it when that restart is active
[ show source ]
re = restart(foo, fn) bind( restart(foo, fn), bind( re, bind( restart(foo, fn), findRestart(re)))) should ==(re)
- - should take a restart as argument and return nil when that restart is not active
[ show source ]
re = restart(foo, fn) bind( restart(foo, fn), bind( restart(foo, fn), findRestart(re))) should be nil
takes zero or more arguments that should evaluate to a condition mimic - this list will match all the conditions this Handler should be able to catch. the last argument is not optional, and should be something activatable that takes one argument - the condition instance. will return a Handler mimic.
- - should take only one argument, and in that case catch all Conditions
[ show source ]
handle(fn(e, 42)) handler call(1) should ==(42) handle(fn) conditions should ==([](Condition))
- - should take one or more Conditions to catch
[ show source ]
c1 = Condition mimic c2 = Condition mimic handle(c1, c2, fn(e, 42)) conditions should ==([](c1, c2))
- - should return something that has kind Handler
[ show source ]
handle(fn) should have kind("Handler")
takes either a name (as a symbol) or a Restart instance. if the restart is active, will transfer control to it, supplying the rest of the given arguments to that restart.
- - should fail if no restarts of the name is active
[ show source ]
fn(invokeRestart(:bar)) should signal(Condition Error RestartNotActive) fn(bind( restart(foo, fn), invokeRestart(:bar))) should signal(Condition Error RestartNotActive) fn(bind( restart(foo, fn), bind( restart(foo, fn), invokeRestart(:bar)))) should signal(Condition Error RestartNotActive)
- - should fail if no restarts of the restart is active
[ show source ]
fn(re = restart(bar, fn) invokeRestart(re)) should signal(Condition Error RestartNotActive) fn(re = restart(bar, fn) bind( restart(foo, fn), invokeRestart(re))) should signal(Condition Error RestartNotActive) fn(re = restart(bar, fn) bind( restart(foo, fn), bind( restart(foo, fn), invokeRestart(re)))) should signal(Condition Error RestartNotActive)
- - should invoke a restart when given the name
[ show source ]
x = 1 bind( restart(foo, fn(x = 42 13)), invokeRestart(:foo)) should ==(13) x should ==(42)
- - should invoke a restart when given the restart
[ show source ]
x = 1 re = restart(foo, fn(x = 42 13)) bind( re, invokeRestart(re)) should ==(13) x should ==(42)
- - should invoke the innermost restart when given the name
[ show source ]
x = 1 invoked = 0 bind( restart(foo, fn(++(invoked) x = 42 13)), bind( restart(foo, fn(++(invoked) x = 43 14)), bind( restart(foo, fn(++(invoked) x = 44 15)), invokeRestart(:foo)))) should ==(15) x should ==(44) invoked should ==(1)
- - should invoke the right restart when given an instance
[ show source ]
x = 1 invoked = 0 re = restart(foo, fn(++(invoked) x = 24 16)) bind( restart(foo, fn(++(invoked) x = 42 13)), bind( re, bind( restart(foo, fn(++(invoked) x = 43 14)), bind( restart(foo, fn(++(invoked) x = 44 15)), invokeRestart(re))))) should ==(16) x should ==(24) invoked should ==(1)
- - should take arguments and pass these along to the restart
[ show source ]
bind( restart(foo, fn(x, x)), invokeRestart(:foo, 13)) should ==(13) bind( restart(foo, fn(x, y, x)), invokeRestart(:foo, 13, 15)) should ==(13) bind( restart(foo, fn(x, y, y)), invokeRestart(:foo, 13, 15)) should ==(15)
takes zero or more arguments that should evaluate to a condition mimic - this list will match all the conditions this Rescue should be able to catch. the last argument is not optional, and should be something activatable that takes one argument - the condition instance. will return a Rescue mimic.
- - should take only one argument, and in that case catch all Conditions
[ show source ]
rescue(fn(e, 42)) handler call(1) should ==(42) rescue(fn) conditions should ==([](Condition))
- - should take one or more Conditions to catch
[ show source ]
c1 = Condition mimic c2 = Condition mimic rescue(c1, c2, fn(e, 42)) conditions should ==([](c1, c2))
- - should return something that has kind Rescue
[ show source ]
rescue(fn) should have kind("Rescue")
takes one optional unevaluated parameter (this should be the first if provided), that is the name of the restart to create. this will default to nil. takes two keyword arguments, report: and test:. These should both be lexical blocks. if not provided, there will be reasonable defaults. the only required argument is something that evaluates into a lexical block. this block is what will be executed when the restart is invoked. will return a Restart mimic.
- - should take an optional unevaluated name as first argument
[ show source ]
restart(blub, fn) name should ==(:blub)
- - should return something that has kind Restart
[ show source ]
restart(fn) should have kind("Restart")
- - should take an optional report: argument
[ show source ]
rp = fn("report" println) restart(report: rp, fn) report should ==(rp)
- - should take an optional test: argument
[ show source ]
t1 = fn("test" println) restart(test: t1, fn) test should ==(t1)
- - should take a code argument
[ show source ]
restart(fn(32 +(43))) code call should ==(75)
takes one or more datums descibing the condition to signal. this datum can be either a mimic of a Condition, in which case it will be signalled directly, or it can be a mimic of a Condition with arguments, in which case it will first be mimicked and the arguments assigned in some way. finally, if the argument is a Text, a mimic of Condition Default will be signalled, with the provided text.
- - should take an existing condition
[ show source ]
c1 = Condition mimic cx = nil bind( rescue(fn(c, cx = c)), signal!(c1)) cx should ==(c1)
- - should take a condition mimic and a set of keyword parameters
[ show source ]
cx = bind( rescue(fn(c, c)), signal!(Condition, foo: "bar")) cx foo should ==("bar") cx should not ==(Condition)
- - should not execute a handler that's not applicable
[ show source ]
x = 1 C1 = Condition mimic bind( handle(C1, fn(c, x = 42)), signal!("foo")) x should ==(1)
- - should execute one applicable handler
[ show source ]
x = 1 bind( handle(fn(c, x = 42)), signal!("foo")) x should ==(42)
- - should execute two applicable handler, among some non-applicable
[ show source ]
x = [] C1 = Condition mimic bind( handle(C1, fn(c, x <<(13))), bind( handle(fn(c, x <<(15))), bind( handle(C1, fn(c, x <<(17))), bind( handle(Condition, fn(c, x <<(19))), signal!("foo"))))) x should ==([](19, 15))
- - should not unwind the stack when invoking handlers
[ show source ]
x = [] bind( handle(fn(c, x <<(2))), x <<(1) signal!("foo") x <<(3) ) x should ==([](1, 2, 3))
- - should only invoke handlers up to the limit of the first applicable rescue
[ show source ]
x = [] bind( handle(fn(c, x <<(1))), handle(fn(c, x <<(2))), rescue(fn(c, x <<(3))), handle(fn(c, x <<(4))), bind( handle(fn(c, x <<(5))), handle(fn(c, x <<(6))), bind( handle(fn(c, x <<(7))), signal!("Foo")))) x should ==([](7, 6, 5, 4, 3))
- - should do nothing if no rescue has been registered for it
[ show source ]
x = 1 signal!("foo") ++(x) x should ==(2) x = 1 C2 = Condition mimic bind( rescue(C2, fn(e, x = 42)), ++(x) signal!("something") ++(x)) x should ==(3)
- - should transfer control if the condition is matched
[ show source ]
x = 1 bind( rescue(fn(e, x = 42)), signal!("something") x = 13) x should ==(42)
- - should transfer control to the innermost handler that matches
[ show source ]
x = 1 C1 = Condition mimic C2 = Condition mimic bind( rescue(C1, fn(e, x = 42)), bind( rescue(fn(e, x = 444)), bind( rescue(C2, fn(e, x = 222)), signal!("something")))) x should ==(444)
- - should invoke the handler with the signalled condition
[ show source ]
x = 1 bind( rescue(fn(e, x = e text)), signal!("something") x = 13) x should ==("something")
- - should return the value of the handler from the bind of the rescue in question
[ show source ]
bind( rescue(fn(e, 42)), signal!("something") x = 13) should ==(42)
takes the same kind of arguments as 'signal!', and will signal a condition. the default condition used is Condition Warning Default. a restart called 'ignore' will be established. if no rescue or restart is invoked warn! will report a warning to System err.
[ show source ]
method(datum, +:krest, if(datum kind?("Text"), datum = Condition Warning Default with(text: datum)) bind( restart(ignore, fn(datum)), result = signal!(datum, *(krest)) System err println("WARNING: #{result report}") result))
- - should signal a Condition Warning Default by default
[ show source ]
x = bind( rescue(fn(c, c)), warn!("something")) x text should ==("something") x should have kind("Condition Warning Default")
- - should take an existing condition
[ show source ]
c1 = Condition mimic cx = nil bind( rescue(fn(c, cx = c)), warn!(c1)) cx should ==(c1)
- - should take a condition mimic and a set of keyword parameters
[ show source ]
cx = bind( rescue(fn(c, c)), warn!(Condition, foo: "bar")) cx foo should ==("bar") cx should not ==(Condition)
- - should establish an ignore-restart
[ show source ]
gah = nil bind( rescue(fn(c, gah)), handle(fn(c, gah = findRestart(:ignore))), warn!("something")) should not be nil