Merged tests drop needless borrows and name their complex types
Browse files at this commit5852a685c1c8a567f1940e21d10d046f2de1e63dParent: b757c23- lint
- merged tests drop needless borrows and name their complex types
7 changed files +35 -30
- crates/forge-web/src/api/statuses.rs +2 -1
- crates/forge-web/src/git_auth.rs +2 -1
- crates/forge-web/src/pages/browse_tests.rs +13 -13
- crates/forge-web/src/pages/forgot.rs +12 -12
- crates/forge-web/src/pages/new_repo.rs +2 -1
- crates/forge-web/src/signatures.rs +2 -1
- crates/forge-web/src/views/heatmap.rs +2 -1
crates/forge-web/src/api/statuses.rsmodified+2 -1
| @@ -361,7 +361,8 @@ mod tests { | ||
| 361 | 361 | let bad_sha = report_uri("abc123"); |
| 362 | 362 | let missing = report_uri(&"0".repeat(40)); |
| 363 | 363 | // (case, uri, auth, cookie, body, expected status, expects a JSON error body) |
| 364 | - let cases: [(&str, &str, Option<&str>, Option<&str>, Option<&str>, u16, bool); 10] = [ | |
| 364 | + type Case<'a> = (&'a str, &'a str, Option<&'a str>, Option<&'a str>, Option<&'a str>, u16, bool); | |
| 365 | + let cases: [Case<'_>; 10] = [ | |
| 365 | 366 | ("read-only token", report.as_str(), Some(reader.as_str()), None, Some(SUCCESS), 403, true), |
| 366 | 367 | ("anonymous", report.as_str(), None, None, Some(SUCCESS), 401, true), |
| 367 | 368 | ("bad token", report.as_str(), Some("Bearer forge_not_a_real_token"), None, Some(SUCCESS), 401, false), |
crates/forge-web/src/git_auth.rsmodified+2 -1
| @@ -102,7 +102,8 @@ mod tests { | ||
| 102 | 102 | fn parse_basic_auth_cases() { |
| 103 | 103 | // One labelled table: each case keeps its own input and expected result. |
| 104 | 104 | let t = BASE64_STANDARD.encode("tahinli:t"); |
| 105 | - let cases: Vec<(&str, String, Option<(&str, &str)>)> = vec![ | |
| 105 | + type Case<'a> = (&'a str, String, Option<(&'a str, &'a str)>); | |
| 106 | + let cases: Vec<Case<'_>> = vec![ | |
| 106 | 107 | ( |
| 107 | 108 | "user and token", |
| 108 | 109 | basic("tahinli:forge_abc"), |
crates/forge-web/src/pages/browse_tests.rsmodified+13 -13
| @@ -73,7 +73,7 @@ fn whitespace_commit(fx: &Fixture) -> String { | ||
| 73 | 73 | |
| 74 | 74 | /// The commit toolbar, and the whitespace toggle that hides whitespace-only files. |
| 75 | 75 | async fn scenario_whitespace_toolbar(fx: &Fixture) { |
| 76 | - let oid = whitespace_commit(&fx); | |
| 76 | + let oid = whitespace_commit(fx); | |
| 77 | 77 | let base = format!("/{OWNER}/{REPO}/commit/{oid}"); |
| 78 | 78 | |
| 79 | 79 | let (status, _, body) = get(&fx.router, &base).await; |
| @@ -275,7 +275,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 275 | 275 | ); |
| 276 | 276 | let page = format!("/{OWNER}/{REPO}/branches"); |
| 277 | 277 | |
| 278 | - let (status, _, html) = send(&fx.router, "GET", &page, Some(&cookie), &[]).await; | |
| 278 | + let (status, _, html) = send(&fx.router, "GET", &page, Some(cookie), &[]).await; | |
| 279 | 279 | assert_eq!(status, 200); |
| 280 | 280 | // feature is 1 ahead of and 54 behind main (the root is its base, main has 54 more commits). |
| 281 | 281 | assert!(html.contains("1 ahead, 54 behind"), "{html}"); |
| @@ -292,7 +292,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 292 | 292 | &fx.router, |
| 293 | 293 | "POST", |
| 294 | 294 | &page, |
| 295 | - Some(&cookie), | |
| 295 | + Some(cookie), | |
| 296 | 296 | &[("csrf", CSRF), ("name", "topic/one"), ("from", "feature")], |
| 297 | 297 | ) |
| 298 | 298 | .await; |
| @@ -314,7 +314,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 314 | 314 | &fx.router, |
| 315 | 315 | "POST", |
| 316 | 316 | &page, |
| 317 | - Some(&cookie), | |
| 317 | + Some(cookie), | |
| 318 | 318 | &[("csrf", CSRF), ("name", name), ("from", from)], |
| 319 | 319 | ) |
| 320 | 320 | .await; |
| @@ -338,7 +338,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 338 | 338 | &fx.router, |
| 339 | 339 | "POST", |
| 340 | 340 | &page, |
| 341 | - Some(&cookie), | |
| 341 | + Some(cookie), | |
| 342 | 342 | &[("csrf", "wrong"), ("name", "x"), ("from", "main")], |
| 343 | 343 | ) |
| 344 | 344 | .await; |
| @@ -350,7 +350,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 350 | 350 | &fx.router, |
| 351 | 351 | "POST", |
| 352 | 352 | &delete, |
| 353 | - Some(&cookie), | |
| 353 | + Some(cookie), | |
| 354 | 354 | &[("csrf", CSRF), ("name", "topic/one"), ("oid", &fx.root)], |
| 355 | 355 | ) |
| 356 | 356 | .await; |
| @@ -360,7 +360,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 360 | 360 | &fx.router, |
| 361 | 361 | "POST", |
| 362 | 362 | &delete, |
| 363 | - Some(&cookie), | |
| 363 | + Some(cookie), | |
| 364 | 364 | &[("csrf", CSRF), ("name", "topic/one"), ("oid", &feature_tip)], |
| 365 | 365 | ) |
| 366 | 366 | .await; |
| @@ -374,7 +374,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | ||
| 374 | 374 | &fx.router, |
| 375 | 375 | "POST", |
| 376 | 376 | &delete, |
| 377 | - Some(&cookie), | |
| 377 | + Some(cookie), | |
| 378 | 378 | &[("csrf", CSRF), ("name", "main"), ("oid", &main_tip)], |
| 379 | 379 | ) |
| 380 | 380 | .await; |
| @@ -402,7 +402,7 @@ async fn scenario_protection(fx: &Fixture, cookie: &str) { | ||
| 402 | 402 | &fx.router, |
| 403 | 403 | "POST", |
| 404 | 404 | &delete, |
| 405 | - Some(&cookie), | |
| 405 | + Some(cookie), | |
| 406 | 406 | &[("csrf", CSRF), ("name", "release/1"), ("oid", &tip)], |
| 407 | 407 | ) |
| 408 | 408 | .await; |
| @@ -412,7 +412,7 @@ async fn scenario_protection(fx: &Fixture, cookie: &str) { | ||
| 412 | 412 | &fx.router, |
| 413 | 413 | "POST", |
| 414 | 414 | &delete, |
| 415 | - Some(&cookie), | |
| 415 | + Some(cookie), | |
| 416 | 416 | &[("csrf", CSRF), ("name", "scratch"), ("oid", &tip)], |
| 417 | 417 | ) |
| 418 | 418 | .await; |
| @@ -428,7 +428,7 @@ async fn scenario_default_branch(fx: &Fixture, cookie: &str) { | ||
| 428 | 428 | &fx.router, |
| 429 | 429 | "POST", |
| 430 | 430 | &settings, |
| 431 | - Some(&cookie), | |
| 431 | + Some(cookie), | |
| 432 | 432 | &[ |
| 433 | 433 | ("csrf", CSRF), |
| 434 | 434 | ("description", "demo"), |
| @@ -452,7 +452,7 @@ async fn scenario_default_branch(fx: &Fixture, cookie: &str) { | ||
| 452 | 452 | &fx.router, |
| 453 | 453 | "POST", |
| 454 | 454 | &settings, |
| 455 | - Some(&cookie), | |
| 455 | + Some(cookie), | |
| 456 | 456 | &[ |
| 457 | 457 | ("csrf", CSRF), |
| 458 | 458 | ("description", "demo"), |
| @@ -474,7 +474,7 @@ async fn scenario_default_branch(fx: &Fixture, cookie: &str) { | ||
| 474 | 474 | &fx.router, |
| 475 | 475 | "GET", |
| 476 | 476 | &format!("/{OWNER}/{REPO}/settings"), |
| 477 | - Some(&cookie), | |
| 477 | + Some(cookie), | |
| 478 | 478 | &[], |
| 479 | 479 | ) |
| 480 | 480 | .await; |
crates/forge-web/src/pages/forgot.rsmodified+12 -12
| @@ -291,10 +291,10 @@ mod tests { | ||
| 291 | 291 | .await |
| 292 | 292 | .unwrap(); |
| 293 | 293 | for address in ["nobody@example.com", "frank@example.com"] { |
| 294 | - let (cookie, precsrf) = precsrf_for(&router, "/forgot").await; | |
| 294 | + let (cookie, precsrf) = precsrf_for(router, "/forgot").await; | |
| 295 | 295 | let form = format!("precsrf={precsrf}&email={}", address.replace('@', "%40")); |
| 296 | 296 | let (status, _, html) = |
| 297 | - send(&router, "POST", "/forgot", Some(&cookie), Some(&form)).await; | |
| 297 | + send(router, "POST", "/forgot", Some(&cookie), Some(&form)).await; | |
| 298 | 298 | assert_eq!(status, 200, "{address}"); |
| 299 | 299 | assert!(html.contains("a reset link is on its way"), "{address}"); |
| 300 | 300 | } |
| @@ -326,21 +326,21 @@ mod tests { | ||
| 326 | 326 | .is_some() |
| 327 | 327 | ); |
| 328 | 328 | |
| 329 | - let (cookie, precsrf) = precsrf_for(&router, "/forgot").await; | |
| 329 | + let (cookie, precsrf) = precsrf_for(router, "/forgot").await; | |
| 330 | 330 | let form = format!("precsrf={precsrf}&email=gina%40example.com"); |
| 331 | - let (status, _, _) = send(&router, "POST", "/forgot", Some(&cookie), Some(&form)).await; | |
| 331 | + let (status, _, _) = send(router, "POST", "/forgot", Some(&cookie), Some(&form)).await; | |
| 332 | 332 | assert_eq!(status, 200); |
| 333 | - let body = wait_for_mail(&state, "/reset/").await; | |
| 333 | + let body = wait_for_mail(state, "/reset/").await; | |
| 334 | 334 | let path = link_in(&body, "/reset/"); |
| 335 | 335 | |
| 336 | - let (status, _, html) = send(&router, "GET", &path, None, None).await; | |
| 336 | + let (status, _, html) = send(router, "GET", &path, None, None).await; | |
| 337 | 337 | assert_eq!(status, 200); |
| 338 | 338 | assert!(html.contains("Set a new password")); |
| 339 | 339 | |
| 340 | - let (cookie, precsrf) = precsrf_for(&router, &path).await; | |
| 340 | + let (cookie, precsrf) = precsrf_for(router, &path).await; | |
| 341 | 341 | let form = |
| 342 | 342 | format!("precsrf={precsrf}&password=brand-new-password-1&confirm=brand-new-password-1"); |
| 343 | - let (status, _, html) = send(&router, "POST", &path, Some(&cookie), Some(&form)).await; | |
| 343 | + let (status, _, html) = send(router, "POST", &path, Some(&cookie), Some(&form)).await; | |
| 344 | 344 | assert_eq!(status, 200); |
| 345 | 345 | assert!(html.contains("Your password is changed")); |
| 346 | 346 | |
| @@ -352,10 +352,10 @@ mod tests { | ||
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | 354 | // The same link is spent now. |
| 355 | - let (cookie, precsrf) = precsrf_for(&router, &path).await; | |
| 355 | + let (cookie, precsrf) = precsrf_for(router, &path).await; | |
| 356 | 356 | let form = |
| 357 | 357 | format!("precsrf={precsrf}&password=another-password-22&confirm=another-password-22"); |
| 358 | - let (status, _, html) = send(&router, "POST", &path, Some(&cookie), Some(&form)).await; | |
| 358 | + let (status, _, html) = send(router, "POST", &path, Some(&cookie), Some(&form)).await; | |
| 359 | 359 | assert_eq!(status, 200); |
| 360 | 360 | assert!(html.contains("This reset link is invalid")); |
| 361 | 361 | } |
| @@ -376,9 +376,9 @@ mod tests { | ||
| 376 | 376 | let token = state.store.create_reset_token(&user.id).await.unwrap(); |
| 377 | 377 | let path = format!("/reset/{token}"); |
| 378 | 378 | |
| 379 | - let (cookie, precsrf) = precsrf_for(&router, &path).await; | |
| 379 | + let (cookie, precsrf) = precsrf_for(router, &path).await; | |
| 380 | 380 | let form = format!("precsrf={precsrf}&password=short&confirm=short"); |
| 381 | - let (status, _, html) = send(&router, "POST", &path, Some(&cookie), Some(&form)).await; | |
| 381 | + let (status, _, html) = send(router, "POST", &path, Some(&cookie), Some(&form)).await; | |
| 382 | 382 | assert_eq!(status, 200); |
| 383 | 383 | assert!( |
| 384 | 384 | html.contains("Set a new password"), |
crates/forge-web/src/pages/new_repo.rsmodified+2 -1
| @@ -498,7 +498,8 @@ mod tests { | ||
| 498 | 498 | #[tokio::test] |
| 499 | 499 | async fn default_labels_are_added_only_when_checked() { |
| 500 | 500 | let site = site().await; |
| 501 | - let cases: [(&str, &[(&str, &str)], usize); 2] = [ | |
| 501 | + type Case<'a> = (&'a str, &'a [(&'a str, &'a str)], usize); | |
| 502 | + let cases: [Case<'_>; 2] = [ | |
| 502 | 503 | ("checked", &[("default_labels", "on")], 9), |
| 503 | 504 | ("unchecked", &[], 0), |
| 504 | 505 | ]; |
crates/forge-web/src/signatures.rsmodified+2 -1
| @@ -793,7 +793,8 @@ mod tests { | ||
| 793 | 793 | #[test] |
| 794 | 794 | fn key_listing_parses_one_key_or_rejects() { |
| 795 | 795 | // (name, colon listing, expected Some((primary fingerprint, emails)) or None for rejection) |
| 796 | - let cases: Vec<(&str, &str, Option<(&str, Vec<&str>)>)> = vec![ | |
| 796 | + type Case<'a> = (&'a str, &'a str, Option<(&'a str, Vec<&'a str>)>); | |
| 797 | + let cases: Vec<Case<'_>> = vec![ | |
| 797 | 798 | ( |
| 798 | 799 | "primary fingerprint and emails", |
| 799 | 800 | "pub:u:255:22:ABCDEF0123456789ABCDEF0123456789ABCDEF01:1700000000::::::23::0:\n\ |
crates/forge-web/src/views/heatmap.rsmodified+2 -1
| @@ -354,7 +354,8 @@ mod tests { | ||
| 354 | 354 | #[test] |
| 355 | 355 | fn a_gap_or_an_old_run_ends_the_current_streak() { |
| 356 | 356 | // (case, counts, current streak, longest streak) |
| 357 | - let cases: [(&str, &[(&str, u32)], u64, u64); 2] = [ | |
| 357 | + type Case<'a> = (&'a str, &'a [(&'a str, u32)], u64, u64); | |
| 358 | + let cases: [Case<'_>; 2] = [ | |
| 358 | 359 | ( |
| 359 | 360 | "old run", |
| 360 | 361 | &[("2026-10-01", 3), ("2026-10-02", 3)], |