Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 78 lines (65 sloc) 1.387 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
assert '10', %q{
i = 0
while i < 10
i += 1
end
p i
}

assert '', "while false; p :nok; end"
assert '', "while nil; p :nok; end"

assert ':ok', "x = 42; while x; p :ok; x = false; end"
assert ':ok', "x = 42; while x; p :ok; x = nil; end"

assert 'nil', "x = while nil; end; p x"

assert "42", "a=[20,10,5,5,1,1]; n = 0; for i in a; n+=i; end; p n"
assert "42", "a=[1,1,1,42]; for i in a; end; p i"
assert '42', %{
def f(x)
for y in 1..1
p x
end
end
f(42)
}

assert "42", "x = while true; break 42; end; p x"
assert "nil", "x = while true; break; end; p x"
assert "42", "i = 0; while i < 100; break if i == 42; i += 1; end; p i"

assert "42", "i = j = 0; while i < 100; i += 1; next if i > 42; j += 1; end; p j"

assert "42", %q{
i = 0; x = nil
while i < 1
x = 1.times { break 41 }
i += 1
end
p x+i
}

assert "42", %q{
x = nil
1.times {
x = while true; break 41; end
x += 1
}
p x
}

assert 'nil', "x = until 123; 42; end; p x"
assert '42', 'x = nil; until x; x = 42; end; p x'
assert '42', "x = until nil; break 42; end; p x"
assert "nil", "x = until nil; break; end; p x"

assert "42", %q{
foo = [42]
until (x = foo.pop).nil?
p x
end
}

assert ':ok', %{
a = nil
for b in [:a, :b].sort {|x, y| x <=> y}
c = nil
end
p :ok
}

assert ':ok', %{
p (while true do
break :ok
break :ko
end)
}
Something went wrong with that request. Please try again.