mirror of
https://github.com/openai/codex.git
synced 2026-04-28 10:21:06 +03:00
2.7 KiB
2.7 KiB
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"
"#
);
DON’Ts
- Bold the keyword: Don’t rely on scattered contains-based assertions; they’re 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: Don’t 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: Don’t 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: Don’t 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: Don’t leave
{}placeholders when you can inline variables directly.
// Bad
let initial = format!(
"[projects]\n'{}' = {{ trust_level = \"untrusted\" }}\n",
raw_path
);