1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(cli/tools/coverage): Split sources by char index (#13114)

This commit is contained in:
Nayeem Rahman 2021-12-17 16:17:35 +00:00 committed by GitHub
parent 5d8baf054e
commit ca1fbdd636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -231,9 +231,12 @@ impl CoverageReporter for LcovCoverageReporter {
continue;
}
let source_line = script_source[0..function.ranges[0].start_offset]
.split('\n')
.count();
let source_line = script_source
.chars()
.take(function.ranges[0].start_offset)
.filter(|c| *c == '\n')
.count()
+ 1;
let line_index = if let Some(source_map) = maybe_source_map.as_ref() {
source_map
@ -277,8 +280,12 @@ impl CoverageReporter for LcovCoverageReporter {
{
let block_hits = function.ranges[0].count;
for (branch_number, range) in function.ranges[1..].iter().enumerate() {
let source_line =
script_source[0..range.start_offset].split('\n').count();
let source_line = script_source
.chars()
.take(range.start_offset)
.filter(|c| *c == '\n')
.count()
+ 1;
let line_index = if let Some(source_map) = maybe_source_map.as_ref() {
source_map