[ioke-scm] [ioke~main:d81e366e] Add support for Condition#ignore
- From: olabini@kenai.com
- To: commits@ioke.kenai.com
- Subject: [ioke-scm] [ioke~main:d81e366e] Add support for Condition#ignore
- Date: Tue, 5 Jan 2010 14:27:38 +0000
Project: ioke
Repository: main
Revision: d81e366e6035b3e1ada11b37da088b88e241a558
Author: olabini
Date: 2010-01-05 14:27:10 UTC
Link:
Log Message:
------------
Add support for Condition#ignore
Revisions:
----------
d81e366e6035b3e1ada11b37da088b88e241a558
Modified Paths:
---------------
src/builtin/M05_ignoreErrors.ik
test/conditions_spec.ik
Diffs:
------
diff --git a/src/builtin/M05_ignoreErrors.ik b/src/builtin/M05_ignoreErrors.ik
index c1ac917..1220ca6 100644
--- a/src/builtin/M05_ignoreErrors.ik
+++ b/src/builtin/M05_ignoreErrors.ik
@@ -1,6 +1,6 @@
DefaultBehavior FlowControl ignoreErrors = dmacro("takes one or two pices of
code. runs the first code segment and returns nil if it signals an
-error. If a second argument of code is given, evalautes this only when an
error is encountered
+error. If a second argument of code is given, evaluates this only when an
error is encountered
and uses the result to return. if everything works as expected, ignoreErrors
will just
return the result of the first evaluation",
@@ -11,3 +11,16 @@ return the result of the first evaluation",
[protectedCode, otherwiseCode]
bind(rescue(Condition Error, fn(c, otherwiseCode evaluateOn(call ground,
call ground))),
protectedCode evaluateOn(call ground, call ground)))
+
+Condition ignore = dmacro("takes one or two pices of code. runs the first
code segment and returns nil if it signals an
+the receiver. If a second argument of code is given, evaluates this only
when an error is encountered
+and uses the result to return. if everything works as expected, ignore will
just
+return the result of the first evaluation",
+
+ [protectedCode]
+ bind(rescue(self, fn(c, nil)),
+ protectedCode evaluateOn(call ground, call ground)),
+
+ [protectedCode, otherwiseCode]
+ bind(rescue(self, fn(c, otherwiseCode evaluateOn(call ground, call
ground))),
+ protectedCode evaluateOn(call ground, call ground)))
diff --git a/test/conditions_spec.ik b/test/conditions_spec.ik
index 3f7be93..2d21c6d 100644
--- a/test/conditions_spec.ik
+++ b/test/conditions_spec.ik
@@ -609,6 +609,52 @@ describe(Condition,
Condition should have kind("Condition")
)
+ describe("ignore",
+ it("should evaluate the code and return the value",
+ x = 42
+ y = 55
+ Condition ignore(x+y) should == 97
+ )
+
+ it("should return nil if any kind of condition is signalled in the code",
+ Condition ignore(10/0) should be nil
+ Condition ignore(signal!("blah")) should be nil
+ )
+
+ it("should not fail when another condition is signalled",
+ Condition Error ignore(
+ signal!("Hello World!")
+ 42) should == 42
+ )
+
+ it("should be possible to define a value to return when an error is
encountered",
+ Condition ignore(
+ 10/0,
+ :failure) should == :failure
+ )
+
+ it("should only evaluate the second part when an error actually happens",
+ called = false
+ Condition ignore(
+ 42,
+ called = true
+ nil) should == 42
+ called should be false
+ )
+
+ it("should only ignore the specific condition",
+ cc = Condition mimic
+
+ cc ignore(
+ signal!("BLAH")
+ 43) should == 43
+
+ cc ignore(
+ signal!(cc)
+ 43) should be nil
+ )
+ )
+
describe(Condition Default,
it("should have the right kind",
Condition Default should have kind("Condition Default")
|
[ioke-scm] [ioke~main:d81e366e] Add support for Condition#ignore |
olabini | 01/05/2010 |





