Merge pull request #2963 from danieleades/refactor/code-quality

Refactor/code quality
This commit is contained in:
Sylvestre Ledru
2022-01-30 18:26:16 +01:00
committed by GitHub
150 changed files with 941 additions and 972 deletions
+5 -5
View File
@@ -67,7 +67,7 @@ pub fn main() {
)
.as_bytes(),
)
.unwrap()
.unwrap();
}
k if k.starts_with(OVERRIDE_PREFIX) => {
phf_map.entry(&k[OVERRIDE_PREFIX.len()..], &map_value);
@@ -79,7 +79,7 @@ pub fn main() {
)
.as_bytes(),
)
.unwrap()
.unwrap();
}
"false" | "true" => {
phf_map.entry(
@@ -94,7 +94,7 @@ pub fn main() {
)
.as_bytes(),
)
.unwrap()
.unwrap();
}
"hashsum" => {
phf_map.entry(
@@ -124,7 +124,7 @@ pub fn main() {
)
.as_bytes(),
)
.unwrap()
.unwrap();
}
_ => {
phf_map.entry(krate, &map_value);
@@ -136,7 +136,7 @@ pub fn main() {
)
.as_bytes(),
)
.unwrap()
.unwrap();
}
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ fn main() {
// * prefix/stem may be any string ending in a non-alphanumeric character
let util_name = if let Some(util) = utils.keys().find(|util| {
binary_as_util.ends_with(*util)
&& !(&binary_as_util[..binary_as_util.len() - (*util).len()])
&& !binary_as_util[..binary_as_util.len() - (*util).len()]
.ends_with(char::is_alphanumeric)
}) {
// prefixed util => replace 0th (aka, executable name) argument
+1 -1
View File
@@ -44,7 +44,7 @@ fn main() -> io::Result<()> {
} else {
println!("Error writing to {}", p);
}
writeln!(summary, "* [{0}](utils/{0}.md)", name)?
writeln!(summary, "* [{0}](utils/{0}.md)", name)?;
}
Ok(())
}
+3 -3
View File
@@ -38,7 +38,7 @@ pub mod options {
}
impl Config {
pub fn from(options: &clap::ArgMatches) -> UResult<Config> {
pub fn from(options: &clap::ArgMatches) -> UResult<Self> {
let file: Option<String> = match options.values_of(options::FILE) {
Some(mut values) => {
let name = values.next().unwrap();
@@ -76,7 +76,7 @@ impl Config {
})
.transpose()?;
Ok(Config {
Ok(Self {
decode: options.is_present(options::DECODE),
ignore_garbage: options.is_present(options::IGNORE_GARBAGE),
wrap_cols: cols,
@@ -153,7 +153,7 @@ pub fn handle_input<R: Read>(
if !decode {
match data.encode() {
Ok(s) => {
wrap_print(&data, s);
wrap_print(&data, &s);
Ok(())
}
Err(_) => Err(USimpleError::new(
+5 -5
View File
@@ -236,7 +236,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
show_tabs,
squeeze_blank,
};
cat_files(files, &options)
cat_files(&files, &options)
}
pub fn uu_app<'a>() -> App<'a> {
@@ -365,7 +365,7 @@ fn cat_path(
}
}
fn cat_files(files: Vec<String>, options: &OutputOptions) -> UResult<()> {
fn cat_files(files: &[String], options: &OutputOptions) -> UResult<()> {
let out_info = FileInformation::from_file(&std::io::stdout());
let mut state = OutputState {
@@ -376,7 +376,7 @@ fn cat_files(files: Vec<String>, options: &OutputOptions) -> UResult<()> {
};
let mut error_messages: Vec<String> = Vec::new();
for path in &files {
for path in files {
if let Err(err) = cat_path(path, options, &mut state, out_info.as_ref()) {
error_messages.push(format!("{}: {}", path.maybe_quote(), err));
}
@@ -479,7 +479,7 @@ fn write_lines<R: FdReadable>(
if !state.at_line_start || !options.squeeze_blank || !state.one_blank_kept {
state.one_blank_kept = true;
if state.at_line_start && options.number == NumberingMode::All {
write!(&mut writer, "{0:6}\t", state.line_number)?;
write!(writer, "{0:6}\t", state.line_number)?;
state.line_number += 1;
}
writer.write_all(options.end_of_line().as_bytes())?;
@@ -498,7 +498,7 @@ fn write_lines<R: FdReadable>(
}
state.one_blank_kept = false;
if state.at_line_start && options.number != NumberingMode::None {
write!(&mut writer, "{0:6}\t", state.line_number)?;
write!(writer, "{0:6}\t", state.line_number)?;
state.line_number += 1;
}
+1 -1
View File
@@ -743,7 +743,7 @@ This almost certainly means that you have a corrupted file system.\n\
NOTIFY YOUR SYSTEM MANAGER.\n\
The following directory is part of the cycle {}.",
file_name.quote()
)
);
}
#[derive(Debug)]
+2 -2
View File
@@ -64,10 +64,10 @@ impl Error {
pub(crate) fn report_full_error(mut err: &dyn std::error::Error) -> String {
let mut desc = String::with_capacity(256);
write!(&mut desc, "{}", err).unwrap();
write!(desc, "{}", err).unwrap();
while let Some(source) = err.source() {
err = source;
write!(&mut desc, ". {}", err).unwrap();
write!(desc, ". {}", err).unwrap();
}
desc
}
+3 -3
View File
@@ -118,7 +118,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
cmode,
};
chmoder.chmod(files)
chmoder.chmod(&files)
}
pub fn uu_app<'a>() -> App<'a> {
@@ -193,10 +193,10 @@ struct Chmoder {
}
impl Chmoder {
fn chmod(&self, files: Vec<String>) -> UResult<()> {
fn chmod(&self, files: &[String]) -> UResult<()> {
let mut r = Ok(());
for filename in &files {
for filename in files {
let filename = &filename[..];
let file = Path::new(filename);
if !file.exists() {
+35 -35
View File
@@ -495,43 +495,43 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
impl ClobberMode {
fn from_matches(matches: &ArgMatches) -> ClobberMode {
fn from_matches(matches: &ArgMatches) -> Self {
if matches.is_present(options::FORCE) {
ClobberMode::Force
Self::Force
} else if matches.is_present(options::REMOVE_DESTINATION) {
ClobberMode::RemoveDestination
Self::RemoveDestination
} else {
ClobberMode::Standard
Self::Standard
}
}
}
impl OverwriteMode {
fn from_matches(matches: &ArgMatches) -> OverwriteMode {
fn from_matches(matches: &ArgMatches) -> Self {
if matches.is_present(options::INTERACTIVE) {
OverwriteMode::Interactive(ClobberMode::from_matches(matches))
Self::Interactive(ClobberMode::from_matches(matches))
} else if matches.is_present(options::NO_CLOBBER) {
OverwriteMode::NoClobber
Self::NoClobber
} else {
OverwriteMode::Clobber(ClobberMode::from_matches(matches))
Self::Clobber(ClobberMode::from_matches(matches))
}
}
}
impl CopyMode {
fn from_matches(matches: &ArgMatches) -> CopyMode {
fn from_matches(matches: &ArgMatches) -> Self {
if matches.is_present(options::LINK) {
CopyMode::Link
Self::Link
} else if matches.is_present(options::SYMBOLIC_LINK) {
CopyMode::SymLink
Self::SymLink
} else if matches.is_present(options::SPARSE) {
CopyMode::Sparse
Self::Sparse
} else if matches.is_present(options::UPDATE) {
CopyMode::Update
Self::Update
} else if matches.is_present(options::ATTRIBUTES_ONLY) {
CopyMode::AttrOnly
Self::AttrOnly
} else {
CopyMode::Copy
Self::Copy
}
}
}
@@ -539,16 +539,16 @@ impl CopyMode {
impl FromStr for Attribute {
type Err = Error;
fn from_str(value: &str) -> CopyResult<Attribute> {
fn from_str(value: &str) -> CopyResult<Self> {
Ok(match &*value.to_lowercase() {
"mode" => Attribute::Mode,
"mode" => Self::Mode,
#[cfg(unix)]
"ownership" => Attribute::Ownership,
"timestamps" => Attribute::Timestamps,
"ownership" => Self::Ownership,
"timestamps" => Self::Timestamps,
#[cfg(feature = "feat_selinux")]
"context" => Attribute::Context,
"links" => Attribute::Links,
"xattr" => Attribute::Xattr,
"context" => Self::Context,
"links" => Self::Links,
"xattr" => Self::Xattr,
_ => {
return Err(Error::InvalidArgument(format!(
"invalid attribute {}",
@@ -577,7 +577,7 @@ fn add_all_attributes() -> Vec<Attribute> {
}
impl Options {
fn from_matches(matches: &ArgMatches) -> CopyResult<Options> {
fn from_matches(matches: &ArgMatches) -> CopyResult<Self> {
let not_implemented_opts = vec![
options::COPY_CONTENTS,
options::SPARSE,
@@ -646,7 +646,7 @@ impl Options {
// if not executed first.
preserve_attributes.sort_unstable();
let options = Options {
let options = Self {
attributes_only: matches.is_present(options::ATTRIBUTES_ONLY),
copy_contents: matches.is_present(options::COPY_CONTENTS),
copy_mode: CopyMode::from_matches(matches),
@@ -703,11 +703,11 @@ impl TargetType {
///
/// Treat target as a dir if we have multiple sources or the target
/// exists and already is a directory
fn determine(sources: &[Source], target: &TargetSlice) -> TargetType {
fn determine(sources: &[Source], target: &TargetSlice) -> Self {
if sources.len() > 1 || target.is_dir() {
TargetType::Directory
Self::Directory
} else {
TargetType::File
Self::File
}
}
}
@@ -741,8 +741,8 @@ fn parse_path_args(path_args: &[String], options: &Options) -> CopyResult<(Vec<S
};
if options.strip_trailing_slashes {
for source in paths.iter_mut() {
*source = source.components().as_path().to_owned()
for source in &mut paths {
*source = source.components().as_path().to_owned();
}
}
@@ -752,7 +752,7 @@ fn parse_path_args(path_args: &[String], options: &Options) -> CopyResult<(Vec<S
fn preserve_hardlinks(
hard_links: &mut Vec<(String, u64)>,
source: &std::path::Path,
dest: std::path::PathBuf,
dest: &std::path::Path,
found_hard_link: &mut bool,
) -> CopyResult<()> {
// Redox does not currently support hard links
@@ -805,7 +805,7 @@ fn preserve_hardlinks(
for hard_link in hard_links.iter() {
if hard_link.1 == inode {
std::fs::hard_link(hard_link.0.clone(), dest.clone()).unwrap();
std::fs::hard_link(hard_link.0.clone(), dest).unwrap();
*found_hard_link = true;
}
}
@@ -849,7 +849,7 @@ fn copy(sources: &[Source], target: &TargetSlice, options: &Options) -> CopyResu
let mut found_hard_link = false;
if preserve_hard_links {
let dest = construct_dest_path(source, target, &target_type, options)?;
preserve_hardlinks(&mut hard_links, source, dest, &mut found_hard_link)?;
preserve_hardlinks(&mut hard_links, source, &dest, &mut found_hard_link)?;
}
if !found_hard_link {
if let Err(error) =
@@ -864,7 +864,7 @@ fn copy(sources: &[Source], target: &TargetSlice, options: &Options) -> CopyResu
}
_ => {
show_error!("{}", error);
non_fatal_errors = true
non_fatal_errors = true;
}
}
}
@@ -1031,7 +1031,7 @@ fn copy_directory(
let mut found_hard_link = false;
let source = path.to_path_buf();
let dest = local_to_target.as_path().to_path_buf();
preserve_hardlinks(&mut hard_links, &source, dest, &mut found_hard_link)?;
preserve_hardlinks(&mut hard_links, &source, &dest, &mut found_hard_link)?;
if !found_hard_link {
match copy_file(
path.as_path(),
@@ -1580,5 +1580,5 @@ fn test_cp_localize_to_target() {
)
.unwrap()
== Path::new("target/c.txt")
)
);
}
+15 -15
View File
@@ -57,13 +57,13 @@ pub struct CsplitOptions {
}
impl CsplitOptions {
fn new(matches: &ArgMatches) -> CsplitOptions {
fn new(matches: &ArgMatches) -> Self {
let keep_files = matches.is_present(options::KEEP_FILES);
let quiet = matches.is_present(options::QUIET);
let elide_empty_files = matches.is_present(options::ELIDE_EMPTY_FILES);
let suppress_matched = matches.is_present(options::SUPPRESS_MATCHED);
CsplitOptions {
Self {
split_name: crash_if_err!(
1,
SplitName::new(
@@ -108,9 +108,9 @@ where
input_iter.rewind_buffer();
if let Some((_, line)) = input_iter.next() {
split_writer.new_writer()?;
split_writer.writeln(line?)?;
split_writer.writeln(&line?)?;
for (_, line) in input_iter {
split_writer.writeln(line?)?;
split_writer.writeln(&line?)?;
}
split_writer.finish_split();
}
@@ -250,7 +250,7 @@ impl<'a> SplitWriter<'a> {
/// # Errors
///
/// Some [`io::Error`] may occur when attempting to write the line.
fn writeln(&mut self, line: String) -> io::Result<()> {
fn writeln(&mut self, line: &str) -> io::Result<()> {
if !self.dev_null {
match self.current_writer {
Some(ref mut current_writer) => {
@@ -343,7 +343,7 @@ impl<'a> SplitWriter<'a> {
}
Ordering::Greater => (),
}
self.writeln(l)?;
self.writeln(&l)?;
}
self.finish_split();
ret
@@ -373,7 +373,7 @@ impl<'a> SplitWriter<'a> {
// The offset is zero or positive, no need for a buffer on the lines read.
// NOTE: drain the buffer of input_iter, no match should be done within.
for line in input_iter.drain_buffer() {
self.writeln(line)?;
self.writeln(&line)?;
}
// retain the matching line
input_iter.set_size_of_buffer(1);
@@ -390,7 +390,7 @@ impl<'a> SplitWriter<'a> {
);
}
// a positive offset, some more lines need to be added to the current split
(false, _) => self.writeln(l)?,
(false, _) => self.writeln(&l)?,
_ => (),
};
offset -= 1;
@@ -399,7 +399,7 @@ impl<'a> SplitWriter<'a> {
while offset > 0 {
match input_iter.next() {
Some((_, line)) => {
self.writeln(line?)?;
self.writeln(&line?)?;
}
None => {
self.finish_split();
@@ -413,7 +413,7 @@ impl<'a> SplitWriter<'a> {
self.finish_split();
return Ok(());
}
self.writeln(l)?;
self.writeln(&l)?;
}
} else {
// With a negative offset we use a buffer to keep the lines within the offset.
@@ -427,7 +427,7 @@ impl<'a> SplitWriter<'a> {
let l = line?;
if regex.is_match(&l) {
for line in input_iter.shrink_buffer_to_size() {
self.writeln(line)?;
self.writeln(&line)?;
}
if !self.options.suppress_matched {
// add 1 to the buffer size to make place for the matched line
@@ -444,12 +444,12 @@ impl<'a> SplitWriter<'a> {
return Ok(());
}
if let Some(line) = input_iter.add_line_to_buffer(ln, l) {
self.writeln(line)?;
self.writeln(&line)?;
}
}
// no match, drain the buffer into the current split
for line in input_iter.drain_buffer() {
self.writeln(line)?;
self.writeln(&line)?;
}
}
@@ -477,8 +477,8 @@ impl<I> InputSplitter<I>
where
I: Iterator<Item = (usize, io::Result<String>)>,
{
fn new(iter: I) -> InputSplitter<I> {
InputSplitter {
fn new(iter: I) -> Self {
Self {
iter,
buffer: Vec::new(),
rewind: false,
+1 -1
View File
@@ -35,7 +35,7 @@ pub enum CsplitError {
impl From<io::Error> for CsplitError {
fn from(error: io::Error) -> Self {
CsplitError::IoError(error)
Self::IoError(error)
}
}
+4 -4
View File
@@ -44,8 +44,8 @@ pub enum ExecutePattern {
impl ExecutePattern {
pub fn iter(&self) -> ExecutePatternIter {
match self {
ExecutePattern::Times(n) => ExecutePatternIter::new(Some(*n)),
ExecutePattern::Always => ExecutePatternIter::new(None),
Self::Times(n) => ExecutePatternIter::new(Some(*n)),
Self::Always => ExecutePatternIter::new(None),
}
}
}
@@ -56,8 +56,8 @@ pub struct ExecutePatternIter {
}
impl ExecutePatternIter {
fn new(max: Option<usize>) -> ExecutePatternIter {
ExecutePatternIter { max, cur: 0 }
fn new(max: Option<usize>) -> Self {
Self { max, cur: 0 }
}
}
+2 -2
View File
@@ -29,7 +29,7 @@ impl SplitName {
prefix_opt: Option<String>,
format_opt: Option<String>,
n_digits_opt: Option<String>,
) -> Result<SplitName, CsplitError> {
) -> Result<Self, CsplitError> {
// get the prefix
let prefix = prefix_opt.unwrap_or_else(|| "xx".to_string());
// the width for the split offset
@@ -231,7 +231,7 @@ impl SplitName {
}
};
Ok(SplitName { fn_split_name })
Ok(Self { fn_split_name })
}
/// Returns the filename of the i-th split.
+2 -2
View File
@@ -340,7 +340,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> URes
Ok(())
}
fn cut_files(mut filenames: Vec<String>, mode: Mode) -> UResult<()> {
fn cut_files(mut filenames: Vec<String>, mode: &Mode) -> UResult<()> {
let mut stdin_read = false;
if filenames.is_empty() {
@@ -527,7 +527,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect();
match mode_parse {
Ok(mode) => cut_files(files, mode),
Ok(mode) => cut_files(files, &mode),
Err(e) => Err(USimpleError::new(1, e)),
}
}
+6 -6
View File
@@ -72,7 +72,7 @@ mod tests {
assert_eq!(vec![] as Vec<usize>, items);
}
fn test_multibyte(line: &[u8], expected: Vec<usize>) {
fn test_multibyte(line: &[u8], expected: &[usize]) {
let iter = Searcher::new(line, NEEDLE);
let items: Vec<usize> = iter.collect();
assert_eq!(expected, items);
@@ -80,26 +80,26 @@ mod tests {
#[test]
fn test_multibyte_normal() {
test_multibyte("...ab...ab...".as_bytes(), vec![3, 8]);
test_multibyte("...ab...ab...".as_bytes(), &[3, 8]);
}
#[test]
fn test_multibyte_needle_head_at_end() {
test_multibyte("a".as_bytes(), vec![]);
test_multibyte("a".as_bytes(), &[]);
}
#[test]
fn test_multibyte_starting_needle() {
test_multibyte("ab...ab...".as_bytes(), vec![0, 5]);
test_multibyte("ab...ab...".as_bytes(), &[0, 5]);
}
#[test]
fn test_multibyte_trailing_needle() {
test_multibyte("...ab...ab".as_bytes(), vec![3, 8]);
test_multibyte("...ab...ab".as_bytes(), &[3, 8]);
}
#[test]
fn test_multibyte_first_byte_false_match() {
test_multibyte("aA..aCaC..ab..aD".as_bytes(), vec![10]);
test_multibyte("aA..aCaC..ab..aD".as_bytes(), &[10]);
}
}
+8 -8
View File
@@ -111,11 +111,11 @@ enum Iso8601Format {
impl<'a> From<&'a str> for Iso8601Format {
fn from(s: &str) -> Self {
match s {
HOURS | HOUR => Iso8601Format::Hours,
MINUTES | MINUTE => Iso8601Format::Minutes,
SECONDS | SECOND => Iso8601Format::Seconds,
NS => Iso8601Format::Ns,
DATE => Iso8601Format::Date,
HOURS | HOUR => Self::Hours,
MINUTES | MINUTE => Self::Minutes,
SECONDS | SECOND => Self::Seconds,
NS => Self::Ns,
DATE => Self::Date,
// Should be caught by clap
_ => panic!("Invalid format: {}", s),
}
@@ -131,9 +131,9 @@ enum Rfc3339Format {
impl<'a> From<&'a str> for Rfc3339Format {
fn from(s: &str) -> Self {
match s {
DATE => Rfc3339Format::Date,
SECONDS | SECOND => Rfc3339Format::Seconds,
NS => Rfc3339Format::Ns,
DATE => Self::Date,
SECONDS | SECOND => Self::Seconds,
NS => Self::Ns,
// Should be caught by clap
_ => panic!("Invalid format: {}", s),
}
+13 -13
View File
@@ -69,7 +69,7 @@ impl Input<io::Stdin> {
let skip = parseargs::parse_skip_amt(&ibs, &iflags, matches)?;
let count = parseargs::parse_count(&iflags, matches)?;
let mut i = Input {
let mut i = Self {
src: io::stdin(),
non_ascii,
ibs,
@@ -157,7 +157,7 @@ impl Input<File> {
.map_err_context(|| "failed to seek in input file".to_string())?;
}
let i = Input {
let i = Self {
src,
non_ascii,
ibs,
@@ -306,7 +306,7 @@ impl OutputTrait for Output<io::Stdout> {
.map_err_context(|| String::from("write error"))?;
}
Ok(Output { dst, obs, cflags })
Ok(Self { dst, obs, cflags })
}
fn fsync(&mut self) -> io::Result<()> {
@@ -322,7 +322,7 @@ impl<W: Write> Output<W>
where
Self: OutputTrait,
{
fn write_blocks(&mut self, buf: Vec<u8>) -> io::Result<WriteStat> {
fn write_blocks(&mut self, buf: &[u8]) -> io::Result<WriteStat> {
let mut writes_complete = 0;
let mut writes_partial = 0;
let mut bytes_total = 0;
@@ -381,7 +381,7 @@ where
) => break,
(rstat_update, buf) => {
let wstat_update = self
.write_blocks(buf)
.write_blocks(&buf)
.map_err_context(|| "failed to write output".to_string())?;
rstat += rstat_update;
@@ -497,7 +497,7 @@ impl OutputTrait for Output<File> {
.map_err_context(|| "failed to seek in output file".to_string())?;
}
Ok(Output { dst, obs, cflags })
Ok(Self { dst, obs, cflags })
} else {
// The following error should only occur if someone
// mistakenly calls Output::<File>::new() without checking
@@ -560,7 +560,7 @@ impl Write for Output<io::Stdout> {
/// Splits the content of buf into cbs-length blocks
/// Appends padding as specified by conv=block and cbs=N
/// Expects ascii encoded data
fn block(buf: Vec<u8>, cbs: usize, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
fn block(buf: &[u8], cbs: usize, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
let mut blocks = buf
.split(|&e| e == NEWLINE)
.map(|split| split.to_vec())
@@ -586,7 +586,7 @@ fn block(buf: Vec<u8>, cbs: usize, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
/// Trims padding from each cbs-length partition of buf
/// as specified by conv=unblock and cbs=N
/// Expects ascii encoded data
fn unblock(buf: Vec<u8>, cbs: usize) -> Vec<u8> {
fn unblock(buf: &[u8], cbs: usize) -> Vec<u8> {
buf.chunks(cbs).fold(Vec::new(), |mut acc, block| {
if let Some(last_char_idx) = block.iter().rposition(|&e| e != SPACE) {
// Include text up to last space.
@@ -643,10 +643,10 @@ fn conv_block_unblock_helper<R: Read>(
// ascii input so perform the block first
let cbs = i.cflags.block.unwrap();
let mut blocks = block(buf, cbs, rstat);
let mut blocks = block(&buf, cbs, rstat);
if let Some(ct) = i.cflags.ctable {
for buf in blocks.iter_mut() {
for buf in &mut blocks {
apply_conversion(buf, ct);
}
}
@@ -662,14 +662,14 @@ fn conv_block_unblock_helper<R: Read>(
apply_conversion(&mut buf, ct);
}
let blocks = block(buf, cbs, rstat).into_iter().flatten().collect();
let blocks = block(&buf, cbs, rstat).into_iter().flatten().collect();
Ok(blocks)
} else if should_unblock_then_conv(i) {
// ascii input so perform the unblock first
let cbs = i.cflags.unblock.unwrap();
let mut buf = unblock(buf, cbs);
let mut buf = unblock(&buf, cbs);
if let Some(ct) = i.cflags.ctable {
apply_conversion(&mut buf, ct);
@@ -684,7 +684,7 @@ fn conv_block_unblock_helper<R: Read>(
apply_conversion(&mut buf, ct);
}
let buf = unblock(buf, cbs);
let buf = unblock(&buf, cbs);
Ok(buf)
} else {
@@ -63,8 +63,8 @@ macro_rules! make_unblock_test (
#[test]
fn block_test_no_nl() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, 3u8];
let res = block(buf, 4, &mut rs);
let buf = [0u8, 1u8, 2u8, 3u8];
let res = block(&buf, 4, &mut rs);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
}
@@ -72,8 +72,8 @@ fn block_test_no_nl() {
#[test]
fn block_test_no_nl_short_record() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, 3u8];
let res = block(buf, 8, &mut rs);
let buf = [0u8, 1u8, 2u8, 3u8];
let res = block(&buf, 8, &mut rs);
assert_eq!(
res,
@@ -84,8 +84,8 @@ fn block_test_no_nl_short_record() {
#[test]
fn block_test_no_nl_trunc() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8];
let res = block(buf, 4, &mut rs);
let buf = [0u8, 1u8, 2u8, 3u8, 4u8];
let res = block(&buf, 4, &mut rs);
// Commented section(s) should be truncated and appear for reference only.
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8 /*, 4u8*/],]);
@@ -95,10 +95,10 @@ fn block_test_no_nl_trunc() {
#[test]
fn block_test_nl_gt_cbs_trunc() {
let mut rs = ReadStat::default();
let buf = vec![
let buf = [
0u8, 1u8, 2u8, 3u8, 4u8, NEWLINE, 0u8, 1u8, 2u8, 3u8, 4u8, NEWLINE, 5u8, 6u8, 7u8, 8u8,
];
let res = block(buf, 4, &mut rs);
let res = block(&buf, 4, &mut rs);
assert_eq!(
res,
@@ -117,8 +117,8 @@ fn block_test_nl_gt_cbs_trunc() {
#[test]
fn block_test_surrounded_nl() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, 5u8, 6u8, 7u8, 8u8];
let res = block(buf, 8, &mut rs);
let buf = [0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, 5u8, 6u8, 7u8, 8u8];
let res = block(&buf, 8, &mut rs);
assert_eq!(
res,
@@ -132,10 +132,10 @@ fn block_test_surrounded_nl() {
#[test]
fn block_test_multiple_nl_same_cbs_block() {
let mut rs = ReadStat::default();
let buf = vec![
let buf = [
0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, NEWLINE, 5u8, 6u8, 7u8, 8u8, 9u8,
];
let res = block(buf, 8, &mut rs);
let res = block(&buf, 8, &mut rs);
assert_eq!(
res,
@@ -150,10 +150,10 @@ fn block_test_multiple_nl_same_cbs_block() {
#[test]
fn block_test_multiple_nl_diff_cbs_block() {
let mut rs = ReadStat::default();
let buf = vec![
let buf = [
0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, 5u8, 6u8, 7u8, NEWLINE, 8u8, 9u8,
];
let res = block(buf, 8, &mut rs);
let res = block(&buf, 8, &mut rs);
assert_eq!(
res,
@@ -168,8 +168,8 @@ fn block_test_multiple_nl_diff_cbs_block() {
#[test]
fn block_test_end_nl_diff_cbs_block() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, 3u8, NEWLINE];
let res = block(buf, 4, &mut rs);
let buf = [0u8, 1u8, 2u8, 3u8, NEWLINE];
let res = block(&buf, 4, &mut rs);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
}
@@ -177,8 +177,8 @@ fn block_test_end_nl_diff_cbs_block() {
#[test]
fn block_test_end_nl_same_cbs_block() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, NEWLINE];
let res = block(buf, 4, &mut rs);
let buf = [0u8, 1u8, 2u8, NEWLINE];
let res = block(&buf, 4, &mut rs);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, SPACE]]);
}
@@ -186,8 +186,8 @@ fn block_test_end_nl_same_cbs_block() {
#[test]
fn block_test_double_end_nl() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, NEWLINE, NEWLINE];
let res = block(buf, 4, &mut rs);
let buf = [0u8, 1u8, 2u8, NEWLINE, NEWLINE];
let res = block(&buf, 4, &mut rs);
assert_eq!(
res,
@@ -198,8 +198,8 @@ fn block_test_double_end_nl() {
#[test]
fn block_test_start_nl() {
let mut rs = ReadStat::default();
let buf = vec![NEWLINE, 0u8, 1u8, 2u8, 3u8];
let res = block(buf, 4, &mut rs);
let buf = [NEWLINE, 0u8, 1u8, 2u8, 3u8];
let res = block(&buf, 4, &mut rs);
assert_eq!(
res,
@@ -210,8 +210,8 @@ fn block_test_start_nl() {
#[test]
fn block_test_double_surrounded_nl_no_trunc() {
let mut rs = ReadStat::default();
let buf = vec![0u8, 1u8, 2u8, 3u8, NEWLINE, NEWLINE, 4u8, 5u8, 6u8, 7u8];
let res = block(buf, 8, &mut rs);
let buf = [0u8, 1u8, 2u8, 3u8, NEWLINE, NEWLINE, 4u8, 5u8, 6u8, 7u8];
let res = block(&buf, 8, &mut rs);
assert_eq!(
res,
@@ -226,10 +226,10 @@ fn block_test_double_surrounded_nl_no_trunc() {
#[test]
fn block_test_double_surrounded_nl_double_trunc() {
let mut rs = ReadStat::default();
let buf = vec![
let buf = [
0u8, 1u8, 2u8, 3u8, NEWLINE, NEWLINE, 4u8, 5u8, 6u8, 7u8, 8u8,
];
let res = block(buf, 4, &mut rs);
let res = block(&buf, 4, &mut rs);
assert_eq!(
res,
@@ -272,24 +272,24 @@ make_block_test!(
#[test]
fn unblock_test_full_cbs() {
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
let res = unblock(buf, 8);
let buf = [0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
let res = unblock(&buf, 8);
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, NEWLINE],);
}
#[test]
fn unblock_test_all_space() {
let buf = vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
let res = unblock(buf, 8);
let buf = [SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
let res = unblock(&buf, 8);
assert_eq!(res, vec![NEWLINE],);
}
#[test]
fn unblock_test_decoy_spaces() {
let buf = vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
let res = unblock(buf, 8);
let buf = [0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
let res = unblock(&buf, 8);
assert_eq!(
res,
@@ -299,8 +299,8 @@ fn unblock_test_decoy_spaces() {
#[test]
fn unblock_test_strip_single_cbs() {
let buf = vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE];
let res = unblock(buf, 8);
let buf = [0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE];
let res = unblock(&buf, 8);
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, NEWLINE],);
}
@@ -317,7 +317,7 @@ fn unblock_test_strip_multi_cbs() {
.flatten()
.collect::<Vec<_>>();
let res = unblock(buf, 8);
let res = unblock(&buf, 8);
let exp = vec![
vec![0u8, NEWLINE],
+5 -5
View File
@@ -296,9 +296,9 @@ impl std::str::FromStr for StatusLevel {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"none" => Ok(StatusLevel::None),
"noxfer" => Ok(StatusLevel::Noxfer),
"progress" => Ok(StatusLevel::Progress),
"none" => Ok(Self::None),
"noxfer" => Ok(Self::Noxfer),
"progress" => Ok(Self::Progress),
_ => Err(ParseError::StatusLevelNotRecognized(s.to_string())),
}
}
@@ -491,14 +491,14 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result<IConvFlags, ParseError
if case.is_some() {
return Err(ParseError::MultipleUCaseLCase);
} else {
case = Some(flag)
case = Some(flag);
}
}
ConvFlag::LCase => {
if case.is_some() {
return Err(ParseError::MultipleUCaseLCase);
} else {
case = Some(flag)
case = Some(flag);
}
}
ConvFlag::Block => match (cbs, iconvflags.unblock) {
+2 -2
View File
@@ -56,10 +56,10 @@ fn unimplemented_flags_should_error() {
let matches = uu_app().try_get_matches_from(args).unwrap();
if parse_iflags(&matches).is_ok() {
succeeded.push(format!("iflag={}", flag))
succeeded.push(format!("iflag={}", flag));
}
if parse_oflags(&matches).is_ok() {
succeeded.push(format!("oflag={}", flag))
succeeded.push(format!("oflag={}", flag));
}
}

Some files were not shown because too many files have changed in this diff Show More