1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
mod configuer_struct;

pub use configuer_struct::Configuer;

#[cfg(test)]
mod tests {
    use super::*;
    use serde::{Deserialize, Serialize};

    #[derive(Serialize, Deserialize, Clone, Default)]
    struct DataModel {
        points: i32,
    }

    #[test]
    #[should_panic(expected = "file created")]
    fn default_value_works() {
        Configuer::with_file("random").on_create(|| {
            panic!("file created");
        });
    }

    #[test]
    fn saving_and_reading_works_between_sessions() {
        {
            let mut config = Configuer::<DataModel>::with_file("my");
            config.data.points = 3;
            config.save();
        }

        let config = Configuer::<DataModel>::with_file("my");

        assert_eq!(config.data.points, 3);
    }
}