]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/theme/tests.rs
Add check for missing CSS variables
[rust.git] / src / librustdoc / theme / tests.rs
1 use super::*;
2
3 #[test]
4 fn test_comments_in_rules() {
5     let text = r#"
6 rule a {}
7
8 rule b, c
9 // a line comment
10 {}
11
12 rule d
13 // another line comment
14 e {}
15
16 rule f/* a multine
17
18 comment*/{}
19
20 rule g/* another multine
21
22 comment*/h
23
24 i {}
25
26 rule j/*commeeeeent
27
28 you like things like "{}" in there? :)
29 */
30 end {}"#;
31
32     let against = r#"
33 rule a {}
34
35 rule b, c {}
36
37 rule d e {}
38
39 rule f {}
40
41 rule gh i {}
42
43 rule j end {}
44 "#;
45
46     let mut ret = Vec::new();
47     get_differences(&load_css_paths(against).unwrap(), &load_css_paths(text).unwrap(), &mut ret);
48     assert!(ret.is_empty());
49 }
50
51 #[test]
52 fn test_text() {
53     let text = r#"
54 a
55 /* sdfs
56 */ b
57 c // sdf
58 d {}
59 "#;
60     let paths = load_css_paths(text).unwrap();
61     assert!(paths.contains_key(&"a b c d".to_owned()));
62 }
63
64 #[test]
65 fn test_comparison() {
66     let origin = r#"
67 @a {
68     b {}
69     c {}
70 }
71 "#;
72
73     let against = r#"
74 @a {
75     b {}
76 }
77 "#;
78
79     let origin = load_css_paths(origin).unwrap();
80     let against = load_css_paths(against).unwrap();
81
82     let mut ret = Vec::new();
83     get_differences(&against, &origin, &mut ret);
84     assert!(ret.is_empty());
85     get_differences(&origin, &against, &mut ret);
86     assert_eq!(ret, vec!["  Missing rule `c`".to_owned()]);
87 }
88
89 #[test]
90 fn check_empty_css() {
91     let paths = load_css_paths("").unwrap();
92     assert_eq!(paths.len(), 0);
93 }
94
95 #[test]
96 fn check_invalid_css() {
97     let paths = load_css_paths("*").unwrap();
98     assert_eq!(paths.len(), 0);
99 }
100
101 #[test]
102 fn test_with_minification() {
103     let text = include_str!("../html/static/css/themes/dark.css");
104     let minified = minifier::css::minify(&text).expect("CSS minification failed").to_string();
105
106     let against = load_css_paths(text).unwrap();
107     let other = load_css_paths(&minified).unwrap();
108
109     let mut ret = Vec::new();
110     get_differences(&against, &other, &mut ret);
111     assert!(ret.is_empty());
112 }
113
114 #[test]
115 fn test_media() {
116     let text = r#"
117 @media (min-width: 701px) {
118     a:hover {
119         color: #fff;
120     }
121
122     b {
123         x: y;
124     }
125 }
126
127 @media (max-width: 1001px) {
128     b {
129         x: y;
130     }
131 }
132 "#;
133
134     let paths = load_css_paths(text).unwrap();
135     let p = paths.get("@media (min-width:701px)");
136     assert!(p.is_some());
137     let p = p.unwrap();
138     assert!(p.children.get("a:hover").is_some());
139     assert!(p.children.get("b").is_some());
140
141     eprintln!("{:?}", paths);
142     let p = paths.get("@media (max-width:1001px)");
143     assert!(p.is_some());
144     let p = p.unwrap();
145     assert!(p.children.get("b").is_some());
146 }
147
148 #[test]
149 fn test_css_variables() {
150     let x = r#"
151 :root {
152     --a: #fff;
153 }
154 "#;
155
156     let y = r#"
157 :root {
158     --a: #fff;
159     --b: #fff;
160 }
161 "#;
162
163     let against = load_css_paths(x).unwrap();
164     let other = load_css_paths(y).unwrap();
165
166     let mut ret = Vec::new();
167     get_differences(&against, &other, &mut ret);
168     assert!(ret.is_empty());
169     get_differences(&other, &against, &mut ret);
170     assert_eq!(ret, vec!["  Missing CSS variable `--b` in `:root`".to_owned()]);
171 }