diff --git a/tests/test_apply.rs b/tests/test_apply.rs index 486e45079..ed8b261aa 100644 --- a/tests/test_apply.rs +++ b/tests/test_apply.rs @@ -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", ""]) + .arg("data.csv"); + + let got: Vec> = 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"); diff --git a/tests/test_applydp.rs b/tests/test_applydp.rs index 31c886e79..cf45ed902 100644 --- a/tests/test_applydp.rs +++ b/tests/test_applydp.rs @@ -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", ""]) + .arg("data.csv"); + + let got: Vec> = 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");