Browse files

Made control flow tests easier to read.

  • Loading branch information...
1 parent 9bfe084 commit a11ba3f6742e9b2de16d3ca2291f54e7fa14ff27 @bakkdoor committed Apr 26, 2011
Showing with 15 additions and 31 deletions.
  1. +0 −1 lib/block.fy
  2. +15 −30 tests/control_flow.fy
View
1 lib/block.fy
@@ -35,7 +35,6 @@ class Block {
}
def while_true: work {
- return_value = nil
{
call if_do: |val| {
work call: [val]
View
45 tests/control_flow.fy
@@ -81,29 +81,26 @@ FancySpec describe: "Control Flow" with: {
x = 0
until: { x == 10 } do: {
x = x + 1
- (x == 5) if_do: { break }
+ { break } if: (x == 5)
}
x == 5 should == true
}
it: "should break from an iteration with return value" for: 'break: when: {
x = 0
- y = (
- { x == 10 } until: {
- x = x + 1
- (x == 5) if_do: {
- break: 42
- }
- }
- )
+ y = until: { x == 10 } do: {
+ x = x + 1
+ { break: 42 } if: (x == 5)
+ }
+
x should == 5
y should == 42
}
it: "should skip an iteration over a Range" for: 'next when: {
total = 0
(1..10) each: |i| {
- (i == 5) if_do: { next }
+ { next } if: (i == 5)
total = total + i
}
total should == 50
@@ -112,7 +109,7 @@ FancySpec describe: "Control Flow" with: {
it: "should skip an iteration over an Array" for: 'next when: {
total = 0
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] each: |i| {
- (i == 5) if_do: { next }
+ { next } if: (i == 5)
total = total + i
}
total should == 50
@@ -121,7 +118,7 @@ FancySpec describe: "Control Flow" with: {
it: "should skip an iteration over an Hash" for: 'next when: {
total = 0
<['a => 1, 'b => 2, 'c => 3, 'd => 4, 'e => 5, 'f => 6]> each: |k v| {
- (k == 'd) if_do: { next }
+ { next } if: (k == 'd)
total = total + v
}
total should == 17
@@ -130,55 +127,43 @@ FancySpec describe: "Control Flow" with: {
it: "stops any loop type at the correct spot" for: 'break when: {
i = 0
loop: {
- if: (i == 3) then: {
- break
- }
+ { break } if: (i == 3)
i = i + 1
}
i should == 3
i = 0
while: { i < 5 } do: {
- if: (i == 3) then: {
- break
- }
+ { break } if: (i == 3)
i = i + 1
}
i should == 3
i = 0
0 upto: 5 do: |n| {
i = n
- if: (n == 3) then: {
- break
- }
+ { break } if: (n == 3)
}
i should == 3
}
it: "stops any loop type at the correct spot" for: 'break: when: {
i = 0
loop: {
- if: (i == 2) then: {
- break: i
- }
+ { break: i } if: (i == 2)
i = i + 1
} . should == 2
i = 0
while: { i < 5 } do: {
- if: (i == 2) then: {
- break: i
- }
+ { break: i } if: (i == 2)
i = i + 1
} . should == 2
i = 0
0 upto: 5 do: |n| {
i = n
- if: (n == 2) then: {
- break: n
- }
+ { break: n } if: (n == 2)
}
i should == 2
}

0 comments on commit a11ba3f

Please sign in to comment.