Skip to content

Commit

Permalink
tests: add tests for apply regex_replace with --replacement set to …
Browse files Browse the repository at this point in the history
…<EMPTY>
  • Loading branch information
jqnatividad committed Dec 11, 2023
1 parent facf4f9 commit c67c23d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,38 @@ fn apply_dynfmt_issue1458() {
assert_eq!(got, expected);
}

#[test]
fn apply_regex_replace_issue1469() {
let wrk = Workdir::new("apply_regex_replace_issue1469");
wrk.create(
"data.csv",
vec![
svec!["col1", "col2", "col3",],
svec!["(Adam)", "B", "Case(hello)Name "],
svec!["Derek(foo)", "(bar)E", "Fos(this needs to go)ter"],
svec!["Gordon", "H", "(cmon)Irvin"],
svec!["Jack(ie)", "K", "Lynch(-Chan)"],
],
);
let mut cmd = wrk.command("apply");
cmd.arg("operations")
.arg("regex_replace")
.arg("col1,col2,col3")
.args(["--comparand", r"\([^)]+\)"])
.args(["--replacement", "<EmpTY>"])
.arg("data.csv");

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["col1", "col2", "col3"],
svec!["", "B", "CaseName "],
svec!["Derek", "E", "Foster"],
svec!["Gordon", "H", "Irvin"],
svec!["Jack", "K", "Lynch"],
];
assert_eq!(got, expected);
}

#[test]
fn apply_calcconv() {
let wrk = Workdir::new("apply");
Expand Down
32 changes: 32 additions & 0 deletions tests/test_applydp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,38 @@ fn applydp_ops_regex_replace() {
assert_eq!(got, expected);
}

#[test]
fn applydp_regex_replace_issue1469() {
let wrk = Workdir::new("applydp_regex_replace_issue1469");
wrk.create(
"data.csv",
vec![
svec!["col1", "col2", "col3",],
svec!["(Adam)", "B", "Case(hello)Name "],
svec!["Derek(foo)", "(bar)E", "Fos(this needs to go)ter"],
svec!["Gordon", "H", "(cmon)Irvin"],
svec!["Jack(ie)", "K", "Lynch(-Chan)"],
],
);
let mut cmd = wrk.command("applydp");
cmd.arg("operations")
.arg("regex_replace")
.arg("col1,col2,col3")
.args(["--comparand", r"\([^)]+\)"])
.args(["--replacement", "<EMPTY>"])
.arg("data.csv");

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["col1", "col2", "col3"],
svec!["", "B", "CaseName "],
svec!["Derek", "E", "Foster"],
svec!["Gordon", "H", "Irvin"],
svec!["Jack", "K", "Lynch"],
];
assert_eq!(got, expected);
}

#[test]
fn applydp_ops_regex_replace_validation_error() {
let wrk = Workdir::new("applydp");
Expand Down

0 comments on commit c67c23d

Please sign in to comment.