Exemplo n.º 1
0
    def test_assigns_variable_to_variable(self):
        expr = """
        alpha = beta
        """

        repres = get_representation(expr)
        repres.should.contain('assign name alpha var beta')
Exemplo n.º 2
0
    def test_single_statement(self):
        expr = """
        10 * 100
        """

        # noinspection PyUnusedLocal
        repres = get_representation(expr)
Exemplo n.º 3
0
    def test_is_supported_with_no_args(self):
        expr = """
        number = Integer()
        """

        repres = get_representation(expr)
        repres.should.contain('assign name number instance name Integer')
Exemplo n.º 4
0
    def test_assigns_lists(self):
        expr = """
        arr = [1, 2, 3]
        """

        repres = get_representation(expr)
        repres.should.contain('assign name arr list int 1 int 2 int 3')
Exemplo n.º 5
0
    def test_works_for_expressions(self):
        expr = """        
            2 + 3 == 5
        """

        repres = get_representation(expr)
        repres.should.contain('comp add int 2 int 3 == int 5')
Exemplo n.º 6
0
    def test_multi_line(self):
        expr = """1 - 1
        2 * 3
        """

        # noinspection PyUnusedLocal
        repres = get_representation(expr)
Exemplo n.º 7
0
    def test_sum_larger_than_nine(self):
        expr = """
        240 / 24
        """

        repres = get_representation(expr)

        repres.should.equal('program block div int 240 int 24')
Exemplo n.º 8
0
    def test_is_supported_with_variables(self):
        expr = """
        class Object
        end
        """

        repres = get_representation(expr)
        repres.should.contain('program block class_ name Object block')
Exemplo n.º 9
0
    def test_works_for_unequal(self):
        expr = """
        12 != 24
        23.4 != 5.67
        """

        repres = get_representation(expr)
        repres.should.contain('comp int 12 != int 24')
        repres.should.contain('comp float 23.4 != float 5.67')
Exemplo n.º 10
0
    def test_is_supported_with_args(self):
        expr = """
        number = Integer(1)
        items = Items(1, 2, 3)
        """

        repres = get_representation(expr)
        repres.should.contain('assign name number instance name Integer args arg int 1')
        repres.should.contain('assign name items instance name Items args arg int 1 , arg int 2 , arg int 3')
Exemplo n.º 11
0
    def test_prints_boolean_variables(self):
        expr = """
        delta = true
        print(delta)
        """

        repres = get_representation(expr)
        repres.should.contain('assign name delta boolean true')
        repres.should.contain('print var delta')
Exemplo n.º 12
0
    def test_prints_variables(self):
        expr = """
        alpha = 1 + 4
        print(alpha)
        """

        repres = get_representation(expr)
        repres.should.contain('assign name alpha add int 1 int 4')
        repres.should.contain('print var alpha')
Exemplo n.º 13
0
    def test_supports_continue(self):
        expr = """
        for item in list
            continue            
        end
        """

        repres = get_representation(expr)
        repres.should.contain('for_ name item var list')
        repres.should.contain('block continue')
Exemplo n.º 14
0
    def test_is_supported_with_variables(self):
        expr = """
        for item in list
            print(item)
        end
        """

        repres = get_representation(expr)
        repres.should.contain('for_ name item var list')
        repres.should.contain('block print var item')
Exemplo n.º 15
0
    def test_supports_break(self):
        expr = """
        for item in list
            break            
        end
        """

        repres = get_representation(expr)
        repres.should.contain('for_ name item var list')
        repres.should.contain('block break')
Exemplo n.º 16
0
    def test_is_supported_with_list(self):
        expr = """
        for item in [1, 2, 3]
            print(item)
        end
        """

        repres = get_representation(expr)
        repres.should.contain('for_ name item list int 1 int 2 int 3')
        repres.should.contain('block print var item')
Exemplo n.º 17
0
    def test_multiline_expression(self):
        expr = """
        240 / 24
        240 + 24
        """

        repres = get_representation(expr)

        repres.should.contain('div int 240 int 24')
        repres.should.contain('add int 240 int 24')
Exemplo n.º 18
0
    def test_works_for_variable(self):
        expr = """
        green = true
        if green
            band = "day"
        end
        """

        repres = get_representation(expr)
        repres.should.contain('assign name green boolean true ')
        repres.should.contain('if_ var green block')
        repres.should.contain('assign name band string "day"')
