Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow println, eprintln & writeln to be used without format string #24

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ macro_rules! writeln {
$target [$($format_str)+] $( $arg )*
)
};
($target:expr $(,)?) => {
$crate::writeln!($target, "")
};
}

/// Writes formatted data to stdout (with `ColorChoice::Auto`).
Expand Down Expand Up @@ -255,6 +258,9 @@ macro_rules! println {
[$($format_str)+] $( $arg )*
).expect("failed to write to stdout in `bunt::println`")
};
() => {
std::println!()
};
}

/// Writes formatted data to stderr (with `ColorChoice::Auto`).
Expand Down Expand Up @@ -302,6 +308,9 @@ macro_rules! eprintln {
[$($format_str)+] $( $arg )*
).expect("failed to write to stderr in `bunt::eprintln`")
};
() => {
std::eprintln!()
};
}

/// Parses the given style specification string and returns the corresponding
Expand Down
13 changes: 13 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ fn no_move_args() {
}
}

#[test]
fn empty_ln() {
// Just make sure they compile, we cannot easily capture and test their output.
println!();
eprintln!();


let mut b = buf();
writeln!(b).unwrap();
writeln!(b,).unwrap();
assert_eq!(raw_str(&b), "\n\n");
}

#[test]
fn arg_referal() {
check!("27" == "{peter}", peter = 27);
Expand Down