Skip to main content

frs/cmds/rsl/output/format/
relative_path.rs

1use super::super::ViolationOutputFormat;
2use super::FormattedRuleViolation;
3use super::format_violation;
4use crate::cmds::rsl::rules::TypedRule;
5use crate::cmds::rsl::rules::relative_path::RelativePathRule;
6use crate::cmds::rsl::rules::relative_path::RelativePathViolation;
7
8impl FormattedRuleViolation for RelativePathViolation {
9    fn format(&self, output_format: ViolationOutputFormat) -> String {
10        format_violation(
11            &self.location,
12            <RelativePathRule as TypedRule>::code(),
13            "use a crate-absolute path",
14            output_format,
15        )
16    }
17}
18
19#[cfg(test)]
20mod tests {
21    use std::path::PathBuf;
22
23    use super::super::super::ViolationOutputFormat;
24    use super::super::FormattedRuleViolation;
25    use crate::cmds::rsl::rules::common::Location;
26    use crate::cmds::rsl::rules::relative_path::RelativePathViolation;
27
28    #[test]
29    fn test_relative_path_violation_when_details_are_present_formats_compact_output() {
30        let violation = RelativePathViolation {
31            location: Location::new(PathBuf::from("test.rs"), 3, 13),
32        };
33
34        assert_eq!(
35            FormattedRuleViolation::format(&violation, ViolationOutputFormat::Compact),
36            "test.rs:3:13,use a crate-absolute path"
37        );
38    }
39
40    #[test]
41    fn test_formatted_rule_violation_when_debug_format_is_selected_includes_code() {
42        let violation = RelativePathViolation {
43            location: Location::new(PathBuf::from("test.rs"), 3, 13),
44        };
45
46        assert_eq!(
47            FormattedRuleViolation::format(&violation, ViolationOutputFormat::Debug),
48            "test.rs:3:13,relative_path,use a crate-absolute path"
49        );
50    }
51}