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

    hello();
    ''')

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