Beispiel #1
0
 def test_pipeline_declaration(self):
     assert parse('pipeline(bar): {foo()}') == [
         Symbol.PIPELINE, [Symbol('bar')], [Symbol('foo')]
     ]
     assert parse('pipeline(bar, fuzz): {foo()}') == [
         Symbol.PIPELINE, [Symbol('bar'), Symbol('fuzz')], [Symbol('foo')]
     ]
Beispiel #2
0
 def test_assignment_function(self):
     assert parse('bar = foo(1)') == [
         Symbol.ASSIGNMENT,
         Symbol('bar'), [Symbol('foo'), 1]
     ]
     assert parse('bar = foo(1, 2)') == [
         Symbol.ASSIGNMENT,
         Symbol('bar'), [Symbol('foo'), 1, 2]
     ]
Beispiel #3
0
 def test_assignment_expr(self):
     assert parse('bar = 1 + 2') == [
         Symbol.ASSIGNMENT,
         Symbol('bar'), [Symbol('+'), 1, 2]
     ]
     assert parse('bar = 1 * 2') == [
         Symbol.ASSIGNMENT,
         Symbol('bar'), [Symbol('*'), 1, 2]
     ]
     assert parse('bar = (1 + 2) * 5') == [
         Symbol.ASSIGNMENT,
         Symbol('bar'), [Symbol('*'), [Symbol('+'), 1, 2], 5]
     ]
Beispiel #4
0
 def test_multiple_stmts_on_pipeline(self):
     parsed = parse('pipeline(bar): {foo(.bar) fuzz(.bar)}')
     assert parsed == [
         Symbol.PIPELINE, [Symbol('bar')],
         [Symbol('foo'), [Symbol.COLUMN, 'bar']],
         [Symbol('fuzz'), [Symbol.COLUMN, 'bar']]
     ]
Beispiel #5
0
 def test_function_call_mixed_arguments(self):
     assert parse('foo(1, 1+2, x, .col, fuzz.buzz, p())') == [
         Symbol('foo'), 1, [Symbol('+'), 1, 2],
         Symbol('x'), [Symbol.COLUMN, 'col'],
         [Symbol.ATTR, Symbol('fuzz'),
          Symbol('buzz')], [Symbol('p')]
     ]
Beispiel #6
0
 def test_sum_using_attr_call(self):
     assert parse('foo.bar + fuzz.buzz') == [
         Symbol('+'), [Symbol.ATTR,
                       Symbol('foo'),
                       Symbol('bar')],
         [Symbol.ATTR, Symbol('fuzz'),
          Symbol('buzz')]
     ]
Beispiel #7
0
 def test_token_string(self):
     assert parse('"hello"') == "hello"
     assert parse('"hello world"') == "hello world"
Beispiel #8
0
 def test_function_call_sugar_column_as_argument(self):
     assert parse('foo(.col)') == [Symbol('foo'), [Symbol.COLUMN, 'col']]
Beispiel #9
0
 def test_function_call_passing_string_as_argument(self):
     assert parse('foo("bar")') == [Symbol('foo'), 'bar']
Beispiel #10
0
 def test_basic_function_call(self):
     assert parse('foo()') == [Symbol('foo')]
Beispiel #11
0
 def test_precedence_using_functions(self):
     assert parse('(foo() + bar()) * 2') == [
         Symbol('*'), [Symbol('+'), [Symbol('foo')], [Symbol('bar')]], 2
     ]
Beispiel #12
0
 def test_expression_with_variables(self):
     assert parse('foo + bar + 2') == [
         Symbol('+'), [Symbol('+'),
                       Symbol('foo'),
                       Symbol('bar')], 2
     ]
Beispiel #13
0
    def test_invalid_sugar_column_call(self):
        assert parse('.1') != [Symbol.COLUMN, 1]

        with pytest.raises(UnexpectedToken):
            parse('.()')
Beispiel #14
0
 def test_escaped_token_string(self):
     assert parse(r'"hello \"world\""') == 'hello "world"'
     assert parse(r'"hello \n world"') == "hello \n world"
     assert parse(r'"hello \t world"') == "hello \t world"
Beispiel #15
0
 def test_sugar_column_call(self):
     assert parse('.col') == [Symbol.COLUMN, 'col']
     assert parse('."col"') == [Symbol.COLUMN, 'col']
Beispiel #16
0
 def test_expression_with_parentheses(self):
     assert parse('(2 + 4)') == [Symbol('+'), 2, 4]
Beispiel #17
0
 def test_precedence_using_parentheses(self):
     assert parse('(2 + 5) * 3') == [Symbol('*'), [Symbol('+'), 2, 5], 3]
Beispiel #18
0
 def test_variable_call(self):
     assert parse('bar') == Symbol('bar')
Beispiel #19
0
 def test_sum_using_functions(self):
     assert parse('foo() + bar() + 1') == [
         Symbol('+'), [Symbol('+'), [Symbol('foo')], [Symbol('bar')]], 1
     ]
Beispiel #20
0
 def test_attribute_call(self):
     assert parse('bar.foo') == [Symbol.ATTR, Symbol('bar'), Symbol('foo')]
Beispiel #21
0
 def test_sum_using_strings(self):
     assert parse('"hello" + "world"') == [Symbol('+'), 'hello', 'world']
Beispiel #22
0
 def test_sum(self):
     assert parse('1 + 2') == [Symbol("+"), 1, 2]
Beispiel #23
0
 def test_token_number(self):
     assert parse('7') == 7
     assert parse('8.1') == 8.1
Beispiel #24
0
 def test_subtraction(self):
     assert parse('1 - 2') == [Symbol('-'), 1, 2]
Beispiel #25
0
 def test_function_call_exp_as_argument(self):
     assert parse('foo(1+2, 8*5)') == [
         Symbol('foo'), [Symbol('+'), 1, 2], [Symbol('*'), 8, 5]
     ]
Beispiel #26
0
 def test_multiplication(self):
     assert parse('1 * 2') == [Symbol('*'), 1, 2]
Beispiel #27
0
 def test_function_call_variable_as_argument(self):
     assert parse('foo(bar)') == [Symbol('foo'), Symbol('bar')]
Beispiel #28
0
 def test_division(self):
     assert parse('1 / 2') == [Symbol('/'), 1, 2]
Beispiel #29
0
 def test_funcion_call_attr_call_as_argument(self):
     assert parse('foo(bar.fuzz)') == [
         Symbol('foo'), [Symbol.ATTR,
                         Symbol('bar'),
                         Symbol('fuzz')]
     ]
Beispiel #30
0
 def test_precedence_of_mult_expr(self):
     assert parse('2 * 5 + 2') == [Symbol('+'), [Symbol('*'), 2, 5], 2]
     assert parse('2 / 5 + 2') == [Symbol('+'), [Symbol('/'), 2, 5], 2]