@@ -14,11 +14,11 @@ pub mod tests {
14
14
fn success ( ) {
15
15
css_inline ( )
16
16
. arg ( "tests/example.html" )
17
- . arg ( "--output-filename-prefix=inlined.keep-style-tags ." )
17
+ . arg ( "--output-filename-prefix=inlined.success ." )
18
18
. assert ( )
19
19
. success ( )
20
20
. stdout ( "tests/example.html: SUCCESS\n " ) ;
21
- let content = fs:: read_to_string ( "tests/inlined.keep-style-tags .example.html" ) . unwrap ( ) ;
21
+ let content = fs:: read_to_string ( "tests/inlined.success .example.html" ) . unwrap ( ) ;
22
22
assert_eq ! (
23
23
content,
24
24
"<html><head>\n \
@@ -38,10 +38,11 @@ pub mod tests {
38
38
css_inline ( )
39
39
. arg ( "tests/example.html" )
40
40
. arg ( "--keep-style-tags" )
41
+ . arg ( "--output-filename-prefix=inlined.keep-style-tags." )
41
42
. assert ( )
42
43
. success ( )
43
44
. stdout ( "tests/example.html: SUCCESS\n " ) ;
44
- let content = fs:: read_to_string ( "tests/inlined.example.html" ) . unwrap ( ) ;
45
+ let content = fs:: read_to_string ( "tests/inlined.keep-style-tags. example.html" ) . unwrap ( ) ;
45
46
assert_eq ! (
46
47
content,
47
48
"<html><head>\n \n \
@@ -55,6 +56,49 @@ pub mod tests {
55
56
)
56
57
}
57
58
59
+ #[ test]
60
+ fn dont_inline_styles ( ) {
61
+ css_inline ( )
62
+ . arg ( "tests/example.html" )
63
+ . arg ( "--inline-style-tags=false" )
64
+ . arg ( "--output-filename-prefix=inlined.dont-inline-styles." )
65
+ . assert ( )
66
+ . success ( )
67
+ . stdout ( "tests/example.html: SUCCESS\n " ) ;
68
+ let content = fs:: read_to_string ( "tests/inlined.dont-inline-styles.example.html" ) . unwrap ( ) ;
69
+ assert_eq ! (
70
+ content,
71
+ "<html><head>\n \n \n \n \
72
+ </head>\n \
73
+ <body>\n \
74
+ <a class=\" test-class\" href=\" https://example.com\" >Test</a>\n \
75
+ <h1>Test</h1>\n \n \n \
76
+ </body></html>"
77
+ )
78
+ }
79
+
80
+ #[ test]
81
+ fn no_remote_stylesheets ( ) {
82
+ css_inline ( )
83
+ . arg ( "tests/example.html" )
84
+ . arg ( "--load-remote-stylesheets=false" )
85
+ . arg ( "--output-filename-prefix=inlined.no-remote-stylesheets." )
86
+ . assert ( )
87
+ . success ( )
88
+ . stdout ( "tests/example.html: SUCCESS\n " ) ;
89
+ let content =
90
+ fs:: read_to_string ( "tests/inlined.no-remote-stylesheets.example.html" ) . unwrap ( ) ;
91
+ assert_eq ! (
92
+ content,
93
+ "<html><head>\n \n \n \n \
94
+ </head>\n \
95
+ <body>\n \
96
+ <a class=\" test-class\" href=\" https://example.com\" style=\" color: #ffffff;\" >Test</a>\n \
97
+ <h1 style=\" text-decoration: none;\" >Test</h1>\n \n \n \
98
+ </body></html>"
99
+ )
100
+ }
101
+
58
102
#[ test]
59
103
#[ cfg( feature = "stylesheet-cache" ) ]
60
104
fn cache_valid ( ) {
@@ -175,11 +219,88 @@ pub mod tests {
175
219
}
176
220
177
221
#[ test_case( "--help" , "css-inline inlines CSS into HTML" ) ]
222
+ #[ test_case( "-h" , "css-inline inlines CSS into HTML" ) ]
178
223
#[ test_case( "--version" , "css-inline" ) ]
224
+ #[ test_case( "-v" , "css-inline" ) ]
179
225
fn args ( arg : & str , expected : & str ) {
180
226
let stdout = css_inline ( ) . arg ( arg) . assert ( ) . success ( ) . to_string ( ) ;
181
227
assert ! ( stdout. contains( expected) , "{}" , stdout) ;
182
228
}
229
+
230
+ #[ test]
231
+ fn flag_requires_value_but_none_provided ( ) {
232
+ css_inline ( )
233
+ . arg ( "--base-url" )
234
+ . assert ( )
235
+ . failure ( )
236
+ . stderr ( "Error parsing arguments: Flag --base-url requires a value\n " ) ;
237
+ }
238
+
239
+ #[ test]
240
+ fn invalid_multi_character_short_flag ( ) {
241
+ css_inline ( )
242
+ . arg ( "-abc" )
243
+ . assert ( )
244
+ . failure ( )
245
+ . stderr ( "Error parsing arguments: Invalid flag: -abc\n " ) ;
246
+ }
247
+
248
+ #[ test]
249
+ fn keep_link_tags_flag ( ) {
250
+ css_inline ( )
251
+ . arg ( "tests/example.html" )
252
+ . arg ( "--keep-link-tags" )
253
+ . arg ( "--output-filename-prefix=inlined.keep-link-tags." )
254
+ . assert ( )
255
+ . success ( )
256
+ . stdout ( "tests/example.html: SUCCESS\n " ) ;
257
+ }
258
+
259
+ #[ test]
260
+ fn unknown_short_flag ( ) {
261
+ css_inline ( )
262
+ . arg ( "-b" )
263
+ . assert ( )
264
+ . failure ( )
265
+ . stderr ( "Unknown flag: b\n " ) ;
266
+ }
267
+
268
+ #[ test]
269
+ fn unknown_boolean_flag ( ) {
270
+ css_inline ( )
271
+ . arg ( "--unknown-flag" )
272
+ . assert ( )
273
+ . failure ( )
274
+ . stderr ( "Unknown flag: unknown-flag\n " ) ;
275
+ }
276
+
277
+ #[ test]
278
+ fn unknown_flag_with_value ( ) {
279
+ css_inline ( )
280
+ . arg ( "--unknown-flag=value" )
281
+ . assert ( )
282
+ . failure ( )
283
+ . stderr ( "Unknown flag: --unknown-flag\n " ) ;
284
+ }
285
+
286
+ #[ test]
287
+ fn invalid_boolean_value_for_flag ( ) {
288
+ css_inline ( )
289
+ . arg ( "--inline-style-tags=invalid" )
290
+ . assert ( )
291
+ . failure ( )
292
+ . stderr ( "Failed to parse value 'invalid' for flag 'inline-style-tags': provided string was not `true` or `false`\n " ) ;
293
+ }
294
+
295
+ #[ test]
296
+ #[ cfg( feature = "stylesheet-cache" ) ]
297
+ fn invalid_numeric_value_for_cache_size ( ) {
298
+ css_inline ( )
299
+ . arg ( "--cache-size=invalid" )
300
+ . assert ( )
301
+ . failure ( )
302
+ . stderr ( "Failed to parse value 'invalid' for flag 'cache-size': invalid digit found in string\n " ) ;
303
+ }
183
304
}
184
305
185
306
#[ cfg( not( feature = "cli" ) ) ]
0 commit comments