file-editor 0.2.0

Clean, elegant API for creating and editing text files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use file_editor::Editor;

/// cover: `insert_after` on the *same line* (`insert_pos == after_marker`)
#[test]
fn insert_after_same_line_no_space_needed() -> std::io::Result<()> {
    let dir = tempfile::tempdir()?;
    let path = dir.path().join("inline.txt");

    Editor::create(&path)?
        .append("hello:world") // no newline
        .insert_after("hello", "_", false)
        .save()?;

    assert_eq!(std::fs::read_to_string(path)?, "hello _:world");
    Ok(())
}