Ejemplo n.º 1
0
 def test_for_loop(self, capsys):
     line = 'for (var i = 0; i < 10; i = i + 1) print i;'
     lox = Lox()
     lox.run(line)
     out, err = capsys.readouterr()
     assert err == ''
     assert out == "0.0\n1.0\n2.0\n3.0\n4.0\n5.0\n6.0\n7.0\n8.0\n9.0\n"
Ejemplo n.º 2
0
    def test_of(self, capsys):
        line = 'var s = "hi"; \
               if(s == "hi" or s == "hello") \
               print("Greetings");'

        lox = Lox()
        lox.run(line)
        out, err = capsys.readouterr()
        assert err == ''
        assert out == "Greetings\n"
Ejemplo n.º 3
0
    def test_num_parameters(self, capsys):
        line = 'fun add(a, b){ \
        return(a + b); \
        } \
        print(add(10, 5));'

        lox = Lox()
        lox.run(line)
        out, err = capsys.readouterr()
        assert err == ''
        assert out == "15.0\n"
Ejemplo n.º 4
0
    def test_string_parameters(self, capsys):
        line = 'fun strAppend(str1, str2) { \
        var str = str1 + str2; \
        return str;} \
        print(strAppend("foo", "bar"));'

        lox = Lox()
        lox.run(line)
        out, err = capsys.readouterr()
        assert err == ''
        assert out == "foobar\n"