def test_if(capfd): interpret(''' if (1) { print 2; } ''') out, err = capfd.readouterr() assert out == '2\n'
def test_func(capfd): interpret(''' func hello() { print "Hello World!"; } hello(); ''') out, err = capfd.readouterr() assert out == 'Hello World!\n'
def test_float_lt_int_error(capfd): with raises(Exception): interpret('1.5 < 5;')
def test_float_lt(capfd): interpret('print 1.5 < .5;') out, err = capfd.readouterr() assert out == 'False\n' and not err
def test_float_add_int_error(): with raises(Exception): interpret('1.5 + 5;')
def test_float_add(capfd): interpret('print 1.5 + .5;') out, err = capfd.readouterr() assert out == '2.0\n' and not err
def test_int_lt(capfd): interpret('print 1 < 5;') out, err = capfd.readouterr() assert out == 'True\n' and not err
def test_add_int_error(): with raises(Exception): interpret('1 + .5;')
def test_string_lt(capfd): interpret('print "foo" < "bar";') out, err = capfd.readouterr() assert out == 'False\n' and not err
def test_print(capfd): interpret('print 1;') out, err = capfd.readouterr() assert out == '1\n'
def test_interp(): interpret('1 + 2;')
def test_while(): interpret('n = 0; while (n < 10) { n = n + 1; }')
def test_string_lt_other_error(capfd): with raises(Exception): interpret('"foo" < 5;')
def test_string_add(capfd): interpret('print "foo" + "bar";') out, err = capfd.readouterr() assert out == 'foobar\n' and not err
def test_int_add(capfd): interpret('print 1 + 5;') out, err = capfd.readouterr() assert out == '6\n' and not err
def test_string_add_other_error(): with raises(Exception): interpret('"foo" + 5;')
def main(i): interpret(codes[i])