Files
codex/prs/bolinfest/study/PR-2586-study.md
2025-09-02 15:17:45 -07:00

2.7 KiB
Raw Blame History

DOs

  • Bold the keyword: Assert exact output via one equality check for clarity and determinism.
let expected = format!(
    r#"[projects.{path_str}]
trust_level = "trusted"
"#
);
assert_eq!(contents, expected);
  • Bold the keyword: Inline variables in format! raw strings to avoid juggling placeholders.
let initial = format!(
    r#"[projects]
{path_str} = {{ trust_level = "untrusted" }}
"#
);
let expected = format!(
    r#"[projects.{path_str}]
trust_level = "trusted"
"#
);
  • Bold the keyword: Quote keys portably based on the path, so tests pass on Windows and Unix.
let raw_path = project_dir.path().to_string_lossy();
let path_str = if raw_path.contains('\\') {
    format!("'{}'", raw_path) // literal-quoted for backslashes
} else {
    format!("\"{}\"", raw_path) // basic-quoted otherwise
};
  • Bold the keyword: Prefer explicit child tables over inline tables for project entries.
// Good: explicit child table
let expected = format!(
    r#"[projects.{path_str}]
trust_level = "trusted"
"#
);
  • Bold the keyword: Keep [projects] implicit when you created it; only write it if it already existed.
// New file you created the table in: no standalone [projects]
let expected_new = format!(
    r#"[projects.{path_str}]
trust_level = "trusted"
"#
);

// Upgrading a file that already had [projects]: keep it and add the child table
let expected_upgrade = format!(
    r#"[projects]

[projects.{path_str}]
trust_level = "trusted"
"#
);

DONTs

  • Bold the keyword: Dont rely on scattered contains-based assertions; theyre brittle and unclear.
// Bad
assert!(!contents.contains("{ trust_level"));
assert!(contents.contains(&format!("[projects.\"{}\"]", raw_path))
     || contents.contains(&format!("[projects.'{}']", raw_path)));
  • Bold the keyword: Dont hardcode a single quoting style or check for two styles manually.
// Bad
let project_key_double = format!("[projects.\"{}\"]", raw_path);
let project_key_single = format!("[projects.'{}']", raw_path);
assert!(contents.contains(&project_key_double) || contents.contains(&project_key_single));
  • Bold the keyword: Dont emit inline tables for project trust; convert to an explicit table.
// Bad
let initial = format!(
    r#"[projects]
{path_str} = {{ trust_level = "trusted" }}
"#
);
  • Bold the keyword: Dont write a standalone [projects] header when you created the table.
// Bad
let expected = format!(
    r#"[projects]

[projects.{path_str}]
trust_level = "trusted"
"#
);
  • Bold the keyword: Dont leave {} placeholders when you can inline variables directly.
// Bad
let initial = format!(
    "[projects]\n'{}' = {{ trust_level = \"untrusted\" }}\n",
    raw_path
);