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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use heck::{CamelCase, SnakeCase};
use proc_macro2::Ident;
use quote::format_ident;

#[derive(Clone, Debug)]
pub struct ConjunctRelation {
    pub(crate) via: String,
    pub(crate) to: String,
}

impl ConjunctRelation {
    pub fn get_via_snake_case(&self) -> Ident {
        format_ident!("{}", self.via.to_snake_case())
    }

    pub fn get_to_snake_case(&self) -> Ident {
        format_ident!("{}", self.to.to_snake_case())
    }

    pub fn get_to_camel_case(&self) -> Ident {
        format_ident!("{}", self.to.to_camel_case())
    }
}

#[cfg(test)]
mod tests {
    use crate::ConjunctRelation;

    fn setup() -> Vec<ConjunctRelation> {
        vec![
            ConjunctRelation {
                via: "cake_filling".to_owned(),
                to: "cake".to_owned(),
            },
            ConjunctRelation {
                via: "cake_filling".to_owned(),
                to: "filling".to_owned(),
            },
        ]
    }

    #[test]
    fn test_get_via_snake_case() {
        let conjunct_relations = setup();
        let via_vec = vec!["cake_filling", "cake_filling"];
        for (con_rel, via) in conjunct_relations.into_iter().zip(via_vec) {
            assert_eq!(con_rel.get_via_snake_case(), via);
        }
    }

    #[test]
    fn test_get_to_snake_case() {
        let conjunct_relations = setup();
        let to_vec = vec!["cake", "filling"];
        for (con_rel, to) in conjunct_relations.into_iter().zip(to_vec) {
            assert_eq!(con_rel.get_to_snake_case(), to);
        }
    }

    #[test]
    fn test_get_to_camel_case() {
        let conjunct_relations = setup();
        let to_vec = vec!["Cake", "Filling"];
        for (con_rel, to) in conjunct_relations.into_iter().zip(to_vec) {
            assert_eq!(con_rel.get_to_camel_case(), to);
        }
    }
}