Skip to content

Commit efa2c54

Browse files
author
Nathan Hawes
committed
[incrParse] Update text-util.py to handle multiple edits and reparse ranges on the same line
It wasn't accounting for the prefix length before a reparse tag previously when keeping track of pre_column_offset and post_column_offset.
1 parent 0152e23 commit efa2c54

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %validate-incrparse %s --test-case MULTI
3+
4+
let one: Int;<reparse MULTI>let two: Int; let three: Int; <<MULTI<||| >>><<MULTI<||| >>>let found: Int;</reparse MULTI>let five: Int;

utils/incrparse/test_util.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def run_command(cmd):
2727

2828
def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
2929
current_reparse_start):
30-
pre_column_offset = 1
31-
post_column_offset = 1
3230
pre_edit_line = ""
3331
post_edit_line = ""
3432

@@ -55,31 +53,29 @@ def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
5553
suffix = subst_match.group(5)
5654

5755
if match_test_case == test_case:
58-
pre_edit_line += prefix + pre_edit
59-
post_edit_line += prefix + post_edit
60-
6156
# Compute the -incremental-edit argument for swift-syntax-test
62-
column = pre_column_offset + len(prefix)
57+
column = len(pre_edit_line) + len(prefix) + 1
6358
edit_arg = '%d:%d-%d:%d=%s' % \
6459
(line_no, column, line_no, column + len(pre_edit),
6560
post_edit)
6661
incremental_edit_args.append('-incremental-edit')
6762
incremental_edit_args.append(edit_arg)
63+
64+
pre_edit_line += prefix + pre_edit
65+
post_edit_line += prefix + post_edit
6866
else:
6967
# For different test cases just take the pre-edit text
7068
pre_edit_line += prefix + pre_edit
7169
post_edit_line += prefix + pre_edit
7270

7371
line = suffix
74-
pre_column_offset += len(pre_edit_line)
75-
post_column_offset += len(post_edit_line)
7672
elif reparse_match:
7773
prefix = reparse_match.group(1)
7874
is_closing = len(reparse_match.group(2)) > 0
7975
match_test_case = reparse_match.group(3)
8076
suffix = reparse_match.group(4)
8177
if match_test_case == test_case:
82-
column = post_column_offset + len(prefix)
78+
column = len(post_edit_line) + len(prefix) + 1
8379
if is_closing:
8480
if not current_reparse_start:
8581
raise TestFailedError('Closing unopened reparse tag '

0 commit comments

Comments
 (0)