Beispiel #1
0
def test_demo(capsys, source, result):
    with open(source, 'r') as f:
        reload(Parser)
        reload(Generator)
        reload(Machine)
        reload(Processor)
        Parser.build('Program')
        ast = Parser.parse(f.read())
        code = Generator.generate(ast)
        Machine.load(code.splitlines(True))
        Machine.run()
        out, err = capsys.readouterr()
        assert out == result
Beispiel #2
0
def test_demo(capsys, source, result):
    with open(source, 'r') as f:
        reload(Parser)
        reload(Generator)
        reload(Machine)
        reload(Processor)
        Parser.build('Program')
        ast = Parser.parse(f.read())
        code = Generator.generate(ast)
        Machine.load(code.splitlines(True))
        Machine.run()
        out, err = capsys.readouterr()
        assert out == result
Beispiel #3
0
def test_read(capsys):
    with open('demo/read.js', 'r') as f:
        mock_stdin = StringIO.StringIO("5\nstring\n")
        sys.stdin = mock_stdin

        reload(Parser)
        reload(Generator)
        reload(Machine)
        reload(Processor)
        Parser.build('Program')
        ast = Parser.parse(f.read())
        code = Generator.generate(ast)
        Machine.load(code.splitlines(True))
        Machine.run()
        out, err = capsys.readouterr()
        assert out == "Please enter an integer.\n5\nPlease enter an string.\n'string'\n"

        sys.stdin = sys.__stdin__
Beispiel #4
0
def test_read(capsys):
    with open('demo/dynamic.js', 'r') as f:
        mock_stdin = StringIO.StringIO("a\nb\nc\n")
        sys.stdin = mock_stdin

        reload(Parser)
        reload(Generator)
        reload(Machine)
        reload(Processor)
        Parser.build('Program')
        ast = Parser.parse(f.read())
        code = Generator.generate(ast)
        Machine.load(code.splitlines(True))
        Machine.run()
        out, err = capsys.readouterr()
        assert out == "Please enter an string.\n{'a': 'a'}\nPlease enter an string.\n{'a': 'a', 'b': 'b'}\n" \
                      "Please enter an string.\n{'a': 'a', 'b': 'b', 'c': 'c'}\n"
        sys.stdin = sys.__stdin__
Beispiel #5
0
def test_read(capsys):
    with open('demo/if-else.js', 'r') as f:
        mock_stdin = StringIO.StringIO("20\n")
        sys.stdin = mock_stdin

        reload(Parser)
        reload(Generator)
        reload(Machine)
        reload(Processor)
        Parser.build('Program')
        ast = Parser.parse(f.read())
        code = Generator.generate(ast)
        Machine.load(code.splitlines(True))
        Machine.run()
        out, err = capsys.readouterr()
        assert out == "'Guess how old I am?'\nPlease enter an integer.\n'Hey! You got it.'\n"

        sys.stdin = sys.__stdin__