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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
mod class;
pub mod classes;
pub use crate::class::classname;
pub use crate::class::Class;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_should_print_base_class() {
let class = classname("home_page");
assert_eq!(class.to_string(), "home_page");
}
#[test]
fn it_should_print_base_class_children() {
let class = classname("home_page").el("content");
assert_eq!(class.to_string(), "home_page__content");
}
#[test]
fn it_should_append_classes() {
let class = classname("page") + "home_page";
assert_eq!(class.to_string(), "page home_page");
}
#[test]
fn it_should_append_different_classes() {
let class = (classname("page") + classname("home_page").attr("large")) + classname("noscript").el("pane");
assert_eq!(class.to_string(), "page home_page home_page--large noscript__pane");
}
#[test]
fn it_should_append_multiple_classes() {
let class = classname("page") + "home_page" + "noscript";
assert_eq!(class.to_string(), "page home_page noscript");
}
#[test]
fn it_should_print_base_class_with_attributes() {
let class = classname("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 = classname("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 = classname("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 = classname("home_page").el("content").attr("large") + "noscript";
assert_eq!(
class.to_string(),
"home_page__content home_page__content--large noscript"
);
}
#[test]
fn it_should_not_print_added_optional_classes_when_none() {
let base : Option<classes::BaseClass> = None;
let class = classname("page") + "home_page" + base + "noscript";
assert_eq!(class.to_string(), "page home_page noscript");
}
#[test]
fn it_should_print_added_optional_classes_when_some() {
let base = Some(classname("mobile"));
let class = classname("page") + "home_page" + base + "noscript";
assert_eq!(class.to_string(), "page home_page mobile noscript");
}
}