Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,16 @@ macro_rules! define_unumeric {
///
/// - only valid UTF-8 data can be printed.
/// - an `X` format specifier with a `#` flag prints the hex data in uppercase,
/// but the leading `0x` is still lowercase
/// but the leading `0x` is still lowercase.
/// - an `o` format specifier with a `#` flag precedes the number with an `o`
/// instead of `0`
/// instead of `0`.
/// - `g`/`G` (shorted floating point) is aliased to `f`/`F`` (decimal floating
/// point)
/// - same for `a`/`A` (hex floating point)
/// point).
/// - same for `a`/`A` (hex floating point).
/// - the `n` format specifier, [`Specifier::WriteBytesWritten`], is not
/// implemented and will cause an error if encountered.
/// - precision is ignored for integral types, instead of specifying the
/// minimum number of digits.
pub fn fmt_write(w: &mut impl fmt::Write) -> impl FnMut(Argument) -> c_int + '_ {
use fmt::Write;
move |Argument {
Expand Down
14 changes: 14 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,17 @@ fn test_errors() {
assert_fmt_err(c"%");
assert_fmt_err(c"%1");
}

/// Test that specifying precision with an integral type does _not_
/// match C. This is one of the documented differences in
/// `fmt_write`. If this is fixed, make sure to update the
/// documentation.
///
/// https://github.com/lights0123/printf-compat/issues/50
#[test]
fn test_int_precision() {
unsafe {
assert_eq!(c_fmt!(c"%.3d", 1).1, "001");
assert_eq!(rust_fmt(c"%.3d".as_ptr(), 1).1, "1");
}
}