Exemplo n.º 1
0
def test_sigma_iterative(capsys, src, output):
    src = sigma_while_src + '\n' + src
    source_file = io.StringIO(src)
    subpascal.run(source_file)
    captured = capsys.readouterr()
    assert '' == captured.err
    assert output == captured.out
Exemplo n.º 2
0
def test_run_unexpected_close_paren_example(capsys):
    source_file = io.StringIO('(+ 18 35))')
    run(source_file)
    captured = capsys.readouterr()
    assert '' == captured.out
    assert "*** Unexpected close parenthesis.\n" == captured.err
Exemplo n.º 3
0
def test_run_single_line(capsys):
    source_file = io.StringIO('(print 123)')
    run(source_file)
    captured = capsys.readouterr()
    assert '123\n' == captured.out
Exemplo n.º 4
0
def test_run_undefined_func_example(capsys):
    source_file = io.StringIO('(spam 18 35)')
    run(source_file)
    captured = capsys.readouterr()
    assert '' == captured.out
    assert "*** Undefined function: 'spam'.\n" == captured.err
Exemplo n.º 5
0
def test_run_gcd_example(capsys):
    source_file = io.StringIO(GCD_EXAMPLE)
    run(source_file)
    captured = capsys.readouterr()
    assert '1\n' == captured.out
Exemplo n.º 6
0
def test_run_doubling_example(capsys):
    source_file = io.StringIO(DOUBLING_EXAMPLE)
    run(source_file)
    captured = capsys.readouterr()
    assert '1\n2\n4\n8\n16\n32\n64\n128\n256\n' == captured.out
Exemplo n.º 7
0
def test_run_multiple_lines(capsys):
    source_file = io.StringIO('(print 123)\n(print 456)')
    run(source_file)
    captured = capsys.readouterr()
    assert '123\n456\n' == captured.out