]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/theme/tests.rs
54226c6cf3b155bcad28190d436bcbf7036f43d2
[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 x = r#"
67 @a {
68     b {}
69 }
70 "#;
71
72     let y = r#"
73 @a {
74     b {}
75     c {}
76 }
77 "#;
78
79     let against = load_css_paths(y).unwrap();
80     let other = load_css_paths(x).unwrap();
81
82     let mut ret = Vec::new();
83     get_differences(&against, &other, &mut ret);
84     assert!(ret.is_empty());
85     get_differences(&other, &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
128     let paths = load_css_paths(text).unwrap();
129     eprintln!("{:?}", paths);
130     let p = paths.get("@media (min-width:701px)");
131     assert!(p.is_some());
132     let p = p.unwrap();
133     assert!(p.children.get("a:hover").is_some());
134     assert!(p.children.get("b").is_some());
135 }