Skip to main content

meta_language/link_network/
verification.rs

1//! Full-match verification of a [`LinkNetwork`] region.
2
3use super::{Link, LinkNetwork};
4use crate::source::ByteRange;
5use crate::verification::{VerificationIssue, VerificationIssueKind, VerificationReport};
6
7impl LinkNetwork {
8    /// Verifies that the selected region has no error or missing links.
9    #[must_use]
10    pub fn verify_full_match(&self, region: Option<ByteRange>) -> VerificationReport {
11        let issues = self
12            .links()
13            .filter(|link| link_is_in_region(link, region))
14            .filter_map(|link| {
15                let flags = link.metadata().flags();
16                let kind = if flags.is_error() {
17                    VerificationIssueKind::ErrorLink
18                } else if flags.is_missing() {
19                    VerificationIssueKind::MissingLink
20                } else if flags.has_error() {
21                    VerificationIssueKind::HasErrorLink
22                } else {
23                    return None;
24                };
25
26                Some(VerificationIssue::new(
27                    link.id(),
28                    kind,
29                    link.metadata().span(),
30                ))
31            })
32            .collect();
33        VerificationReport::new(issues)
34    }
35}
36
37fn link_is_in_region(link: &Link, region: Option<ByteRange>) -> bool {
38    let Some(region) = region else {
39        return true;
40    };
41    link.metadata()
42        .span()
43        .is_some_and(|span| span.byte_range().intersects(region))
44}