From cff8cc0e22f655f6cc2f00175e826b4f5c36209e Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 18:08:51 -0400 Subject: [PATCH] Fix clippy::unreadable_literal. --- src/uu/df/src/table.rs | 18 ++-- src/uu/od/src/inputdecoder.rs | 4 +- src/uu/od/src/prn_float.rs | 85 ++++++++++--------- src/uucore/src/lib/features/format/human.rs | 2 +- .../src/lib/features/format/num_format.rs | 68 +++++++-------- .../src/lib/features/format/num_parser.rs | 2 +- src/uucore/src/lib/features/fsext.rs | 12 +-- src/uucore/src/lib/features/process.rs | 2 +- src/uucore/src/lib/mods/posix.rs | 6 +- src/uucore/src/lib/parser/parse_glob.rs | 2 +- 10 files changed, 102 insertions(+), 99 deletions(-) diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index daa30d1ee..460bd0329 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -841,12 +841,12 @@ mod tests { }, usage: crate::table::FsUsage { blocksize: 4096, - blocks: 244029695, - bfree: 125085030, - bavail: 125085030, + blocks: 244_029_695, + bfree: 125_085_030, + bavail: 125_085_030, bavail_top_bit_set: false, files: 999, - ffree: 1000000, + ffree: 1_000_000, }, }; @@ -871,12 +871,12 @@ mod tests { }, usage: crate::table::FsUsage { blocksize: 4096, - blocks: 244029695, - bfree: 125085030, - bavail: 125085030, + blocks: 244_029_695, + bfree: 125_085_030, + bavail: 125_085_030, bavail_top_bit_set: false, - files: 99999999999, - ffree: 999999, + files: 99_999_999_999, + ffree: 999_999, }, }; diff --git a/src/uu/od/src/inputdecoder.rs b/src/uu/od/src/inputdecoder.rs index e63eaed14..62117d546 100644 --- a/src/uu/od/src/inputdecoder.rs +++ b/src/uu/od/src/inputdecoder.rs @@ -179,8 +179,8 @@ mod tests { assert_eq!(-2.0, mem.read_float(0, 8)); assert_eq!(-2.0, mem.read_float(4, 4)); - assert_eq!(0xc000000000000000, mem.read_uint(0, 8)); - assert_eq!(0xc0000000, mem.read_uint(4, 4)); + assert_eq!(0xc000_0000_0000_0000, mem.read_uint(0, 8)); + assert_eq!(0xc000_0000, mem.read_uint(4, 4)); assert_eq!(0xc000, mem.read_uint(6, 2)); assert_eq!(0xc0, mem.read_uint(7, 1)); assert_eq!(&[0, 0xc0], mem.get_buffer(6)); diff --git a/src/uu/od/src/prn_float.rs b/src/uu/od/src/prn_float.rs index f44abf7c4..f524a0203 100644 --- a/src/uu/od/src/prn_float.rs +++ b/src/uu/od/src/prn_float.rs @@ -94,72 +94,72 @@ fn format_float(f: f64, width: usize, precision: usize) -> String { #[allow(clippy::cognitive_complexity)] fn test_format_flo32() { assert_eq!(format_flo32(1.0), " 1.0000000"); - assert_eq!(format_flo32(9.9999990), " 9.9999990"); + assert_eq!(format_flo32(9.999_999_0), " 9.9999990"); assert_eq!(format_flo32(10.0), " 10.000000"); - assert_eq!(format_flo32(99.999977), " 99.999977"); - assert_eq!(format_flo32(99.999992), " 99.999992"); + assert_eq!(format_flo32(99.999_977), " 99.999977"); + assert_eq!(format_flo32(99.999_992), " 99.999992"); assert_eq!(format_flo32(100.0), " 100.00000"); assert_eq!(format_flo32(999.99994), " 999.99994"); assert_eq!(format_flo32(1000.0), " 1000.0000"); assert_eq!(format_flo32(9999.9990), " 9999.9990"); assert_eq!(format_flo32(10000.0), " 10000.000"); assert_eq!(format_flo32(99999.992), " 99999.992"); - assert_eq!(format_flo32(100000.0), " 100000.00"); - assert_eq!(format_flo32(999999.94), " 999999.94"); - assert_eq!(format_flo32(1000000.0), " 1000000.0"); - assert_eq!(format_flo32(9999999.0), " 9999999.0"); - assert_eq!(format_flo32(10000000.0), " 10000000"); - assert_eq!(format_flo32(99999992.0), " 99999992"); - assert_eq!(format_flo32(100000000.0), " 1.0000000e8"); - assert_eq!(format_flo32(9.9999994e8), " 9.9999994e8"); + assert_eq!(format_flo32(100_000.0), " 100000.00"); + assert_eq!(format_flo32(999_999.94), " 999999.94"); + assert_eq!(format_flo32(1_000_000.0), " 1000000.0"); + assert_eq!(format_flo32(9_999_999.0), " 9999999.0"); + assert_eq!(format_flo32(10_000_000.0), " 10000000"); + assert_eq!(format_flo32(99_999_992.0), " 99999992"); + assert_eq!(format_flo32(100_000_000.0), " 1.0000000e8"); + assert_eq!(format_flo32(9.999_999_4e8), " 9.9999994e8"); assert_eq!(format_flo32(1.0e9), " 1.0000000e9"); - assert_eq!(format_flo32(9.9999990e9), " 9.9999990e9"); + assert_eq!(format_flo32(9.999_999_0e9), " 9.9999990e9"); assert_eq!(format_flo32(1.0e10), " 1.0000000e10"); assert_eq!(format_flo32(0.1), " 0.10000000"); - assert_eq!(format_flo32(0.99999994), " 0.99999994"); - assert_eq!(format_flo32(0.010000001), " 1.0000001e-2"); - assert_eq!(format_flo32(0.099999994), " 9.9999994e-2"); + assert_eq!(format_flo32(0.999_999_94), " 0.99999994"); + assert_eq!(format_flo32(0.010_000_001), " 1.0000001e-2"); + assert_eq!(format_flo32(0.099_999_994), " 9.9999994e-2"); assert_eq!(format_flo32(0.001), " 1.0000000e-3"); - assert_eq!(format_flo32(0.0099999998), " 9.9999998e-3"); + assert_eq!(format_flo32(0.009_999_999_8), " 9.9999998e-3"); assert_eq!(format_flo32(-1.0), " -1.0000000"); - assert_eq!(format_flo32(-9.9999990), " -9.9999990"); + assert_eq!(format_flo32(-9.999_999_0), " -9.9999990"); assert_eq!(format_flo32(-10.0), " -10.000000"); - assert_eq!(format_flo32(-99.999977), " -99.999977"); - assert_eq!(format_flo32(-99.999992), " -99.999992"); + assert_eq!(format_flo32(-99.999_977), " -99.999977"); + assert_eq!(format_flo32(-99.999_992), " -99.999992"); assert_eq!(format_flo32(-100.0), " -100.00000"); assert_eq!(format_flo32(-999.99994), " -999.99994"); assert_eq!(format_flo32(-1000.0), " -1000.0000"); assert_eq!(format_flo32(-9999.9990), " -9999.9990"); assert_eq!(format_flo32(-10000.0), " -10000.000"); assert_eq!(format_flo32(-99999.992), " -99999.992"); - assert_eq!(format_flo32(-100000.0), " -100000.00"); - assert_eq!(format_flo32(-999999.94), " -999999.94"); - assert_eq!(format_flo32(-1000000.0), " -1000000.0"); - assert_eq!(format_flo32(-9999999.0), " -9999999.0"); - assert_eq!(format_flo32(-10000000.0), " -10000000"); - assert_eq!(format_flo32(-99999992.0), " -99999992"); - assert_eq!(format_flo32(-100000000.0), " -1.0000000e8"); - assert_eq!(format_flo32(-9.9999994e8), " -9.9999994e8"); + assert_eq!(format_flo32(-100_000.0), " -100000.00"); + assert_eq!(format_flo32(-999_999.94), " -999999.94"); + assert_eq!(format_flo32(-1_000_000.0), " -1000000.0"); + assert_eq!(format_flo32(-9_999_999.0), " -9999999.0"); + assert_eq!(format_flo32(-10_000_000.0), " -10000000"); + assert_eq!(format_flo32(-99_999_992.0), " -99999992"); + assert_eq!(format_flo32(-100_000_000.0), " -1.0000000e8"); + assert_eq!(format_flo32(-9.999_999_4e8), " -9.9999994e8"); assert_eq!(format_flo32(-1.0e9), " -1.0000000e9"); - assert_eq!(format_flo32(-9.9999990e9), " -9.9999990e9"); + assert_eq!(format_flo32(-9.999_999_0e9), " -9.9999990e9"); assert_eq!(format_flo32(-1.0e10), " -1.0000000e10"); assert_eq!(format_flo32(-0.1), " -0.10000000"); - assert_eq!(format_flo32(-0.99999994), " -0.99999994"); - assert_eq!(format_flo32(-0.010000001), " -1.0000001e-2"); - assert_eq!(format_flo32(-0.099999994), " -9.9999994e-2"); + assert_eq!(format_flo32(-0.999_999_94), " -0.99999994"); + assert_eq!(format_flo32(-0.010_000_001), " -1.0000001e-2"); + assert_eq!(format_flo32(-0.099_999_994), " -9.9999994e-2"); assert_eq!(format_flo32(-0.001), " -1.0000000e-3"); - assert_eq!(format_flo32(-0.0099999998), " -9.9999998e-3"); + assert_eq!(format_flo32(-0.009_999_999_8), " -9.9999998e-3"); - assert_eq!(format_flo32(3.4028233e38), " 3.4028233e38"); - assert_eq!(format_flo32(-3.4028233e38), " -3.4028233e38"); - assert_eq!(format_flo32(-1.1663108e-38), "-1.1663108e-38"); - assert_eq!(format_flo32(-4.7019771e-38), "-4.7019771e-38"); + assert_eq!(format_flo32(3.402_823_3e38), " 3.4028233e38"); + assert_eq!(format_flo32(-3.402_823_3e38), " -3.4028233e38"); + assert_eq!(format_flo32(-1.166_310_8e-38), "-1.1663108e-38"); + assert_eq!(format_flo32(-4.701_977_1e-38), "-4.7019771e-38"); assert_eq!(format_flo32(1e-45), " 1e-45"); - assert_eq!(format_flo32(-3.402823466e+38), " -3.4028235e38"); + assert_eq!(format_flo32(-3.402_823_466e+38), " -3.4028235e38"); assert_eq!(format_flo32(f32::NAN), " NaN"); assert_eq!(format_flo32(f32::INFINITY), " inf"); assert_eq!(format_flo32(f32::NEG_INFINITY), " -inf"); @@ -172,13 +172,16 @@ fn test_format_flo32() { fn test_format_flo64() { assert_eq!(format_flo64(1.0), " 1.0000000000000000"); assert_eq!(format_flo64(10.0), " 10.000000000000000"); - assert_eq!(format_flo64(1000000000000000.0), " 1000000000000000.0"); assert_eq!( - format_flo64(10000000000000000.0), + format_flo64(1_000_000_000_000_000.0), + " 1000000000000000.0" + ); + assert_eq!( + format_flo64(10_000_000_000_000_000.0), " 10000000000000000" ); assert_eq!( - format_flo64(100000000000000000.0), + format_flo64(100_000_000_000_000_000.0), " 1.0000000000000000e17" ); @@ -186,7 +189,7 @@ fn test_format_flo64() { assert_eq!(format_flo64(-0.01), " -1.0000000000000000e-2"); assert_eq!( - format_flo64(-2.2250738585072014e-308), + format_flo64(-2.225_073_858_507_201_4e-308), "-2.2250738585072014e-308" ); assert_eq!(format_flo64(4e-320), " 4e-320"); diff --git a/src/uucore/src/lib/features/format/human.rs b/src/uucore/src/lib/features/format/human.rs index 28d143a42..e33b77fcd 100644 --- a/src/uucore/src/lib/features/format/human.rs +++ b/src/uucore/src/lib/features/format/human.rs @@ -54,7 +54,7 @@ pub fn human_readable(size: u64, sfmt: SizeFormat) -> String { #[test] fn test_human_readable() { let test_cases = [ - (133456345, SizeFormat::Binary, "128M"), + (133_456_345, SizeFormat::Binary, "128M"), (12 * 1024 * 1024, SizeFormat::Binary, "12M"), (8500, SizeFormat::Binary, "8.4K"), ]; diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index 034f092da..0cd5d6c13 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -560,12 +560,12 @@ mod test { assert_eq!(f(0.0), "0.000000"); assert_eq!(f(1.0), "1.000000"); assert_eq!(f(100.0), "100.000000"); - assert_eq!(f(123456.789), "123456.789000"); - assert_eq!(f(12.3456789), "12.345679"); - assert_eq!(f(1000000.0), "1000000.000000"); - assert_eq!(f(99999999.0), "99999999.000000"); - assert_eq!(f(1.9999995), "1.999999"); - assert_eq!(f(1.9999996), "2.000000"); + assert_eq!(f(123_456.789), "123456.789000"); + assert_eq!(f(12.345_678_9), "12.345679"); + assert_eq!(f(1_000_000.0), "1000000.000000"); + assert_eq!(f(99_999_999.0), "99999999.000000"); + assert_eq!(f(1.999_999_5), "1.999999"); + assert_eq!(f(1.999_999_6), "2.000000"); } #[test] @@ -575,10 +575,10 @@ mod test { assert_eq!(f(0.0), "0.000000e+00"); assert_eq!(f(1.0), "1.000000e+00"); assert_eq!(f(100.0), "1.000000e+02"); - assert_eq!(f(123456.789), "1.234568e+05"); - assert_eq!(f(12.3456789), "1.234568e+01"); - assert_eq!(f(1000000.0), "1.000000e+06"); - assert_eq!(f(99999999.0), "1.000000e+08"); + assert_eq!(f(123_456.789), "1.234568e+05"); + assert_eq!(f(12.345_678_9), "1.234568e+01"); + assert_eq!(f(1_000_000.0), "1.000000e+06"); + assert_eq!(f(99_999_999.0), "1.000000e+08"); } #[test] @@ -589,19 +589,19 @@ mod test { assert_eq!(f(0.0), "0e+00"); assert_eq!(f(1.0), "1e+00"); assert_eq!(f(100.0), "1e+02"); - assert_eq!(f(123456.789), "1e+05"); - assert_eq!(f(12.3456789), "1e+01"); - assert_eq!(f(1000000.0), "1e+06"); - assert_eq!(f(99999999.0), "1e+08"); + assert_eq!(f(123_456.789), "1e+05"); + assert_eq!(f(12.345_678_9), "1e+01"); + assert_eq!(f(1_000_000.0), "1e+06"); + assert_eq!(f(99_999_999.0), "1e+08"); let f = |x| format_float_scientific(x, 0, Case::Lowercase, ForceDecimal::Yes); assert_eq!(f(0.0), "0.e+00"); assert_eq!(f(1.0), "1.e+00"); assert_eq!(f(100.0), "1.e+02"); - assert_eq!(f(123456.789), "1.e+05"); - assert_eq!(f(12.3456789), "1.e+01"); - assert_eq!(f(1000000.0), "1.e+06"); - assert_eq!(f(99999999.0), "1.e+08"); + assert_eq!(f(123_456.789), "1.e+05"); + assert_eq!(f(12.345_678_9), "1.e+01"); + assert_eq!(f(1_000_000.0), "1.e+06"); + assert_eq!(f(99_999_999.0), "1.e+08"); } #[test] @@ -611,10 +611,10 @@ mod test { assert_eq!(f(0.0), "0"); assert_eq!(f(1.0), "1"); assert_eq!(f(100.0), "100"); - assert_eq!(f(123456.789), "123457"); - assert_eq!(f(12.3456789), "12.3457"); - assert_eq!(f(1000000.0), "1e+06"); - assert_eq!(f(99999999.0), "1e+08"); + assert_eq!(f(123_456.789), "123457"); + assert_eq!(f(12.345_678_9), "12.3457"); + assert_eq!(f(1_000_000.0), "1e+06"); + assert_eq!(f(99_999_999.0), "1e+08"); } #[test] @@ -624,10 +624,10 @@ mod test { assert_eq!(f(0.0), "0.00000"); assert_eq!(f(1.0), "1.00000"); assert_eq!(f(100.0), "100.000"); - assert_eq!(f(123456.789), "123457."); - assert_eq!(f(12.3456789), "12.3457"); - assert_eq!(f(1000000.0), "1.00000e+06"); - assert_eq!(f(99999999.0), "1.00000e+08"); + assert_eq!(f(123_456.789), "123457."); + assert_eq!(f(12.345_678_9), "12.3457"); + assert_eq!(f(1_000_000.0), "1.00000e+06"); + assert_eq!(f(99_999_999.0), "1.00000e+08"); } #[test] @@ -637,19 +637,19 @@ mod test { assert_eq!(f(0.0), "0"); assert_eq!(f(1.0), "1"); assert_eq!(f(100.0), "1e+02"); - assert_eq!(f(123456.789), "1e+05"); - assert_eq!(f(12.3456789), "1e+01"); - assert_eq!(f(1000000.0), "1e+06"); - assert_eq!(f(99999999.0), "1e+08"); + assert_eq!(f(123_456.789), "1e+05"); + assert_eq!(f(12.345_678_9), "1e+01"); + assert_eq!(f(1_000_000.0), "1e+06"); + assert_eq!(f(99_999_999.0), "1e+08"); let f = |x| format_float_shortest(x, 0, Case::Lowercase, ForceDecimal::Yes); assert_eq!(f(0.0), "0."); assert_eq!(f(1.0), "1."); assert_eq!(f(100.0), "1.e+02"); - assert_eq!(f(123456.789), "1.e+05"); - assert_eq!(f(12.3456789), "1.e+01"); - assert_eq!(f(1000000.0), "1.e+06"); - assert_eq!(f(99999999.0), "1.e+08"); + assert_eq!(f(123_456.789), "1.e+05"); + assert_eq!(f(12.345_678_9), "1.e+01"); + assert_eq!(f(1_000_000.0), "1.e+06"); + assert_eq!(f(99_999_999.0), "1.e+08"); } #[test] diff --git a/src/uucore/src/lib/features/format/num_parser.rs b/src/uucore/src/lib/features/format/num_parser.rs index e0492b258..f7a72bccd 100644 --- a/src/uucore/src/lib/features/format/num_parser.rs +++ b/src/uucore/src/lib/features/format/num_parser.rs @@ -356,7 +356,7 @@ mod tests { assert_eq!(Ok(0.5), ParsedNumber::parse_f64("0x.8")); assert_eq!(Ok(0.0625), ParsedNumber::parse_f64("0x.1")); - assert_eq!(Ok(15.0078125), ParsedNumber::parse_f64("0xf.02")); + assert_eq!(Ok(15.007_812_5), ParsedNumber::parse_f64("0xf.02")); } #[test] diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 5a6e4156d..6bf7d18f4 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -907,7 +907,7 @@ pub fn pretty_fstype<'a>(fstype: i64) -> Cow<'a, str> { 0x0187 => "autofs".into(), 0x4246_5331 => "befs".into(), 0x6264_6576 => "bdevfs".into(), - 0xCA451A4E => "bcachefs".into(), + 0xCA45_1A4E => "bcachefs".into(), 0x1BAD_FACE => "bfs".into(), 0xCAFE_4A11 => "bpf_fs".into(), 0x4249_4E4D => "binfmt_misc".into(), @@ -1037,12 +1037,12 @@ mod tests { fn test_fs_type() { // spell-checker:disable assert_eq!("ext2/ext3", pretty_fstype(0xEF53)); - assert_eq!("tmpfs", pretty_fstype(0x01021994)); + assert_eq!("tmpfs", pretty_fstype(0x0102_1994)); assert_eq!("nfs", pretty_fstype(0x6969)); - assert_eq!("btrfs", pretty_fstype(0x9123683e)); - assert_eq!("xfs", pretty_fstype(0x58465342)); - assert_eq!("zfs", pretty_fstype(0x2FC12FC1)); - assert_eq!("ntfs", pretty_fstype(0x5346544e)); + assert_eq!("btrfs", pretty_fstype(0x9123_683e)); + assert_eq!("xfs", pretty_fstype(0x5846_5342)); + assert_eq!("zfs", pretty_fstype(0x2FC1_2FC1)); + assert_eq!("ntfs", pretty_fstype(0x5346_544e)); assert_eq!("fat", pretty_fstype(0x4006)); assert_eq!("UNKNOWN (0x1234)", pretty_fstype(0x1234)); // spell-checker:enable diff --git a/src/uucore/src/lib/features/process.rs b/src/uucore/src/lib/features/process.rs index 67f2ba2ac..007e712fa 100644 --- a/src/uucore/src/lib/features/process.rs +++ b/src/uucore/src/lib/features/process.rs @@ -151,6 +151,6 @@ mod tests { assert!(getsid(getpid()).expect("getsid(getpid)") > 0); // This might caused tests failure but the probability is low. - assert!(getsid(999999).is_err()); + assert!(getsid(999_999).is_err()); } } diff --git a/src/uucore/src/lib/mods/posix.rs b/src/uucore/src/lib/mods/posix.rs index 05e928ca6..44c0d4f00 100644 --- a/src/uucore/src/lib/mods/posix.rs +++ b/src/uucore/src/lib/mods/posix.rs @@ -21,13 +21,13 @@ use std::env; /// '199209' for POSIX 1003.2-1992, which would define Obsolete mode -pub const OBSOLETE: usize = 199209; +pub const OBSOLETE: usize = 199_209; /// '200112' for POSIX 1003.1-2001, which is the minimum version for Traditional mode -pub const TRADITIONAL: usize = 200112; +pub const TRADITIONAL: usize = 200_112; /// '200809' for POSIX 1003.1-2008, which is the minimum version for Modern mode -pub const MODERN: usize = 200809; +pub const MODERN: usize = 200_809; /// Returns the value of the `_POSIX2_VERSION` environment variable if it is defined pub fn posix_version() -> Option { diff --git a/src/uucore/src/lib/parser/parse_glob.rs b/src/uucore/src/lib/parser/parse_glob.rs index 100d2edf5..08271788a 100644 --- a/src/uucore/src/lib/parser/parse_glob.rs +++ b/src/uucore/src/lib/parser/parse_glob.rs @@ -97,7 +97,7 @@ mod tests { // test that we don't look for closing square brackets unnecessarily // Verifies issue #5584 - let chars = "^[".repeat(174571); + let chars = "^[".repeat(174_571); assert_eq!(fix_negation(chars.as_str()), chars); }