summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCosmicHorror <CosmicHorrorDev@pm.me>2023-11-02 18:05:55 -0600
committerGitHub <noreply@github.com>2023-11-02 19:05:55 -0500
commit4f77cfe1b8681bd164ea990e6c0ec2c2b8acb614 (patch)
treecc6a21cf2faec0665882c421d077863809c711b6 /tests
parent79f5de0db76aef3ab8f02d204890de6f74d69d12 (diff)
Rework the replacements flag (#267)
* Add replacements tests * Honor `-n` when using `--preview` * Rework CLI for replacements flag * Remove dead code * Remove lingering TODO
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs
index d0af23f..a727ed5 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -194,4 +194,60 @@ mod cli {
<b>^^^^</b>
"###);
}
+
+ #[test]
+ fn limit_replacements_file() -> Result<()> {
+ let mut file = tempfile::NamedTempFile::new()?;
+ file.write_all(b"foo\nfoo\nfoo")?;
+ let path = file.into_temp_path();
+
+ sd().args(["-n", "1", "foo", "bar", path.to_str().unwrap()])
+ .assert()
+ .success();
+ assert_file(&path, "bar\nfoo\nfoo");
+
+ Ok(())
+ }
+
+ #[test]
+ fn limit_replacements_file_preview() -> Result<()> {
+ let mut file = tempfile::NamedTempFile::new()?;
+ file.write_all(b"foo\nfoo\nfoo")?;
+ let path = file.into_temp_path();
+
+ sd().args([
+ "--preview",
+ "-n",
+ "1",
+ "foo",
+ "bar",
+ path.to_str().unwrap(),
+ ])
+ .assert()
+ .success()
+ .stdout(format!(
+ "{}\nfoo\nfoo\n",
+ ansi_term::Color::Green.paint("bar")
+ ));
+
+ Ok(())
+ }
+
+ #[test]
+ fn limit_replacements_stdin() {
+ sd().args(["-n", "1", "foo", "bar"])
+ .write_stdin("foo\nfoo\nfoo")
+ .assert()
+ .success()
+ .stdout("bar\nfoo\nfoo");
+ }
+
+ #[test]
+ fn limit_replacements_stdin_preview() {
+ sd().args(["--preview", "-n", "1", "foo", "bar"])
+ .write_stdin("foo\nfoo\nfoo")
+ .assert()
+ .success()
+ .stdout("bar\nfoo\nfoo");
+ }
}