Skip to content

Commit

Permalink
Merge pull request #24 from LukasKalbertodt/ln-without-format
Browse files Browse the repository at this point in the history
Allow `println`, `eprintln` & `writeln` to be used without format string
  • Loading branch information
LukasKalbertodt committed Sep 9, 2021
2 parents fc40fc0 + d45b50f commit 7073596
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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 @@ -256,6 +259,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 @@ -303,6 +309,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

0 comments on commit 7073596

Please sign in to comment.