Exemplo n.º 19
0
    def test_is_supported(self):
        expr = """
        class Integer
            def do_it(val)
            end
        end
        
        """

        repres = get_representation(expr)
        repres.should.contain('class_ name Integer')
        repres.should.contain('def_ name do_it params param name val block')
Exemplo n.º 20
0
    def test_supports_typed_parameters(self):
        expr = """
        class Integer
            def :init(val::Cint32)
            end
        end

        """

        repres = get_representation(expr)
        repres.should.contain('class_ name Integer')
        repres.should.contain('ctor_ name init params param name val Cint32')
Exemplo n.º 21
0
    def test_is_supported_for_no_args(self):
        expr = """
        class Integer
            def :init()
            end
        end
        
        """

        repres = get_representation(expr)
        repres.should.contain('class_ name Integer')
        repres.should.contain('ctor_ name init')
Exemplo n.º 22
0
    def test_supports_multiple_untyped_parameters(self):
        expr = """
        class Integer
            def :init(val, another)
            end
        end

        """

        repres = get_representation(expr)
        repres.should.contain('class_ name Integer')
        repres.should.contain('ctor_ name init params param name val , param name another')
Exemplo n.º 23
0
    def test_works_for_booleans_with_no_else(self):
        expr = """
        if true
            a = 1
        end
        print(a)
        """

        repres = get_representation(expr)
        repres.should.contain('if_ boolean true block ')
        repres.should.contain('assign name a int 1 ')
        repres.should.contain('print var a')
Exemplo n.º 24
0
    def test_assigns_variable_to_constant(self):
        expr = """
        alpha = 123
        beta = 23.45
        gamma = "a j g"
        delta = true
        """

        repres = get_representation(expr)
        repres.should.contain('assign name alpha int 123')
        repres.should.contain('assign name beta float 23.45')
        repres.should.contain('assign name gamma string "a j g"')
        repres.should.contain('assign name delta boolean true')
Exemplo n.º 25
0
    def test_has_a_body(self):
        expr = """
        class Integer
            def :init(val)
                true
            end
        end

        """

        repres = get_representation(expr)
        repres.should.contain('class_ name Integer')
        repres.should.contain('ctor_ name init params param name val block boolean true')
Exemplo n.º 26
0
    def test_assigns_variable_to_expression(self):
        expr = """
        alpha = 1 + 4
        beta = 2 * 3 / 4 - 1
        delta =  2 * (3 / (4 - 1))
        """

        repres = get_representation(expr)
        repres.should.contain('assign name alpha add int 1 int 4')
        repres.should.contain(
            'assign name beta sub div mul int 2 int 3 int 4 int 1')
        repres.should.contain(
            'assign name delta mul int 2 div int 3 sub int 4 int 1')
Exemplo n.º 27
0
    def test_supports_types(self):
        expr = """
        class Integer
            def do_it(val::Cint32)
                true
            end
        end
        
        """

        repres = get_representation(expr)
        repres.should.contain('class_ name Integer')
        repres.should.contain(
            'def_ name do_it params param name val Cint32 block boolean true')
Exemplo n.º 28
0
    def test_works_for_greater_than_and_less_than(self):
        expr = """
        24123 >= 24
        10 <= 12
        12.3 >= 24.23
        10.11 <= 12.43
        """

        repres = get_representation(expr)
        repres.should.contain('comp int 24123 >= int 24')
        repres.should.contain('comp int 10 <= int 12')

        repres.should.contain('comp float 12.3 >= float 24.23')
        repres.should.contain('comp float 10.11 <= float 12.43')
Exemplo n.º 29
0
    def test_works_for_greater_and_less(self):
        expr = """
        24123 > 24
        10 < 12
        12.3 > 24.23
        10.11 < 12.43
        """

        repres = get_representation(expr)
        repres.should.contain('comp int 24123 > int 24')
        repres.should.contain('comp int 10 < int 12')

        repres.should.contain('comp float 12.3 > float 24.23')
        repres.should.contain('comp float 10.11 < float 12.43')
Exemplo n.º 30
0
    def test_works_for_booleans_with_else(self):
        expr = """
        if true
            a = 1
        else
            a = 2
        end
        """

        repres = get_representation(expr)
        repres.should.contain('if_ boolean true')
        repres.should.contain('block assign name a int 1 ')
        repres.should.contain('block assign name a int 2')
        '''