lcov_parser/report/
file.rs

1// Copyright (c) 2015-2016 lcov-parser developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9use std::collections::btree_map:: { BTreeMap };
10use merger::ops:: { TryMerge, MergeResult, TestError };
11use report::test:: { Test, Tests };
12use report::summary:: { Summary };
13use report::attribute:: { SourceFile };
14
15#[derive(Debug, Clone)]
16pub struct File {
17    tests: Tests
18}
19
20impl File {
21    pub fn new(tests: Tests) -> Self {
22        File {
23            tests: tests
24        }
25    }
26    pub fn tests(&self) -> &Tests {
27        &self.tests
28    }
29    pub fn get_test(&self, name: &String) -> Option<&Test> {
30        self.tests.get(name)
31    }
32}
33
34impl<'a> TryMerge<&'a File> for File {
35    type Err = TestError;
36
37    fn try_merge(&mut self, file: &'a File) -> MergeResult<Self::Err> {
38        self.tests.try_merge(file.tests())
39    }
40}
41
42
43
44#[derive(Debug, Clone)]
45pub struct Files {
46    files: BTreeMap<SourceFile, File>
47}
48
49impl Files {
50    pub fn new() -> Self {
51        Files {
52            files: BTreeMap::new()
53        }
54    }
55}
56
57impl_summary!(Files, files<SourceFile, File>);
58
59
60impl<'a> TryMerge<(&'a SourceFile, &'a File)> for Files {
61    type Err = TestError;
62
63    fn try_merge(&mut self, source_file: (&'a SourceFile, &'a File)) -> MergeResult<Self::Err> {
64        if !self.files.contains_key(source_file.0) {
65            self.files.insert(source_file.0.clone(), source_file.1.clone());
66            return Ok(());
67        }
68        let file = self.files.get_mut(source_file.0).unwrap();
69        file.try_merge(source_file.1)
70    }
71}
72
73impl_try_merge_self_summary!(Files:files, TestError);