MCPcopy Index your code
hub / github.com/endbasic/endbasic / rewrite_with_line_ending

Function rewrite_with_line_ending

core/tests/testutils/mod.rs:460–469  ·  view source on GitHub ↗

Rewrites `path` file with to use `line_ending`. This is "inefficient" (not that it matters in this specific scenario) but it helps keep `generate()` simple _and_ it also allows us to validate CRLF behavior outside of Windows.

(path: &Path, line_ending: &str)

Source from the content-addressed store, hash-verified

458/// This is "inefficient" (not that it matters in this specific scenario) but it helps keep
459/// `generate()` simple _and_ it also allows us to validate CRLF behavior outside of Windows.
460fn rewrite_with_line_ending(path: &Path, line_ending: &str) -> io::Result<()> {
461 if line_ending == "\n" {
462 return Ok(());
463 }
464
465 let text = fs::read_to_string(path)?;
466 let normalized = text.replace("\r\n", "\n");
467 let rewritten = normalized.replace('\n', line_ending);
468 fs::write(path, rewritten)
469}
470
471#[test]
472fn test_rewrite_with_line_ending() -> io::Result<()> {

Callers 2

run_one_testFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected