Skip to content

Commit

Permalink
style: simplify statements for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Nov 9, 2024
1 parent e6b7c63 commit f1bf12a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ mod tests_xdg {
fn get_temp_path(name: &str, suffix: &str) -> String {
let pid = std::process::id();
std::env::temp_dir()
.join(format!("{}.{}.{}", name, pid, suffix))
.join(format!("{name}.{pid}.{suffix}"))
.into_os_string()
.into_string()
.expect("failed to convert into string")
Expand Down
13 changes: 6 additions & 7 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ async fn delayed_response(req: HttpRequest) -> impl Responder {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(format!(
"<html><body><p>Delayed by {}ms</p></body></html>",
qs
"<html><body><p>Delayed by {qs}ms</p></body></html>"
))
}

Expand All @@ -50,7 +49,7 @@ where
let _ = env_logger::try_init();

// start the server on a random port
let bind_addr = format!("{}:0", host);
let bind_addr = format!("{host}:0");
let (tx, rx) = cbc::bounded(2);
let data = AppState {
tx: Arc::new(tx.clone()),
Expand Down Expand Up @@ -110,8 +109,8 @@ where
let tmpdir = cwd.join("target").join("tmp");
let html_dir = html_dir.unwrap_or(tmpdir);
let id = rand::thread_rng().next_u32();
let pb = html_dir.join(format!("test.{}.html", id));
let img_uri = format!("{}?r={}", URI_PNG_1PX, id);
let pb = html_dir.join(format!("test.{id}.html"));
let img_uri = format!("{URI_PNG_1PX}?r={id}");
check_request_received_using(img_uri, "127.0.0.1", |uri, _port| {
let url = url_op(&pb);
let mut html_file = std::fs::File::create(&pb).expect("failed to create html file");
Expand All @@ -132,8 +131,8 @@ where

#[allow(dead_code)]
pub async fn check_browser(browser: Browser, platform: &str) {
check_request_received(browser, format!("/{}", platform)).await;
check_request_received(browser, format!("/{}/😀😀😀", platform)).await;
check_request_received(browser, format!("/{platform}")).await;
check_request_received(browser, format!("/{platform}/😀😀😀")).await;
}

const URI_PNG_1PX: &str = "/img/1px.png";
Expand Down
12 changes: 5 additions & 7 deletions tests/test_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod tests {
async fn test_android() {
let mut app_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
app_dir.push("tests/test-android-app");
let uri = format!("/{}", TEST_PLATFORM);
let uri = format!("/{TEST_PLATFORM}");

check_request_received_using(uri, "127.0.0.1", |url, port| {
// modify android app code to use the correct url
Expand All @@ -32,7 +32,7 @@ mod tests {
.split('\n')
.map(|s| {
if s.starts_with("const SERVER_URL") {
format!("const SERVER_URL: &str = \"{}\";", url)
format!("const SERVER_URL: &str = \"{url}\";")
} else {
s.into()
}
Expand All @@ -55,16 +55,15 @@ mod tests {
log::error!("failed to run {:?}", adb_cmd);
}

let adb_reverse_port = format!("tcp:{}", port);
let adb_reverse_port = format!("tcp:{port}");
let mut adb_cmd = Command::new("adb");
adb_cmd
.arg("reverse")
.arg(&adb_reverse_port)
.arg(&adb_reverse_port);
assert!(
adb_cmd.status().expect("Failed to invoke").success(),
"Failed to run {:?}",
adb_cmd
"Failed to run {adb_cmd:?}"
);

// invoke app in android
Expand All @@ -83,8 +82,7 @@ mod tests {
// check for apk run status
assert!(
apk_run_status.expect("Failed to invoke").success(),
"failed to run {:?}",
apk_run_cmd
"failed to run {apk_run_cmd:?}"
);
})
.await;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests {
#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_wasm32() {
let uri = &format!("/{}", TEST_PLATFORM);
let uri = &format!("/{TEST_PLATFORM}");
let ipv4 = "127.0.0.1";
check_request_received_using(uri.into(), ipv4, |url, _port| {
// modify html to use the correct url
Expand Down

0 comments on commit f1bf12a

Please sign in to comment.