1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

expand: fix formatting issues and cleanup

This commit is contained in:
Sebastian Bentmar Holgersson 2023-01-03 22:06:40 +00:00 committed by Sylvestre Ledru
parent 69d8729598
commit 1bf723fe40
2 changed files with 18 additions and 19 deletions

View file

@ -38,7 +38,7 @@ static DEFAULT_TABSTOP: usize = 8;
/// The mode to use when replacing tabs beyond the last one specified in /// The mode to use when replacing tabs beyond the last one specified in
/// the `--tabs` argument. /// the `--tabs` argument.
#[derive(PartialEq, Debug)] #[derive(PartialEq)]
enum RemainingMode { enum RemainingMode {
None, None,
Slash, Slash,
@ -195,7 +195,6 @@ fn tabstops_parse(s: &str) -> Result<(RemainingMode, Vec<usize>), ParseError> {
Ok((remaining_mode, nums)) Ok((remaining_mode, nums))
} }
#[derive(Debug)]
struct Options { struct Options {
files: Vec<String>, files: Vec<String>,
tabstops: Vec<usize>, tabstops: Vec<usize>,
@ -345,11 +344,11 @@ fn next_tabstop(tabstops: &[usize], col: usize, remaining_mode: &RemainingMode)
Some(t) => t - col, Some(t) => t - col,
None => { None => {
let step_size = tabstops[num_tabstops - 1]; let step_size = tabstops[num_tabstops - 1];
let last_fixed_tabstop = tabstops[num_tabstops-2]; let last_fixed_tabstop = tabstops[num_tabstops - 2];
let characters_since_last_tabstop = col-last_fixed_tabstop; let characters_since_last_tabstop = col - last_fixed_tabstop;
let steps_required = 1 + characters_since_last_tabstop/step_size; let steps_required = 1 + characters_since_last_tabstop / step_size;
steps_required*step_size-characters_since_last_tabstop steps_required * step_size - characters_since_last_tabstop
} }
}, },
RemainingMode::Slash => match tabstops[0..num_tabstops - 1].iter().find(|&&t| t > col) { RemainingMode::Slash => match tabstops[0..num_tabstops - 1].iter().find(|&&t| t > col) {
@ -378,7 +377,7 @@ enum CharType {
fn expand(options: &Options) -> std::io::Result<()> { fn expand(options: &Options) -> std::io::Result<()> {
use self::CharType::*; use self::CharType::*;
let mut output = BufWriter::new(stdout()); let mut output = BufWriter::new(stdout());
let ts = options.tabstops.as_ref(); let ts = options.tabstops.as_ref();
let mut buf = Vec::new(); let mut buf = Vec::new();

View file

@ -275,7 +275,7 @@ fn test_tabs_shortcut() {
.args(&["-2", "-5", "-7"]) .args(&["-2", "-5", "-7"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -285,7 +285,7 @@ fn test_comma_separated_tabs_shortcut() {
.args(&["-2,5", "-7"]) .args(&["-2,5", "-7"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -295,7 +295,7 @@ fn test_tabs_and_tabs_shortcut_mixed() {
.args(&["-2", "--tabs=5", "-7"]) .args(&["-2", "--tabs=5", "-7"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -305,7 +305,7 @@ fn test_ignore_initial_plus() {
.args(&["--tabs=+3"]) .args(&["--tabs=+3"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -315,7 +315,7 @@ fn test_ignore_initial_pluses() {
.args(&["--tabs=++3"]) .args(&["--tabs=++3"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -325,7 +325,7 @@ fn test_ignore_initial_slash() {
.args(&["--tabs=/3"]) .args(&["--tabs=/3"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -335,7 +335,7 @@ fn test_ignore_initial_slashes() {
.args(&["--tabs=//3"]) .args(&["--tabs=//3"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -345,7 +345,7 @@ fn test_ignore_initial_plus_slash_combination() {
.args(&["--tabs=+/3"]) .args(&["--tabs=+/3"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -355,7 +355,7 @@ fn test_comma_with_plus_1() {
.args(&["--tabs=3,+6"]) .args(&["--tabs=3,+6"])
.pipe_in("\t111\t222\t333") .pipe_in("\t111\t222\t333")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" 111 222 333"); .stdout_is(" 111 222 333");
} }
@ -365,7 +365,7 @@ fn test_comma_with_plus_2() {
.args(&["--tabs=1,+5"]) .args(&["--tabs=1,+5"])
.pipe_in("\ta\tb\tc") .pipe_in("\ta\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is(" a b c"); .stdout_is(" a b c");
} }
@ -375,7 +375,7 @@ fn test_comma_with_plus_3() {
.args(&["--tabs=2,+5"]) .args(&["--tabs=2,+5"])
.pipe_in("a\tb\tc") .pipe_in("a\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is("a b c"); .stdout_is("a b c");
} }
@ -385,6 +385,6 @@ fn test_comma_with_plus_4() {
.args(&["--tabs=1,3,+5"]) .args(&["--tabs=1,3,+5"])
.pipe_in("a\tb\tc") .pipe_in("a\tb\tc")
.succeeds() .succeeds()
// 01234567890 // 01234567890
.stdout_is("a b c"); .stdout_is("a b c");
} }