Skip to content

Commit

Permalink
tests: fixlengths added tests for --remove-empty option
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Jan 5, 2025
1 parent bac4721 commit 78beb07
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions tests/test_fixlengths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,155 @@ fn prop_fixlengths_explicit_len() {
}
qcheck(p as fn(Vec<CsvRecord>, usize) -> TestResult);
}

#[test]
fn fixlengths_remove_empty_basic() {
let rows = vec![
svec!["a", "", "c", "", "e"],
svec!["f", "", "h", "", "j"],
svec!["k", "", "m", "", "o"],
];

let wrk = Workdir::new("fixlengths_remove_empty_basic").flexible(true);
wrk.create("in.csv", rows);

let mut cmd = wrk.command("fixlengths");
cmd.arg("in.csv").args(["-r"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
assert_eq!(
got,
vec![
svec!["a", "c", "e"],
svec!["f", "h", "j"],
svec!["k", "m", "o"],
]
);
}

#[test]
fn fixlengths_remove_empty_with_length() {
let rows = vec![
svec!["a", "", "c", "", "e"],
svec!["f", "", "h", "", "j"],
svec!["k", "", "m", "", "o"],
];

let wrk = Workdir::new("fixlengths_remove_empty_with_length").flexible(true);
wrk.create("in.csv", rows);

let mut cmd = wrk.command("fixlengths");
cmd.arg("in.csv").args(["-r"]).args(["-l", "4"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
assert_eq!(
got,
vec![
svec!["a", "c", "e", ""],
svec!["f", "h", "j", ""],
svec!["k", "m", "o", ""],
]
);
}

#[test]
fn fixlengths_remove_empty_with_insert() {
let rows = vec![
svec!["a", "", "c", "", "e"],
svec!["f", "", "h", "", "j"],
svec!["k", "", "m", "", "o"],
];

let wrk = Workdir::new("fixlengths_remove_empty_with_insert").flexible(true);
wrk.create("in.csv", rows);

let mut cmd = wrk.command("fixlengths");
cmd.arg("in.csv").args(["-r"]).args(["-i", "2"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
assert_eq!(
got,
vec![
svec!["a", "c", "e"],
svec!["f", "h", "j"],
svec!["k", "m", "o"],
]
);
}

#[test]
fn fixlengths_remove_empty_with_length_and_insert() {
let rows = vec![
svec!["a", "", "c", "", "e"],
svec!["f", "", "h", "", "j"],
svec!["k", "", "m", "", "o"],
];

let wrk = Workdir::new("fixlengths_remove_empty_with_length_and_insert").flexible(true);
wrk.create("in.csv", rows);

let mut cmd = wrk.command("fixlengths");
cmd.arg("in.csv")
.args(["-r"])
.args(["-l", "5"])
.args(["-i", "2"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
assert_eq!(
got,
vec![
svec!["a", "", "", "c", "e"],
svec!["f", "", "", "h", "j"],
svec!["k", "", "", "m", "o"],
]
);
}

#[test]
fn fixlengths_remove_empty_all_empty_columns() {
let rows = vec![
svec!["a", "", "", "", "e"],
svec!["f", "", "", "", "j"],
svec!["k", "", "", "", "o"],
];

let wrk = Workdir::new("fixlengths_remove_empty_all_empty_columns").flexible(true);
wrk.create("in.csv", rows);

let mut cmd = wrk.command("fixlengths");
cmd.arg("in.csv").args(["-r"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
assert_eq!(
got,
vec![svec!["a", "e"], svec!["f", "j"], svec!["k", "o"],]
);
}

#[test]
fn fixlengths_remove_empty_with_negative_insert() {
let rows = vec![
svec!["a", "", "c", "", "e"],
svec!["f", "", "h", "", "j"],
svec!["k", "", "m", "", "o"],
];

let wrk = Workdir::new("fixlengths_remove_empty_with_negative_insert").flexible(true);
wrk.create("in.csv", rows);

let mut cmd = wrk.command("fixlengths");
cmd.arg("in.csv")
.args(["-r"])
.args(["-l", "5"])
.args(["-i", "-2"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
assert_eq!(
got,
vec![
svec!["a", "c", "", "", "e"],
svec!["f", "h", "", "", "j"],
svec!["k", "m", "", "", "o"],
]
);
}

0 comments on commit 78beb07

Please sign in to comment.