hex_patch/app/
mockup.rs

1#[cfg(test)]
2pub mod test {
3    use std::io::Write;
4
5    use ratatui::{backend::TestBackend, Terminal};
6
7    use crate::app::{settings::verbosity::Verbosity, App};
8
9    impl App {
10        /// Create a mockup of the app with the given data.
11        /// Sets the logger verbosity to debug.
12        pub fn mockup(data: Vec<u8>) -> Self {
13            let mut app = App::default();
14            let mut input_file =
15                tempfile::NamedTempFile::new().expect("Failed to create tempfile for mockup.");
16            input_file
17                .write_all(&data)
18                .expect("Failed to write data to tempfile for mockup.");
19            let mut terminal = Terminal::new(TestBackend::new(80, 25)).unwrap();
20            app.open_file(&input_file.path().to_string_lossy(), &mut terminal)
21                .expect("Failed to open file for mockup.");
22            app.logger.change_verbosity(Verbosity::Debug);
23            app
24        }
25    }
26
27    #[test]
28    fn test_mockup() {
29        let data = b"Hello, World!";
30        let app = App::mockup(data.to_vec());
31        assert_eq!(app.data.bytes(), data);
32    }
33}