Example #1
0
    def test_assigns_variable_to_variable(self):
        expr = """
        alpha = beta
        """

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

        # noinspection PyUnusedLocal
        repres = get_representation(expr)
Example #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')
Example #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')
Example #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')
Example #6
0
    def test_multi_line(self):
        expr = """1 - 1
        2 * 3
        """

        # noinspection PyUnusedLocal
        repres = get_representation(expr)
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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"')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
Example #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')
        '''