Skip to content

Commit

Permalink
expr: Remove useless arg in enum variant
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Feb 27, 2025
1 parent 591a3f8 commit cf5aa13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/uu/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub enum ExprError {
UnmatchedOpeningBrace,
#[error("Unmatched ) or \\}}")]
UnmatchedClosingBrace,
#[error("Invalid content of {0}")]
InvalidContent(String),
#[error("Invalid content of \\{{\\}}")]
InvalidBracketContent,
}

impl UError for ExprError {
Expand Down
36 changes: 9 additions & 27 deletions src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn check_posix_regex_errors(pattern: &str) -> ExprResult<()> {
(true, true, false) => Ok(()),
(_, false, _) => Err(ExprError::UnmatchedOpeningBrace),
(false, _, _) => Err(ExprError::UnmatchedOpeningParenthesis),
(true, true, true) => Err(ExprError::InvalidContent(r"\{\}".to_string())),
(true, true, true) => Err(ExprError::InvalidBracketContent),
}
}

Expand Down Expand Up @@ -601,7 +601,7 @@ pub fn is_truthy(s: &NumOrStr) -> bool {
#[cfg(test)]
mod test {
use crate::ExprError;
use crate::ExprError::InvalidContent;
use crate::ExprError::InvalidBracketContent;

use super::{check_posix_regex_errors, AstNode, BinOp, NumericOp, RelationOp, StringOp};

Expand Down Expand Up @@ -793,38 +793,20 @@ mod test {

#[test]
fn check_regex_empty_repeating_pattern() {
assert_eq!(
check_posix_regex_errors("ab\\{\\}"),
Err(InvalidContent(r"\{\}".to_string()))
)
assert_eq!(check_posix_regex_errors("ab\\{\\}"), Err(InvalidBracketContent))
}

#[test]
fn check_regex_intervals_two_numbers() {
assert_eq!(
// out of order
check_posix_regex_errors("ab\\{1,0\\}"),
Err(InvalidContent(r"\{\}".to_string()))
);
assert_eq!(
check_posix_regex_errors("ab\\{1,a\\}"),
Err(InvalidContent(r"\{\}".to_string()))
);
assert_eq!(
check_posix_regex_errors("ab\\{a,3\\}"),
Err(InvalidContent(r"\{\}".to_string()))
);
assert_eq!(
check_posix_regex_errors("ab\\{a,b\\}"),
Err(InvalidContent(r"\{\}".to_string()))
);
assert_eq!(
check_posix_regex_errors("ab\\{a,\\}"),
Err(InvalidContent(r"\{\}".to_string()))
);
assert_eq!(
check_posix_regex_errors("ab\\{,b\\}"),
Err(InvalidContent(r"\{\}".to_string()))
Err(InvalidBracketContent)
);
assert_eq!(check_posix_regex_errors("ab\\{1,a\\}"), Err(InvalidBracketContent));
assert_eq!(check_posix_regex_errors("ab\\{a,3\\}"), Err(InvalidBracketContent));
assert_eq!(check_posix_regex_errors("ab\\{a,b\\}"), Err(InvalidBracketContent));
assert_eq!(check_posix_regex_errors("ab\\{a,\\}"), Err(InvalidBracketContent));
assert_eq!(check_posix_regex_errors("ab\\{,b\\}"), Err(InvalidBracketContent));
}
}
2 changes: 1 addition & 1 deletion tests/by-util/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ mod gnu_expr {
.stdout_only("\n");
}

#[ignore]
#[ignore = "rust-onig bug, see https://github.com/rust-onig/rust-onig/issues/188"]
#[test]
fn test_bre10() {
new_ucmd!()
Expand Down

0 comments on commit cf5aa13

Please sign in to comment.