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

    hello();
    ''')

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