#![allow(missing_docs)]
use predicates::prelude::*;
use std::fs;
use tempfile::NamedTempFile;
use textum::{BoundaryMode, Patch, PatchSet};
#[test]
fn patch_replaces_text_in_tempfile() {
let temp = NamedTempFile::new().unwrap();
fs::write(temp.path(), "Hello Louis!").unwrap();
let patch = Patch::from_literal_target(
temp.path().to_string_lossy().into(),
"Louis",
BoundaryMode::Include,
"World",
);
let mut set = PatchSet::new();
set.add(patch);
let results = set
.apply_to_files()
.expect("patch application should succeed");
let new_content = results
.get(temp.path().to_str().unwrap())
.expect("file should be in results");
assert_eq!(new_content, "Hello World!");
fs::write(temp.path(), new_content).unwrap();
let on_disk = fs::read_to_string(temp.path()).unwrap();
assert!(predicate::str::contains("World").eval(&on_disk));
assert!(predicate::str::is_match(r"^Hello\sWorld!$")
.unwrap()
.eval(&on_disk));
}