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)
| 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. |
| 460 | fn 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] |
| 472 | fn test_rewrite_with_line_ending() -> io::Result<()> { |
no outgoing calls
no test coverage detected