From ca34b55ca2abd90b2da2c315d243169a204da4af Mon Sep 17 00:00:00 2001 From: Danny Hooper Date: Wed, 10 Jul 2024 18:22:08 -0500 Subject: [PATCH] fake-formatter: add --uppercase and --append formatting behaviors This allows tests to easily distinguish the effects of multiple formatters that could be applied during a single `jj fix` command, which is helpful for testing the feature for configuring multiple formatters on potentially overlapping filesets. Uppercase is a counterpart to lowercase. Append exposes the number of changes and their order of execution in the file content, which provides a terse way of writing test expectations. --- cli/testing/fake-formatter.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cli/testing/fake-formatter.rs b/cli/testing/fake-formatter.rs index 777e4a5b3b..a58791d4a6 100644 --- a/cli/testing/fake-formatter.rs +++ b/cli/testing/fake-formatter.rs @@ -44,6 +44,14 @@ struct Args { #[arg(long, default_value_t = false)] uppercase: bool, + /// Convert all characters to lowercase when reading stdin. + #[arg(long, default_value_t = false)] + lowercase: bool, + + /// Adds a line to the end of the file + #[arg(long)] + append: Option, + /// Write this string to stdout, and ignore stdin. #[arg(long)] stdout: Option, @@ -64,9 +72,14 @@ fn main() -> ExitCode { eprint!("{}", data); } let stdout = if let Some(data) = args.stdout { - data // --reverse doesn't apply to --stdout. + // Other content-altering flags don't apply to --stdout. + assert!(!args.reverse); + assert!(!args.uppercase); + assert!(!args.lowercase); + assert!(args.append.is_none()); + data } else { - std::io::stdin() + let mut stdout = std::io::stdin() .lines() .map(|line| { format!("{}\n", { @@ -76,13 +89,21 @@ fn main() -> ExitCode { line.unwrap() }; if args.uppercase { + assert!(!args.lowercase); line.to_uppercase() + } else if args.lowercase { + assert!(!args.uppercase); + line.to_lowercase() } else { line } }) }) - .join("") + .join(""); + if let Some(line) = args.append { + stdout.push_str(&line); + } + stdout }; print!("{}", stdout); if let Some(path) = args.tee {