-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:8013bd0f
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use crate::input::StatementsMap; | ||
use crate::input::{InputData, LineRange}; | ||
use crate::types::{FileLocation, FunctionName, HitCount, LineNumber}; | ||
use std::collections::HashMap; | ||
|
||
pub type FilesCoverageData = HashMap<FileLocation, FileCoverageData>; | ||
|
||
impl From<&InputData> for FilesCoverageData { | ||
fn from(input_data: &InputData) -> Self { | ||
input_data | ||
.statements_map | ||
.iter() | ||
.filter(|(id, _)| input_data.executed_sierra_ids.contains(id)) | ||
.fold( | ||
create_files_coverage_data(&input_data.statements_map), | ||
|mut files_coverage_data, (_, statement_origin)| { | ||
if let Some(function_details) = files_coverage_data | ||
.get_mut(&statement_origin.file_location) | ||
.and_then(|functions| functions.get_mut(&statement_origin.function_name)) | ||
{ | ||
function_details.register_hit(&statement_origin.line_range); | ||
} | ||
files_coverage_data | ||
}, | ||
) | ||
} | ||
} | ||
|
||
fn create_files_coverage_data(statements_map: &StatementsMap) -> FilesCoverageData { | ||
statements_map | ||
.values() | ||
.cloned() | ||
.fold(HashMap::new(), |mut acc, origin| { | ||
acc.entry(origin.file_location) | ||
.or_default() | ||
.entry(origin.function_name) | ||
.and_modify(|function_details: &mut FunctionCoverageData| { | ||
function_details.register_line(&origin.line_range); | ||
}) | ||
.or_insert(origin.line_range.into()); | ||
acc | ||
}) | ||
} | ||
|
||
pub type FileCoverageData = HashMap<FunctionName, FunctionCoverageData>; | ||
|
||
pub type FunctionCoverageData = HashMap<LineNumber, HitCount>; | ||
|
||
impl From<LineRange> for FunctionCoverageData { | ||
fn from(line_range: LineRange) -> Self { | ||
let mut function_coverage_data = FunctionCoverageData::new(); | ||
function_coverage_data.register_line(&line_range); | ||
function_coverage_data | ||
} | ||
} | ||
|
||
trait Register { | ||
fn register_line<T: IntoIterator<Item = LineNumber>>(&mut self, lines: T); | ||
fn register_hit<T: IntoIterator<Item = LineNumber>>(&mut self, lines: T); | ||
} | ||
|
||
impl Register for FunctionCoverageData { | ||
fn register_line<T: IntoIterator<Item = LineNumber>>(&mut self, lines: T) { | ||
for line in lines { | ||
self.entry(line).or_default(); | ||
} | ||
} | ||
|
||
fn register_hit<T: IntoIterator<Item = LineNumber>>(&mut self, lines: T) { | ||
for line in lines { | ||
*self.entry(line).or_default() += 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod function; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod cli; | ||
mod coverage_data; | ||
mod input; | ||
mod types; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub type FileLocation = String; | ||
pub type FunctionName = String; | ||
pub type LineNumber = usize; | ||
pub type HitCount = usize; |