provenant/license_detection/detection/
types.rs1use crate::license_detection::models::LicenseMatch;
4
5pub struct DetectionGroup {
6 pub matches: Vec<LicenseMatch>,
8}
9
10impl DetectionGroup {
11 pub fn new(matches: Vec<LicenseMatch>) -> Self {
12 Self { matches }
13 }
14}
15
16#[derive(Debug, Clone)]
19pub struct LicenseDetection {
20 pub license_expression: Option<String>,
23
24 pub license_expression_spdx: Option<String>,
26
27 pub matches: Vec<LicenseMatch>,
29
30 pub detection_log: Vec<String>,
32
33 pub identifier: Option<String>,
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 fn create_test_match(start_line: usize, end_line: usize) -> LicenseMatch {
43 LicenseMatch {
44 rid: 0,
45 license_expression: "mit".to_string(),
46 license_expression_spdx: Some("MIT".to_string()),
47 from_file: Some("test.txt".to_string()),
48 start_line,
49 end_line,
50 start_token: 0,
51 end_token: 0,
52 matcher: crate::license_detection::models::MatcherKind::Hash,
53 score: 95.0,
54 matched_length: 100,
55 match_coverage: 95.0,
56 rule_relevance: 100,
57 rule_identifier: "mit.LICENSE".to_string(),
58 rule_url: "https://example.com".to_string(),
59 matched_text: Some("MIT License".to_string()),
60 referenced_filenames: None,
61 rule_kind: crate::license_detection::models::RuleKind::None,
62 is_from_license: false,
63 rule_length: 100,
64 matched_token_positions: None,
65 hilen: 50,
66 rule_start_token: 0,
67 qspan_positions: None,
68 ispan_positions: None,
69 hispan_positions: None,
70 candidate_resemblance: 0.0,
71 candidate_containment: 0.0,
72 }
73 }
74
75 #[test]
76 fn test_detection_group_new_empty() {
77 let group = DetectionGroup::new(Vec::new());
78 assert_eq!(group.matches.len(), 0);
79 }
80
81 #[test]
82 fn test_detection_group_new_with_matches() {
83 let match1 = create_test_match(1, 5);
84 let match2 = create_test_match(10, 15);
85 let group = DetectionGroup::new(vec![match1, match2]);
86
87 assert_eq!(group.matches.len(), 2);
88 }
89}