Example #1
0
def test_if(capfd):
    interpret('''
    if (1) {
       print 2;
    }
    ''')
    out, err = capfd.readouterr()
    assert out == '2\n'
Example #2
0
def test_func(capfd):
    interpret('''
    func hello() {
      print "Hello World!";
    }

    hello();
    ''')

    out, err = capfd.readouterr()
    assert out == 'Hello World!\n'
Example #3
0
def test_float_lt_int_error(capfd):
    with raises(Exception):
        interpret('1.5 < 5;')
Example #4
0
def test_float_lt(capfd):
    interpret('print 1.5 < .5;')
    out, err = capfd.readouterr()
    assert out == 'False\n' and not err
Example #5
0
def test_float_add_int_error():
    with raises(Exception):
        interpret('1.5 + 5;')
Example #6
0
def test_float_add(capfd):
    interpret('print 1.5 + .5;')
    out, err = capfd.readouterr()
    assert out == '2.0\n' and not err
Example #7
0
def test_int_lt(capfd):
    interpret('print 1 < 5;')
    out, err = capfd.readouterr()
    assert out == 'True\n' and not err
Example #8
0
def test_add_int_error():
    with raises(Exception):
        interpret('1 + .5;')
Example #9
0
def test_string_lt(capfd):
    interpret('print "foo" < "bar";')
    out, err = capfd.readouterr()
    assert out == 'False\n' and not err
Example #10
0
def test_print(capfd):
    interpret('print 1;')
    out, err = capfd.readouterr()
    assert out == '1\n'
Example #11
0
def test_interp():
    interpret('1 + 2;')
Example #12
0
def test_while():
    interpret('n = 0; while (n < 10) { n = n + 1; }')
Example #13
0
def test_string_lt_other_error(capfd):
    with raises(Exception):
        interpret('"foo" < 5;')
Example #14
0
def test_string_add(capfd):
    interpret('print "foo" + "bar";')
    out, err = capfd.readouterr()
    assert out == 'foobar\n' and not err
Example #15
0
def test_int_add(capfd):
    interpret('print 1 + 5;')
    out, err = capfd.readouterr()
    assert out == '6\n' and not err
Example #16
0
def test_string_add_other_error():
    with raises(Exception):
        interpret('"foo" + 5;')
Example #17
0
 def main(i):
     interpret(codes[i])