mirror of
https://github.com/clap-rs/clap
synced 2024-12-16 15:52:44 +00:00
1bbfd956aa
In a follow up commit, my editor stripped trailing whitespace. Rather than have everyone fight this, let's not make a deal over the small stuff.
38 lines
893 B
Rust
38 lines
893 B
Rust
use clap::{App, Arg, ValueHint};
|
|
use clap_generate::{generate, generators::*};
|
|
use std::fmt;
|
|
|
|
mod bash;
|
|
mod elvish;
|
|
mod fish;
|
|
mod powershell;
|
|
mod zsh;
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
pub struct PrettyString<'a>(pub &'a str);
|
|
|
|
impl<'a> fmt::Debug for PrettyString<'a> {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
f.write_str(self.0)
|
|
}
|
|
}
|
|
|
|
macro_rules! assert_eq {
|
|
($left:expr, $right:expr) => {
|
|
pretty_assertions::assert_eq!(PrettyString($left), PrettyString($right));
|
|
};
|
|
}
|
|
|
|
pub fn common<G: Generator>(gen: G, app: &mut App, name: &str, fixture: &str) {
|
|
let mut buf = vec![];
|
|
generate(gen, app, name, &mut buf);
|
|
let string = String::from_utf8(buf).unwrap();
|
|
|
|
assert_eq!(&normalize(&string), &normalize(fixture));
|
|
}
|
|
|
|
fn normalize(string: &str) -> String {
|
|
use itertools::Itertools;
|
|
|
|
string.lines().map(|s| s.trim_end()).join("\n")
|
|
}
|