diff --git a/src/output.rs b/src/output.rs index 2cd419b..efee0b3 100644 --- a/src/output.rs +++ b/src/output.rs @@ -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 { diff --git a/tests/tests.rs b/tests/tests.rs index af74bc5..789a541 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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"); + } +}