friendly_errors/
doc_url.rs

1use crate::FriendlyError;
2
3impl FriendlyError {
4    pub fn print_doc_url(&mut self) {
5        if let Some(url) = &self.data.doc_url {
6            let url = url.clone();
7            self.add_empty_line();
8            self.output.push_str("To learn more, read the docs at ");
9            self.output.push_str(&url);
10        }
11    }
12}
13
14#[cfg(test)]
15mod test {
16    use super::*;
17    use indoc::indoc;
18
19    #[test]
20    fn test_append_doc_url() {
21        let mut error = FriendlyError::new().doc_url("https://example.com/");
22        error.print_doc_url();
23        assert_eq!(
24            error.output,
25            "To learn more, read the docs at https://example.com/"
26        );
27    }
28
29    #[test]
30    fn test_append_doc_url_with_output() {
31        let mut error = FriendlyError::new()
32            .doc_url("https://example.com/")
33            .set_output("Error message");
34        error.print_doc_url();
35        assert_eq!(
36            error.output,
37            indoc!(
38                "
39                Error message
40
41                To learn more, read the docs at https://example.com/"
42            )
43        );
44    }
45}