import unittest
from compyler.test.util import eval_code

stmts = [
# for
    ("""

for i in range(10):
    print i

print
print "DONE"

""","""0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nDONE\n"""),

# for continue
    ("""

for i in range(10):
    print i
    continue
    print "NOOO"

print
print "DONE"

""","""0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nDONE\n"""),

# for - break
    ("""

for i in range(10):
    print i
    if i == 5: break

print
print "DONE"

""","""0\n1\n2\n3\n4\n5\n\nDONE\n"""),

#while

    ("""

a = 0
b = 1

while a < 100:
    print "FIB: %s" % a
    a,b = b, a + b
    
print "DONE"

""","""FIB: 0
FIB: 1
FIB: 1
FIB: 2
FIB: 3
FIB: 5
FIB: 8
FIB: 13
FIB: 21
FIB: 34
FIB: 55
FIB: 89
DONE
"""),
]


class test_opcodes_loops(unittest.TestCase):
    def test_if_statements(self):
        for stmt in stmts:
            self.failUnless(eval_code(stmt[0],stmt[1],"exec",title='test_opcodes_loops'))
                
if __name__ == "__main__":
    unittest.main()

