mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
refactor ~ cargo make format
This commit is contained in:
@@ -153,7 +153,10 @@ fn test_format_item_hex() {
|
||||
assert_eq!(" 00000000", format_item_hex32(0));
|
||||
assert_eq!(" ffffffff", format_item_hex32(0xffff_ffff));
|
||||
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]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
//! Primitives used by num_format and sub_modules.
|
||||
//! never dealt with above (e.g. Sub Tokenizer never uses these)
|
||||
|
||||
|
||||
@@ -25,8 +25,13 @@ impl Formatter for CninetyNineHexFloatf {
|
||||
str_in: &str,
|
||||
) -> Option<FormatPrimitive> {
|
||||
let second_field = field.second_field.unwrap_or(6) + 1;
|
||||
let analysis =
|
||||
FloatAnalysis::analyze(&str_in, initial_prefix, Some(second_field as usize), None, true);
|
||||
let analysis = FloatAnalysis::analyze(
|
||||
&str_in,
|
||||
initial_prefix,
|
||||
Some(second_field as usize),
|
||||
None,
|
||||
true,
|
||||
);
|
||||
let f = get_primitive_hex(
|
||||
initial_prefix,
|
||||
&str_in[initial_prefix.offset..],
|
||||
@@ -51,7 +56,11 @@ fn get_primitive_hex(
|
||||
_last_dec_place: usize,
|
||||
capitalized: bool,
|
||||
) -> 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.
|
||||
// for hex to hex, it's really just a matter of moving the
|
||||
|
||||
@@ -76,11 +76,13 @@ impl Formatter for Decf {
|
||||
second_field as usize,
|
||||
None,
|
||||
);
|
||||
Some(if get_len_fmt_primitive(&f_fl) >= get_len_fmt_primitive(&f_sci) {
|
||||
f_sci
|
||||
} else {
|
||||
f_fl
|
||||
})
|
||||
Some(
|
||||
if get_len_fmt_primitive(&f_fl) >= get_len_fmt_primitive(&f_sci) {
|
||||
f_sci
|
||||
} else {
|
||||
f_fl
|
||||
},
|
||||
)
|
||||
}
|
||||
fn primitive_to_str(&self, prim: &FormatPrimitive, field: FormatField) -> String {
|
||||
primitive_to_str_common(prim, &field)
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// spell-checker:ignore (ToDO) arrnum
|
||||
|
||||
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::RadixDef;
|
||||
|
||||
|
||||
@@ -20,8 +20,13 @@ impl Formatter for Floatf {
|
||||
str_in: &str,
|
||||
) -> Option<FormatPrimitive> {
|
||||
let second_field = field.second_field.unwrap_or(6) + 1;
|
||||
let analysis =
|
||||
FloatAnalysis::analyze(&str_in, initial_prefix, None, Some(second_field as usize), false);
|
||||
let analysis = FloatAnalysis::analyze(
|
||||
&str_in,
|
||||
initial_prefix,
|
||||
None,
|
||||
Some(second_field as usize),
|
||||
false,
|
||||
);
|
||||
let f = get_primitive_dec(
|
||||
initial_prefix,
|
||||
&str_in[initial_prefix.offset..],
|
||||
|
||||
@@ -150,7 +150,12 @@ impl Intf {
|
||||
// - if the string falls outside bounds:
|
||||
// for i64 output, the int minimum or int max (depending on sign)
|
||||
// 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 {
|
||||
'i' | 'd' => match i64::from_str_radix(segment, radix_in as u32) {
|
||||
Ok(i) => {
|
||||
|
||||
+13
-9
@@ -475,12 +475,14 @@ impl Stater {
|
||||
let show_fs = matches.is_present(options::FILE_SYSTEM);
|
||||
|
||||
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 {
|
||||
Stater::generate_tokens(&format_str, use_printf)?
|
||||
};
|
||||
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 {
|
||||
// mount points aren't displayed when showing filesystem information
|
||||
@@ -540,12 +542,13 @@ impl Stater {
|
||||
match result {
|
||||
Ok(meta) => {
|
||||
let file_type = meta.file_type();
|
||||
let tokens =
|
||||
if self.from_user || !(file_type.is_char_device() || file_type.is_block_device()) {
|
||||
&self.default_tokens
|
||||
} else {
|
||||
&self.default_dev_tokens
|
||||
};
|
||||
let tokens = if self.from_user
|
||||
|| !(file_type.is_char_device() || file_type.is_block_device())
|
||||
{
|
||||
&self.default_tokens
|
||||
} else {
|
||||
&self.default_dev_tokens
|
||||
};
|
||||
|
||||
for t in tokens.iter() {
|
||||
match *t {
|
||||
@@ -867,7 +870,8 @@ impl Stater {
|
||||
} else {
|
||||
format_str.push_str(" File: %N\n Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n");
|
||||
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 {
|
||||
format_str.push_str("Device: %Dh/%dd\tInode: %-10i Links: %h\n");
|
||||
}
|
||||
|
||||
@@ -612,12 +612,12 @@ impl FsMeta for StatFs {
|
||||
}
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn namelen(&self) -> u64 {
|
||||
self.f_namemax as u64 // spell-checker:disable-line
|
||||
self.f_namemax as u64 // spell-checker:disable-line
|
||||
}
|
||||
// XXX: should everything just use statvfs?
|
||||
#[cfg(not(any(target_vendor = "apple", target_os = "freebsd", target_os = "linux")))]
|
||||
fn namelen(&self) -> u64 {
|
||||
self.f_namemax as u64 // spell-checker:disable-line
|
||||
self.f_namemax as u64 // spell-checker:disable-line
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ fn table(c: &mut Criterion) {
|
||||
// Deterministic RNG; use an explicitly-named RNG to guarantee stability
|
||||
use rand::{RngCore, SeedableRng};
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
const SEED: u64 = 0xdead_bebe_ea75_cafe; // spell-checker:disable-line
|
||||
const SEED: u64 = 0xdead_bebe_ea75_cafe; // spell-checker:disable-line
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
|
||||
|
||||
std::iter::repeat_with(move || array_init::<_, _, INPUT_SIZE>(|_| rng.next_u64()))
|
||||
|
||||
@@ -38,7 +38,7 @@ fn test_decode() {
|
||||
|
||||
#[test]
|
||||
fn test_garbage() {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
.pipe_in(input)
|
||||
@@ -49,7 +49,7 @@ fn test_garbage() {
|
||||
#[test]
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in &["-i", "--ignore-garbage"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
.arg(ignore_garbage_param)
|
||||
|
||||
@@ -9,7 +9,7 @@ fn test_output_simple() {
|
||||
new_ucmd!()
|
||||
.args(&["alpha.txt"])
|
||||
.succeeds()
|
||||
.stdout_only("abcde\nfghij\nklmno\npqrst\nuvwxyz\n"); // spell-checker:disable-line
|
||||
.stdout_only("abcde\nfghij\nklmno\npqrst\nuvwxyz\n"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -67,8 +67,8 @@ fn test_fifo_symlink() {
|
||||
assert!(s.fixtures.is_fifo("dir/pipe"));
|
||||
|
||||
// Make cat read the pipe through a symlink
|
||||
s.fixtures.symlink_file("dir/pipe", "sympipe"); // spell-checker:disable-line
|
||||
let proc = s.ucmd().args(&["sympipe"]).run_no_wait(); // spell-checker:disable-line
|
||||
s.fixtures.symlink_file("dir/pipe", "sympipe"); // spell-checker:disable-line
|
||||
let proc = s.ucmd().args(&["sympipe"]).run_no_wait(); // spell-checker:disable-line
|
||||
|
||||
let data = vec_of_size(128 * 1024);
|
||||
let data2 = data.clone();
|
||||
@@ -111,7 +111,7 @@ fn test_piped_to_regular_file() {
|
||||
.succeeds();
|
||||
}
|
||||
let contents = read_to_string(&file_path).unwrap();
|
||||
assert_eq!(contents, "abcde\nfghij\nklmno\npqrst\nuvwxyz\n"); // spell-checker:disable-line
|
||||
assert_eq!(contents, "abcde\nfghij\nklmno\npqrst\nuvwxyz\n"); // spell-checker:disable-line
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ fn test_three_directories_and_file_and_stdin() {
|
||||
"alpha.txt",
|
||||
"-",
|
||||
"file_which_does_not_exist.txt",
|
||||
"nonewline.txt", // spell-checker:disable-line
|
||||
"nonewline.txt", // spell-checker:disable-line
|
||||
"test_directory3/test_directory5",
|
||||
"test_directory3/../test_directory3/test_directory5",
|
||||
"test_directory3",
|
||||
@@ -202,7 +202,7 @@ fn test_three_directories_and_file_and_stdin() {
|
||||
.fails()
|
||||
.stderr_is_fixture("three_directories_and_file_and_stdin.stderr.expected")
|
||||
.stdout_is(
|
||||
"abcde\nfghij\nklmno\npqrst\nuvwxyz\nstdout bytestext without a trailing newline", // spell-checker:disable-line
|
||||
"abcde\nfghij\nklmno\npqrst\nuvwxyz\nstdout bytestext without a trailing newline", // spell-checker:disable-line
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ fn a_empty() {
|
||||
new_ucmd!()
|
||||
.args(&["a", "empty"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("aempty.expected"); // spell-checker:disable-line
|
||||
.stdout_only_fixture("aempty.expected"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -181,7 +181,7 @@ fn test_date_set_valid_2() {
|
||||
if get_effective_uid() == 0 {
|
||||
let result = new_ucmd!()
|
||||
.arg("--set")
|
||||
.arg("Sat 20 Mar 2021 14:53:01 AWST") // spell-checker:disable-line
|
||||
.arg("Sat 20 Mar 2021 14:53:01 AWST") // spell-checker:disable-line
|
||||
.fails();
|
||||
result.no_stdout();
|
||||
assert!(result.stderr_str().starts_with("date: invalid date "));
|
||||
|
||||
@@ -35,9 +35,9 @@ fn test_str_utils() {
|
||||
assert_eq!("asd#zcv", s.purify());
|
||||
|
||||
let s = "con256asd";
|
||||
assert!(s.fnmatch("*[2][3-6][5-9]?sd")); // spell-checker:disable-line
|
||||
assert!(s.fnmatch("*[2][3-6][5-9]?sd")); // spell-checker:disable-line
|
||||
|
||||
let s = "zxc \t\nqwe jlk hjl"; // spell-checker:disable-line
|
||||
let s = "zxc \t\nqwe jlk hjl"; // spell-checker:disable-line
|
||||
let (k, v) = s.split_two();
|
||||
assert_eq!("zxc", k);
|
||||
assert_eq!("qwe jlk hjl", v);
|
||||
|
||||
@@ -189,7 +189,7 @@ fn test_hyphen_values_inside_string() {
|
||||
new_ucmd!()
|
||||
.arg("'\"\n'CXXFLAGS=-g -O2'\n\"'") // spell-checker:disable-line
|
||||
.succeeds()
|
||||
.stdout_contains("CXXFLAGS"); // spell-checker:disable-line
|
||||
.stdout_contains("CXXFLAGS"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -209,7 +209,10 @@ fn test_big_primes() {
|
||||
|
||||
fn run(input_string: &[u8], output_string: &[u8]) {
|
||||
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
|
||||
new_ucmd!()
|
||||
.pipe_in(input_string)
|
||||
|
||||
@@ -282,7 +282,7 @@ fn test_backspace_is_not_word_boundary() {
|
||||
.args(&["-w10", "-s"])
|
||||
.pipe_in("foobar\x086789abcdef")
|
||||
.succeeds()
|
||||
.stdout_is("foobar\x086789a\nbcdef"); // spell-checker:disable-line
|
||||
.stdout_is("foobar\x086789a\nbcdef"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -308,9 +308,9 @@ fn test_carriage_return_should_reset_column_count() {
|
||||
fn test_carriage_return_is_not_word_boundary() {
|
||||
new_ucmd!()
|
||||
.args(&["-w6", "-s"])
|
||||
.pipe_in("fizz\rbuzz\rfizzbuzz") // spell-checker:disable-line
|
||||
.pipe_in("fizz\rbuzz\rfizzbuzz") // spell-checker:disable-line
|
||||
.succeeds()
|
||||
.stdout_is("fizz\rbuzz\rfizzbu\nzz"); // spell-checker:disable-line
|
||||
.stdout_is("fizz\rbuzz\rfizzbu\nzz"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
//
|
||||
@@ -530,7 +530,7 @@ fn test_bytewise_carriage_return_should_not_reset_column_count() {
|
||||
fn test_bytewise_carriage_return_is_not_word_boundary() {
|
||||
new_ucmd!()
|
||||
.args(&["-w6", "-s", "-b"])
|
||||
.pipe_in("fizz\rbuzz\rfizzbuzz") // spell-checker:disable-line
|
||||
.pipe_in("fizz\rbuzz\rfizzbuzz") // spell-checker:disable-line
|
||||
.succeeds()
|
||||
.stdout_is("fizz\rb\nuzz\rfi\nzzbuzz"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ fn test_kill_set_bad_signal_name() {
|
||||
// spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-s")
|
||||
.arg("IAMNOTASIGNAL") // spell-checker:disable-line
|
||||
.arg("IAMNOTASIGNAL") // spell-checker:disable-line
|
||||
.fails()
|
||||
.stderr_contains("unknown signal");
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ fn test_symlink_interactive() {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-i", "-s", file, link])
|
||||
.pipe_in("Yesh") // spell-checker:disable-line
|
||||
.pipe_in("Yesh") // spell-checker:disable-line
|
||||
.succeeds()
|
||||
.no_stderr();
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user