@@ -44,11 +44,7 @@ rule j end {}
4444"# ;
4545
4646 let mut ret = Vec :: new ( ) ;
47- get_differences (
48- & load_css_paths ( against. as_bytes ( ) ) ,
49- & load_css_paths ( text. as_bytes ( ) ) ,
50- & mut ret,
51- ) ;
47+ get_differences ( & load_css_paths ( against) . unwrap ( ) , & load_css_paths ( text) . unwrap ( ) , & mut ret) ;
5248 assert ! ( ret. is_empty( ) ) ;
5349}
5450
6157c // sdf
6258d {}
6359"# ;
64- let paths = load_css_paths ( text. as_bytes ( ) ) ;
65- assert ! ( paths. children . contains ( & CssPath :: new ( "a b c d" . to_owned( ) ) ) ) ;
60+ let paths = load_css_paths ( text) . unwrap ( ) ;
61+ assert ! ( paths. contains_key ( & "a b c d" . to_owned( ) ) ) ;
6662}
6763
6864#[ test]
6965fn test_comparison ( ) {
7066 let x = r#"
71- a {
72- b {
73- c {}
74- }
67+ @a {
68+ b {}
7569}
7670"# ;
7771
7872 let y = r#"
79- a {
73+ @ a {
8074 b {}
75+ c {}
8176}
8277"# ;
8378
84- let against = load_css_paths ( y. as_bytes ( ) ) ;
85- let other = load_css_paths ( x. as_bytes ( ) ) ;
79+ let against = load_css_paths ( y) . unwrap ( ) ;
80+ let other = load_css_paths ( x) . unwrap ( ) ;
8681
8782 let mut ret = Vec :: new ( ) ;
8883 get_differences ( & against, & other, & mut ret) ;
8984 assert ! ( ret. is_empty( ) ) ;
9085 get_differences ( & other, & against, & mut ret) ;
91- assert_eq ! ( ret, vec![ " Missing \" c \" rule" . to_owned( ) ] ) ;
86+ assert_eq ! ( ret, vec![ " Missing rule `c` " . to_owned( ) ] ) ;
9287}
9388
9489#[ test]
9590fn check_empty_css ( ) {
96- let events = load_css_events ( & [ ] ) ;
97- assert_eq ! ( events . len( ) , 0 ) ;
91+ let paths = load_css_paths ( "" ) . unwrap ( ) ;
92+ assert_eq ! ( paths . len( ) , 0 ) ;
9893}
9994
10095#[ test]
10196fn check_invalid_css ( ) {
102- let events = load_css_events ( b "*") ;
103- assert_eq ! ( events . len( ) , 0 ) ;
97+ let paths = load_css_paths ( "*" ) . unwrap ( ) ;
98+ assert_eq ! ( paths . len( ) , 0 ) ;
10499}
105100
106101#[ test]
107102fn test_with_minification ( ) {
108103 let text = include_str ! ( "../html/static/css/themes/dark.css" ) ;
109104 let minified = minifier:: css:: minify ( & text) . expect ( "CSS minification failed" ) . to_string ( ) ;
110105
111- let against = load_css_paths ( text. as_bytes ( ) ) ;
112- let other = load_css_paths ( minified. as_bytes ( ) ) ;
106+ let against = load_css_paths ( text) . unwrap ( ) ;
107+ let other = load_css_paths ( & minified) . unwrap ( ) ;
113108
114109 let mut ret = Vec :: new ( ) ;
115110 get_differences ( & against, & other, & mut ret) ;
116111 assert ! ( ret. is_empty( ) ) ;
117112}
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+ }
0 commit comments