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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
mod attr_class;
mod class;
mod el_class;
mod str_class;

pub use crate::attr_class::AttrClass;
pub use crate::class::Class;
pub use crate::el_class::ElClass;
pub use crate::str_class::StrClass;

//
// Internally this crate works by structuring nodes in reverse order.
//
// i.e. The following code ...
//
//   Node::new("home_page").append("content").append("button")
//
// Would produce a structure like this ...
//
//  {
//      base_class: "button",
//      parent: {
//          base_class: "content",
//          parent: {
//              base_class: "home_page",
//              parent: None,
//          }
//      }
//  }
//

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_should_print_base_class() {
        let class = Class::new("home_page");
        assert_eq!(class.to_string(), "home_page");
    }

    #[test]
    fn it_should_print_base_class_children() {
        let class = Class::new("home_page").el("content");
        assert_eq!(class.to_string(), "home_page__content");
    }

    #[test]
    fn it_should_append_classes() {
        let class = Class::new("page") + "home_page";
        assert_eq!(class.to_string(), "page home_page");
    }

    #[test]
    fn it_should_append_multiple_classes() {
        let class = Class::new("page") + "home_page" + "noscript";
        assert_eq!(class.to_string(), "page home_page noscript");
    }

    #[test]
    fn it_should_print_base_class_with_attributes() {
        let class = Class::new("home_page").attr("wide");
        assert_eq!(class.to_string(), "home_page home_page--wide");
    }

    #[test]
    fn it_should_print_base_class_with_multiple_attributes() {
        let class = Class::new("home_page").attr("wide").attr("bold");
        assert_eq!(
            class.to_string(),
            "home_page home_page--wide home_page--bold"
        );
    }

    #[test]
    fn it_should_print_base_class_children_with_attributes() {
        let class = Class::new("home_page").el("content").attr("large");
        assert_eq!(
            class.to_string(),
            "home_page__content home_page__content--large"
        );
    }

    #[test]
    fn it_should_print_base_class_children_with_attributes_with_additions() {
        let class = Class::new("home_page").el("content").attr("large") + "noscript";
        assert_eq!(
            class.to_string(),
            "home_page__content home_page__content--large noscript"
        );
    }
}