Skip to content

Commit

Permalink
Made control flow tests easier to read.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Apr 26, 2011
1 parent 9bfe084 commit a11ba3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
1 change: 0 additions & 1 deletion lib/block.fy
Expand Up @@ -35,7 +35,6 @@ class Block {
}

def while_true: work {
return_value = nil
{
call if_do: |val| {
work call: [val]
Expand Down
45 changes: 15 additions & 30 deletions tests/control_flow.fy
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit a11ba3f

Please sign in to comment.