Skip to content

Commit 55cfec1

Browse files
authored
Assign count for continued lines in script (#69)
1 parent ab335d2 commit 55cfec1

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

covimerage/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ def map_function(self, f):
463463

464464
# Assign counts from function to script.
465465
for [f_lnum, f_line] in f.lines.items():
466-
s_line = script.lines[script_lnum + f_lnum]
466+
s_lnum = script_lnum + f_lnum
467+
s_line = script.lines[s_lnum]
467468

468469
# XXX: might not be the same, since function lines
469470
# are joined, while script lines might be spread
@@ -472,8 +473,7 @@ def map_function(self, f):
472473
if script_source != f_line.line:
473474
while True:
474475
try:
475-
peek = script.lines[script_lnum +
476-
f_lnum + 1]
476+
peek = script.lines[script_lnum + f_lnum + 1]
477477
except KeyError:
478478
pass
479479
else:
@@ -494,6 +494,14 @@ def map_function(self, f):
494494
s_line.count += f_line.count
495495
else:
496496
s_line.count = f_line.count
497+
498+
# Assign count to continued lines.
499+
i = s_lnum + 1
500+
n = len(script.lines)
501+
while i < n and RE_CONTINUING_LINE.match(script.lines[i].line):
502+
script.lines[i].count = s_line.count
503+
i += 1
504+
497505
if f_line.self_time:
498506
if s_line.self_time:
499507
s_line.self_time += f_line.self_time

tests/fixtures/dict_function_with_continued_lines.profile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ count total (s) self (s)
1010
if a:arg
1111
echom
1212
\ a:arg
13+
\ .'.'
1314
else
1415
echom a:arg
1516
endif
@@ -25,10 +26,10 @@ Total time: 0.000079
2526
Self time: 0.000079
2627

2728
count total (s) self (s)
28-
3 0.000010 if a:arg
29-
2 0.000031 echom a:arg
30-
2 0.000004 else
31-
1 0.000017 echom a:arg
29+
3 0.000008 if a:arg
30+
2 0.000059 echom a:arg .'.'
31+
2 0.000003 else
32+
1 0.000114 echom a:arg
3233
1 0.000002 endif
3334

3435
FUNCTIONS SORTED ON TOTAL TIME

tests/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def test_profile_parse_dict_function_with_continued_lines():
248248
(1, 'function! obj.dict_function(arg) abort'),
249249
(3, ' if a:arg'),
250250
(2, ' echom'),
251-
(N, ' \\ a:arg'),
251+
(2, ' \\ a:arg'),
252+
(2, ' \\ .\'.\''),
252253
(2, ' else'),
253254
(1, ' echom a:arg'),
254255
(1, ' endif'),

tests/test_plugin/dict_function_with_continued_lines.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function! obj.dict_function(arg) abort
44
if a:arg
55
echom
66
\ a:arg
7+
\ .'.'
78
else
89
echom a:arg
910
endif

0 commit comments

Comments
 (0)