Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expr: remove onig #5515

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ num-bigint = "0.4.4"
num-traits = "0.2.17"
number_prefix = "0.4"
once_cell = "1.18.0"
onig = { version = "~6.4", default-features = false }
parse_datetime = "0.5.0"
phf = "0.11.2"
phf_codegen = "0.11.2"
Expand Down
2 changes: 1 addition & 1 deletion src/uu/expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/expr.rs"
clap = { workspace = true }
num-bigint = { workspace = true }
num-traits = { workspace = true }
onig = { workspace = true }
regex = { workspace = true }
uucore = { workspace = true }

[[bin]]
Expand Down
11 changes: 5 additions & 6 deletions src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use num_bigint::BigInt;
use num_traits::Zero;
use onig::{Regex, RegexOptions, Syntax};
use regex::Regex;

use crate::tokens::Token;

Expand Down Expand Up @@ -482,16 +482,15 @@

fn operator_match(values: &[String]) -> Result<String, String> {
assert!(values.len() == 2);
let re = Regex::with_options(&values[1], RegexOptions::REGEX_OPTION_NONE, Syntax::grep())
.map_err(|err| err.description().to_string())?;
Ok(if re.captures_len() > 0 {
let re = Regex::new(&values[1]).map_err(|err| err.to_string())?;
Ok(if re.captures_len() > 1 {
cakebaker marked this conversation as resolved.
Show resolved Hide resolved
re.captures(&values[0])
.map(|captures| captures.at(1).unwrap())
.map(|captures| captures.get(1).unwrap().as_str())

Check warning on line 488 in src/uu/expr/src/syntax_tree.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/expr/src/syntax_tree.rs#L488

Added line #L488 was not covered by tests
.unwrap_or("")
.to_string()
} else {
re.find(&values[0])
.map_or("0".to_string(), |(start, end)| (end - start).to_string())
.map_or("0".to_string(), |m| m.len().to_string())
})
}

Expand Down
38 changes: 32 additions & 6 deletions tests/by-util/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,52 @@
}

#[test]
fn test_regex() {
// FixME: [2022-12-19; rivy] test disabled as it currently fails due to 'oniguruma' bug (see GH:kkos/oniguruma/issues/279)
// new_ucmd!()
// .args(&["a^b", ":", "a^b"])
// .succeeds()
// .stdout_only("3\n");
#[ignore = "requires custom regex syntax"]
fn test_regex_hat() {
new_ucmd!()

Check warning on line 250 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L249-L250

Added lines #L249 - L250 were not covered by tests
.args(&["a^b", ":", "a^b"])
.succeeds()
.stdout_only("3\n");
}

Check warning on line 254 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L253-L254

Added lines #L253 - L254 were not covered by tests

#[test]
#[ignore = "requires custom regex syntax"]
fn test_regex_hat2() {

Check warning on line 258 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L258

Added line #L258 was not covered by tests
new_ucmd!()
.args(&["a^b", ":", "a\\^b"])
.succeeds()
.stdout_only("3\n");
}

Check warning on line 263 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L263

Added line #L263 was not covered by tests

#[test]
#[ignore = "requires custom regex syntax"]
fn test_regex_dollar() {

Check warning on line 267 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L267

Added line #L267 was not covered by tests
new_ucmd!()
.args(&["a$b", ":", "a\\$b"])
.succeeds()
.stdout_only("3\n");
}

Check warning on line 272 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L272

Added line #L272 was not covered by tests

#[test]
#[ignore = "requires custom regex syntax"]
fn test_regex_number() {

Check warning on line 276 in tests/by-util/test_expr.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_expr.rs#L276

Added line #L276 was not covered by tests
new_ucmd!()
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
.succeeds()
.stdout_only("2\n");
}

#[test]
fn test_regex_temporary() {
// This test should fail, but currently passes, because our regex syntax is
// different from GNU. This is only here to check that regex is working
// even if it's the wrong syntax.
new_ucmd!()
.args(&["-5", ":", "-{0,1}[0-9]*$"])
.succeeds()
.stdout_only("2\n");
}

#[test]
fn test_substr() {
new_ucmd!()
Expand Down
Loading