Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66cea11

Browse files
committed
improve format of tests' code
1 parent2b42c64 commit66cea11

File tree

8 files changed

+175
-141
lines changed

8 files changed

+175
-141
lines changed

‎tests/cli/base_url.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ mod passing {
2828
// STDOUT should contain newly added base URL
2929
assert_eq!(
3030
String::from_utf8_lossy(&out.stdout),
31-
"<html><head>\
32-
<base href=\"http://localhost:8000/\"></base>\
33-
</head><body>Hello, World!</body></html>\n"
31+
r#"<html><head><base href="http://localhost:8000/"></base></head><body>Hello, World!</body></html>
32+
"#
3433
);
3534

3635
// Exit code should be 0
@@ -42,7 +41,7 @@ mod passing {
4241
letmut cmd =Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
4342
let out = cmd
4443
.arg("-M")
45-
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
44+
.arg(r#"data:text/html,<base href="http://localhost:8000/" />Hello%2C%20World!"#)
4645
.output()
4746
.unwrap();
4847

@@ -52,9 +51,8 @@ mod passing {
5251
// STDOUT should contain newly added base URL
5352
assert_eq!(
5453
String::from_utf8_lossy(&out.stdout),
55-
"<html><head>\
56-
<base href=\"http://localhost:8000/\">\
57-
</head><body>Hello, World!</body></html>\n"
54+
r#"<html><head><base href="http://localhost:8000/"></head><body>Hello, World!</body></html>
55+
"#
5856
);
5957

6058
// Exit code should be 0
@@ -68,7 +66,7 @@ mod passing {
6866
.arg("-M")
6967
.arg("-b")
7068
.arg("http://localhost/")
71-
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
69+
.arg(r#"data:text/html,<base href="http://localhost:8000/" />Hello%2C%20World!"#)
7270
.output()
7371
.unwrap();
7472

@@ -78,9 +76,8 @@ mod passing {
7876
// STDOUT should contain newly added base URL
7977
assert_eq!(
8078
String::from_utf8_lossy(&out.stdout),
81-
"<html><head>\
82-
<base href=\"http://localhost/\">\
83-
</head><body>Hello, World!</body></html>\n"
79+
r#"<html><head><base href="http://localhost/"></head><body>Hello, World!</body></html>
80+
"#
8481
);
8582

8683
// Exit code should be 0
@@ -94,7 +91,7 @@ mod passing {
9491
.arg("-M")
9592
.arg("-b")
9693
.arg("")
97-
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
94+
.arg(r#"data:text/html,<base href="http://localhost:8000/" />Hello%2C%20World!"#)
9895
.output()
9996
.unwrap();
10097

@@ -104,9 +101,8 @@ mod passing {
104101
// STDOUT should contain newly added base URL
105102
assert_eq!(
106103
String::from_utf8_lossy(&out.stdout),
107-
"<html><head>\
108-
<base href=\"\">\
109-
</head><body>Hello, World!</body></html>\n"
104+
r#"<html><head><base href=""></head><body>Hello, World!</body></html>
105+
"#
110106
);
111107

112108
// Exit code should be 0

‎tests/cli/basic.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ mod passing {
6767
// STDOUT should contain HTML created out of STDIN
6868
assert_eq!(
6969
String::from_utf8_lossy(&out.stdout),
70-
"<html><head></head><body>Hello from STDIN\n</body></html>\n"
70+
r#"<html><head></head><body>Hello from STDIN
71+
</body></html>
72+
"#
7173
);
7274

7375
// Exit code should be 0
@@ -103,7 +105,19 @@ mod passing {
103105
// STDOUT should contain embedded CSS url()'s
104106
assert_eq!(
105107
String::from_utf8_lossy(&out.stdout),
106-
"<html><head><style>\n\n @charset\"UTF-8\";\n\n @import\"data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K\";\n\n @import url(\"data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K\");\n\n @import url(\"data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K\");\n\n</style>\n</head><body></body></html>\n"
108+
r##"<html><head><style>
109+
110+
@charset "UTF-8";
111+
112+
@import "data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K";
113+
114+
@import url("data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K");
115+
116+
@import url("data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K");
117+
118+
</style>
119+
</head><body></body></html>
120+
"##
107121
);
108122

109123
// Exit code should be 0

‎tests/cli/data_url.rs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ mod passing {
2929
// STDOUT should contain isolated HTML
3030
assert_eq!(
3131
String::from_utf8_lossy(&out.stdout),
32-
"<html><head>\
33-
<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'unsafe-eval' 'unsafe-inline' data:;\"></meta>\
34-
</head><body>Hello, World!</body></html>\n"
32+
r#"<html><head><meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-eval' 'unsafe-inline' data:;"></meta></head><body>Hello, World!</body></html>
33+
"#
3534
);
3635

3736
// Exit code should be 0
@@ -54,10 +53,8 @@ mod passing {
5453
// STDOUT should contain HTML with no CSS
5554
assert_eq!(
5655
String::from_utf8_lossy(&out.stdout),
57-
"<html><head>\
58-
<meta http-equiv=\"Content-Security-Policy\" content=\"style-src 'none';\"></meta>\
59-
<style></style>\
60-
</head><body>Hello</body></html>\n"
56+
r#"<html><head><meta http-equiv="Content-Security-Policy" content="style-src 'none';"></meta><style></style></head><body>Hello</body></html>
57+
"#
6158
);
6259

6360
// Exit code should be 0
@@ -80,10 +77,8 @@ mod passing {
8077
// STDOUT should contain HTML with no web fonts
8178
assert_eq!(
8279
String::from_utf8_lossy(&out.stdout),
83-
"<html><head>\
84-
<meta http-equiv=\"Content-Security-Policy\" content=\"font-src 'none';\"></meta>\
85-
<style></style>\
86-
</head><body>Hi</body></html>\n"
80+
r#"<html><head><meta http-equiv="Content-Security-Policy" content="font-src 'none';"></meta><style></style></head><body>Hi</body></html>
81+
"#
8782
);
8883

8984
// Exit code should be 0
@@ -96,7 +91,7 @@ mod passing {
9691
let out = cmd
9792
.arg("-M")
9893
.arg("-f")
99-
.arg("data:text/html,<iframe src=\"https://duckduckgo.com\"></iframe>Hi")
94+
.arg(r#"data:text/html,<iframe src="https://duckduckgo.com"></iframe>Hi"#)
10095
.output()
10196
.unwrap();
10297

@@ -106,9 +101,8 @@ mod passing {
106101
// STDOUT should contain HTML with no iframes
107102
assert_eq!(
108103
String::from_utf8_lossy(&out.stdout),
109-
"<html><head>\
110-
<meta http-equiv=\"Content-Security-Policy\" content=\"frame-src 'none'; child-src 'none';\"></meta>\
111-
</head><body><iframe src=\"\"></iframe>Hi</body></html>\n"
104+
r#"<html><head><meta http-equiv="Content-Security-Policy" content="frame-src 'none'; child-src 'none';"></meta></head><body><iframe src=""></iframe>Hi</body></html>
105+
"#
112106
);
113107

114108
// Exit code should be 0
@@ -132,15 +126,8 @@ mod passing {
132126
assert_eq!(
133127
String::from_utf8_lossy(&out.stdout),
134128
format!(
135-
"<html>\
136-
<head>\
137-
<meta http-equiv=\"Content-Security-Policy\" content=\"img-src data:;\"></meta>\
138-
</head>\
139-
<body>\
140-
<img src=\"{empty_image}\">\
141-
Hi\
142-
</body>\
143-
</html>\n",
129+
r#"<html><head><meta http-equiv="Content-Security-Policy" content="img-src data:;"></meta></head><body><img src="{empty_image}">Hi</body></html>
130+
"#,
144131
empty_image =EMPTY_IMAGE_DATA_URL,
145132
)
146133
);
@@ -165,12 +152,8 @@ mod passing {
165152
// STDOUT should contain HTML with no JS
166153
assert_eq!(
167154
String::from_utf8_lossy(&out.stdout),
168-
"<html>\
169-
<head>\
170-
<meta http-equiv=\"Content-Security-Policy\" content=\"script-src 'none';\"></meta>\
171-
<script></script></head>\
172-
<body>Hi</body>\
173-
</html>\n"
155+
r#"<html><head><meta http-equiv="Content-Security-Policy" content="script-src 'none';"></meta><script></script></head><body>Hi</body></html>
156+
"#
174157
);
175158

176159
// Exit code should be 0
@@ -211,7 +194,7 @@ mod failing {
211194
letmut cmd =Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
212195
let out = cmd
213196
.arg("-M")
214-
.arg("data:text/html,%3Cscript%20src=\"src/tests/data/basic/local-script.js\"%3E%3C/script%3E")
197+
.arg(r#"data:text/html,%3Cscript%20src="src/tests/data/basic/local-script.js"%3E%3C/script%3E"#)
215198
.output()
216199
.unwrap();
217200

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp