1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

refactor ~ cargo make format

This commit is contained in:
Roy Ivy III 2021-05-30 22:55:28 -05:00
parent c392cd1cb4
commit 3f35e0a421
36 changed files with 129 additions and 100 deletions

View file

@ -153,7 +153,10 @@ fn test_format_item_hex() {
assert_eq!(" 00000000", format_item_hex32(0)); assert_eq!(" 00000000", format_item_hex32(0));
assert_eq!(" ffffffff", format_item_hex32(0xffff_ffff)); assert_eq!(" ffffffff", format_item_hex32(0xffff_ffff));
assert_eq!(" 0000000000000000", format_item_hex64(0)); assert_eq!(" 0000000000000000", format_item_hex64(0));
assert_eq!(" ffffffffffffffff", format_item_hex64(0xffff_ffff_ffff_ffff)); assert_eq!(
" ffffffffffffffff",
format_item_hex64(0xffff_ffff_ffff_ffff)
);
} }
#[test] #[test]

View file

@ -1,4 +1,3 @@
//! Primitives used by num_format and sub_modules. //! Primitives used by num_format and sub_modules.
//! never dealt with above (e.g. Sub Tokenizer never uses these) //! never dealt with above (e.g. Sub Tokenizer never uses these)

View file

@ -25,8 +25,13 @@ impl Formatter for CninetyNineHexFloatf {
str_in: &str, str_in: &str,
) -> Option<FormatPrimitive> { ) -> Option<FormatPrimitive> {
let second_field = field.second_field.unwrap_or(6) + 1; let second_field = field.second_field.unwrap_or(6) + 1;
let analysis = let analysis = FloatAnalysis::analyze(
FloatAnalysis::analyze(&str_in, initial_prefix, Some(second_field as usize), None, true); &str_in,
initial_prefix,
Some(second_field as usize),
None,
true,
);
let f = get_primitive_hex( let f = get_primitive_hex(
initial_prefix, initial_prefix,
&str_in[initial_prefix.offset..], &str_in[initial_prefix.offset..],
@ -51,7 +56,11 @@ fn get_primitive_hex(
_last_dec_place: usize, _last_dec_place: usize,
capitalized: bool, capitalized: bool,
) -> FormatPrimitive { ) -> FormatPrimitive {
let prefix = Some(String::from(if initial_prefix.sign == -1 { "-0x" } else { "0x" })); let prefix = Some(String::from(if initial_prefix.sign == -1 {
"-0x"
} else {
"0x"
}));
// TODO actual conversion, make sure to get back mantissa. // TODO actual conversion, make sure to get back mantissa.
// for hex to hex, it's really just a matter of moving the // for hex to hex, it's really just a matter of moving the

View file

@ -76,11 +76,13 @@ impl Formatter for Decf {
second_field as usize, second_field as usize,
None, None,
); );
Some(if get_len_fmt_primitive(&f_fl) >= get_len_fmt_primitive(&f_sci) { Some(
if get_len_fmt_primitive(&f_fl) >= get_len_fmt_primitive(&f_sci) {
f_sci f_sci
} else { } else {
f_fl f_fl
}) },
)
} }
fn primitive_to_str(&self, prim: &FormatPrimitive, field: FormatField) -> String { fn primitive_to_str(&self, prim: &FormatPrimitive, field: FormatField) -> String {
primitive_to_str_common(prim, &field) primitive_to_str_common(prim, &field)

View file

@ -2,7 +2,9 @@
// spell-checker:ignore (ToDO) arrnum // spell-checker:ignore (ToDO) arrnum
use super::super::format_field::FormatField; use super::super::format_field::FormatField;
use super::super::formatter::{get_it_at, warn_incomplete_conv, Base, FormatPrimitive, InitialPrefix}; use super::super::formatter::{
get_it_at, warn_incomplete_conv, Base, FormatPrimitive, InitialPrefix,
};
use super::base_conv; use super::base_conv;
use super::base_conv::RadixDef; use super::base_conv::RadixDef;

View file

@ -20,8 +20,13 @@ impl Formatter for Floatf {
str_in: &str, str_in: &str,
) -> Option<FormatPrimitive> { ) -> Option<FormatPrimitive> {
let second_field = field.second_field.unwrap_or(6) + 1; let second_field = field.second_field.unwrap_or(6) + 1;
let analysis = let analysis = FloatAnalysis::analyze(
FloatAnalysis::analyze(&str_in, initial_prefix, None, Some(second_field as usize), false); &str_in,
initial_prefix,
None,
Some(second_field as usize),
false,
);
let f = get_primitive_dec( let f = get_primitive_dec(
initial_prefix, initial_prefix,
&str_in[initial_prefix.offset..], &str_in[initial_prefix.offset..],

View file

@ -150,7 +150,12 @@ impl Intf {
// - if the string falls outside bounds: // - if the string falls outside bounds:
// for i64 output, the int minimum or int max (depending on sign) // for i64 output, the int minimum or int max (depending on sign)
// for u64 output, the u64 max in the output radix // for u64 output, the u64 max in the output radix
fn conv_from_segment(segment: &str, radix_in: Base, field_char: char, sign: i8) -> FormatPrimitive { fn conv_from_segment(
segment: &str,
radix_in: Base,
field_char: char,
sign: i8,
) -> FormatPrimitive {
match field_char { match field_char {
'i' | 'd' => match i64::from_str_radix(segment, radix_in as u32) { 'i' | 'd' => match i64::from_str_radix(segment, radix_in as u32) {
Ok(i) => { Ok(i) => {

View file

@ -475,12 +475,14 @@ impl Stater {
let show_fs = matches.is_present(options::FILE_SYSTEM); let show_fs = matches.is_present(options::FILE_SYSTEM);
let default_tokens = if format_str.is_empty() { let default_tokens = if format_str.is_empty() {
Stater::generate_tokens(&Stater::default_format(show_fs, terse, false), use_printf).unwrap() Stater::generate_tokens(&Stater::default_format(show_fs, terse, false), use_printf)
.unwrap()
} else { } else {
Stater::generate_tokens(&format_str, use_printf)? Stater::generate_tokens(&format_str, use_printf)?
}; };
let default_dev_tokens = let default_dev_tokens =
Stater::generate_tokens(&Stater::default_format(show_fs, terse, true), use_printf).unwrap(); Stater::generate_tokens(&Stater::default_format(show_fs, terse, true), use_printf)
.unwrap();
let mount_list = if show_fs { let mount_list = if show_fs {
// mount points aren't displayed when showing filesystem information // mount points aren't displayed when showing filesystem information
@ -540,8 +542,9 @@ impl Stater {
match result { match result {
Ok(meta) => { Ok(meta) => {
let file_type = meta.file_type(); let file_type = meta.file_type();
let tokens = let tokens = if self.from_user
if self.from_user || !(file_type.is_char_device() || file_type.is_block_device()) { || !(file_type.is_char_device() || file_type.is_block_device())
{
&self.default_tokens &self.default_tokens
} else { } else {
&self.default_dev_tokens &self.default_dev_tokens
@ -867,7 +870,8 @@ impl Stater {
} else { } else {
format_str.push_str(" File: %N\n Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"); format_str.push_str(" File: %N\n Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n");
if show_dev_type { if show_dev_type {
format_str.push_str("Device: %Dh/%dd\tInode: %-10i Links: %-5h Device type: %t,%T\n"); format_str
.push_str("Device: %Dh/%dd\tInode: %-10i Links: %-5h Device type: %t,%T\n");
} else { } else {
format_str.push_str("Device: %Dh/%dd\tInode: %-10i Links: %h\n"); format_str.push_str("Device: %Dh/%dd\tInode: %-10i Links: %h\n");
} }

View file

@ -209,7 +209,10 @@ fn test_big_primes() {
fn run(input_string: &[u8], output_string: &[u8]) { fn run(input_string: &[u8], output_string: &[u8]) {
println!("STDIN='{}'", String::from_utf8_lossy(input_string)); println!("STDIN='{}'", String::from_utf8_lossy(input_string));
println!("STDOUT(expected)='{}'", String::from_utf8_lossy(output_string)); println!(
"STDOUT(expected)='{}'",
String::from_utf8_lossy(output_string)
);
// now run factor // now run factor
new_ucmd!() new_ucmd!()
.pipe_in(input_string) .pipe_in(input_string)

View file

@ -5,7 +5,8 @@ fn test_more_no_arg() {
// Reading from stdin is now supported, so this must succeed // Reading from stdin is now supported, so this must succeed
if atty::is(atty::Stream::Stdout) { if atty::is(atty::Stream::Stdout) {
new_ucmd!().succeeds(); new_ucmd!().succeeds();
} else {} } else {
}
} }
#[test] #[test]
@ -19,5 +20,6 @@ fn test_more_dir_arg() {
const EXPECTED_ERROR_MESSAGE: &str = const EXPECTED_ERROR_MESSAGE: &str =
"more: '.' is a directory.\nTry 'more --help' for more information."; "more: '.' is a directory.\nTry 'more --help' for more information.";
assert_eq!(result.stderr_str().trim(), EXPECTED_ERROR_MESSAGE); assert_eq!(result.stderr_str().trim(), EXPECTED_ERROR_MESSAGE);
} else {} } else {
}
} }

View file

@ -47,12 +47,7 @@ fn test_reference() {
scene.ucmd().arg("-s").arg("+5KB").arg(FILE1).run(); scene.ucmd().arg("-s").arg("+5KB").arg(FILE1).run();
scene scene.ucmd().arg("--reference").arg(FILE1).arg(FILE2).run();
.ucmd()
.arg("--reference")
.arg(FILE1)
.arg(FILE2)
.run();
file.seek(SeekFrom::End(0)).unwrap(); file.seek(SeekFrom::End(0)).unwrap();
let actual = file.seek(SeekFrom::Current(0)).unwrap(); let actual = file.seek(SeekFrom::Current(0)).unwrap();