def test_parse_at_cursor_no_closing_bracket(): ''' GIVEN function invocation occupies single line AND closing bracket is absent WHEN parsing the buffer range THEN empty parsed range is returned ''' buffer = ['test(', ' a, b,', ' c'] assert buffer_parser.parse_at_cursor((1, 0), buffer) is None
def test_extra_brackets(cursor_row, cursor_col, arrange_parse_args_line): ''' GIVEN function invocation occupies multiple lines AND there are a few extra brackets AND cursor position varies from top left to bottom right WHEN parsing the buffer range THEN the data is extracted correctly AND result does not depend on cursor position ''' buffer = ['test((a) + (b), ', ' (b + c), d,', ' (f)) # comment'] expected_args = ['(a) + (b)', '(b + c)', 'd', '(f)'] with arrange_parse_args_line('(a) + (b), (b + c), d, (f)', expected_args): assert _properties_equal( buffer_parser.parse_at_cursor((cursor_row, cursor_col), buffer), [0, 2, 0, 'test(', expected_args, ') # comment'])
def test_parse_at_cursor_multiple_lines_cursor_positions( cursor_row, cursor_col, arrange_parse_args_line): ''' GIVEN function invocation occupies multiple lines AND some text is present at the end AND cursor position varies from top left to bottom right WHEN parsing the buffer range THEN the data is extracted correctly AND result does not depend on cursor position ''' buffer = ['this_is_test_function(a,', 'b, ', ' c, ', 'd) #test'] expected_args = ['a', 'b', 'c', 'd'] with arrange_parse_args_line('a,b, c, d', expected_args): assert _properties_equal( buffer_parser.parse_at_cursor((cursor_row, cursor_col), buffer), [0, 3, 0, 'this_is_test_function(', expected_args, ') #test'])
def test_parse_at_cursor_single_line_inside_brackets_ending( text_ending, arrange_parse_args_line): ''' GIVEN function invocation occupies single line AND ending text is of varied length AND cursor position is inside brackets WHEN parsing the buffer range THEN the data is extracted correctly ''' buffer = ['this_is_test_function(a, b, c, d)' + text_ending] expected_args = ['a', 'b', 'c', 'd'] with arrange_parse_args_line('a, b, c, d', expected_args): assert _properties_equal( buffer_parser.parse_at_cursor((1, 23), buffer), [ 0, 0, 0, 'this_is_test_function(', expected_args, ')' + text_ending ])
def test_parse_at_cursor_multiple_lines_inside_brackets_beginning( offset, text_beginning, arrange_parse_args_line): ''' GIVEN function invocation occupies multiple lines AND beginning text is of varied length AND offset is of varied length AND cursor position is inside brackets WHEN parsing the buffer range THEN the data is extracted correctly ''' buffer = [offset + text_beginning + '(a,', ' b,', ' c, ', ' d)'] expected_args = ['a', 'b', 'c', 'd'] with arrange_parse_args_line('a, b, c, d', expected_args): assert _properties_equal(buffer_parser.parse_at_cursor( (2, 0), buffer), [ 0, 3, len(offset), offset + text_beginning + '(', expected_args, ')' ])
def test_nested_invocations_with_square_brackets(cursor_row, cursor_col, arrange_parse_args_line): ''' GIVEN function invocation occupies multiple lines AND there are a few nested function invocations AND some function results are accessed by index AND some function resutls are functions that are invoked AND cursor position varies from top left to bottom right WHEN parsing the buffer range THEN the data is extracted correctly AND result does not depend on cursor position ''' buffer = ['test(', ' n_1(a)(a1),', ' n_2(n_3(b))[0],', ' n_4(c))'] expected_args = ['n_1(a)(a1)', 'n_2(n_3(b))[0]', 'n_4(c)'] with arrange_parse_args_line( ' n_1(a)(a1), n_2(n_3(b))[0], n_4(c)', expected_args): assert _properties_equal( buffer_parser.parse_at_cursor((cursor_row, cursor_col), buffer), [0, 3, 0, 'test(', expected_args, ')'])
def wrap_args(self, cursor, buffer): parsed_range = parse_at_cursor(cursor, buffer) if _can_wrap(parsed_range): self._allocate_lines(parsed_range, buffer) self._wrap_args(parsed_range, buffer)
def recognized(self, cursor, buffer): parsed_range = parse_at_cursor(cursor, buffer) return _can_wrap(parsed_range) and self._recognized( parsed_range, buffer)